Windows下使用Rtools編譯R語言包
使用devtools安裝github中的R原始碼時,經常會出各種錯誤,索性搜了一下怎麼在Windows下直接打包,網上的資料也是參差不齊,以下是自己驗證通過的。
一、下載Rtools
下載地址: ofollow,noindex">https://cran.r-project.org/bin/windows/Rtools/
根據自己安裝的R版本,下載相容的Rtools即可,我下載的是 Rtools35.exe
二、安裝Rtools
Windows下的安裝都是傻瓜式的,一步步點確定即可,有兩個地方需要注意:
2.1 安裝路徑
第一次安裝的時候,沒有使用這個預設路徑(C:\Rtools),選擇了其他的路徑,結果在後面安裝R包時,報找不到"c:/Rtools/mingw_32/bin/g++"的異常。
解除安裝Rtools後,重新安裝時,就用這個預設路徑了,後面就OK了。
2.2 設定環境變數
選中上面的“Add rtools to system PATH”,就省了自己在Windows中設定環境變量了。
三、編譯R語言程式碼
以編譯Twitter的 BreakoutDetection 為例(https://github.com/twitter/BreakoutDetection),將原始碼下載到本地,放到R語言SDK的bin目錄下(也可以放到其他目錄,只是使用命令時加上路徑即可):
通過cmd命令,切換到上述目錄,執行如下命令:
Rcmd build BreakoutDetection-1.0.1
輸出資訊為:
* checking for file 'BreakoutDetection-1.0.1/DESCRIPTION' ... OK * preparing 'BreakoutDetection': * checking DESCRIPTION meta-information ... OK * cleaning src * checking for LF line-endings in source and make files and shell scripts * checking for empty or unneeded directories * looking to see if a 'data/datalist' file should be added * building 'BreakoutDetection_1.0.1.tar.gz'
會發現在本地生成了一個 BreakoutDetection_1.0.1.tar.gz,這就是我們要安裝的包,但不是傳說中的zip包,是典型的Linux下的.tar.gz包。
四、安裝R語言程式碼包
開啟R語言SDK的RGui,選擇“Packages”-->"Install package(s) from local files",如下所示:
瀏覽選擇前一步驟生成的包(BreakoutDetection_1.0.1.tar.gz),如下所示:
安裝完後,會在library下發現安裝好的包,通過library(BreakoutDetection)命令,即可使用該包中的功能了。
五、Rcmd的一些命令引數