2016-05-14 76 views
0

我試着按照該指南中http://adv-r.had.co.nz/Rcpp.html瞭解RCPP 但我總是需要運行devtools::find_rtools()任何RCPP功能的工作原理之前: 如果我做爲什麼我需要在has_devel()= TRUE之前運行find_rtools()?

library(devtools) 
library(Rcpp) 

has_devel() # Error: Command failed(1) 

# Example from http://adv-r.had.co.nz/Rcpp.html 
add <- cppFunction('int add(int x, int y, int z) { 
    int sum = x + y + z; 
    return sum; 
}') 

我得到一個錯誤,Rstudio提示我安裝額外的構建工具(但是當我說是時沒有任何反應)。它看起來像一些命令失敗,但system("where make")給出了我的路徑中的路徑。 當我再做

find_rtools() # True 

has_devel() # True 

# Try the example again 
add <- cppFunction('int add(int x, int y, int z) { 
    int sum = x + y + z; 
    return sum; 
}') 
# Now works 
add(1,2,3) # 6 

兩個devtools和RCPP似乎是幸福的。爲什麼是這樣的,我該如何解決這個問題?

這裏是我的道路開始

path <- get_path() 
head(path, 8) 

[1] "F:\\Software\\R-3.3.0\\bin\\x64" 
"F:\\Software\\Rtools\\bin"      
[3] "F:\\Software\\Rtools\\gcc-4.6.3\\bin" 
"F:\\Software\\Python 3\\Scripts\\"    
[5] "F:\\Software\\Python 3\\" 
"F:\\Software\\Rtools\\bin"      
[7] "F:\\Software\\Rtools\\gcc-4.6.3\\bin" 
"C:\\Program Files (x86)\\Intel\\iCLS Client\\" 
+0

是從一個乾淨的R對話這條道路? 'find_rtools()'只修改你的路徑。如果您希望在不必運行devtools的情況下永久工作,請通過環境變量對話框(在Windows開始菜單中)更改路徑。 – Thomas

+0

是的,那是來自乾淨的會議。 但是路徑中缺少哪個目錄,Rtools似乎至少有一些目錄? – luoar

回答

2

基本上,你沒有把rtools對系統PATH可變安裝位置。所以devtools::find_rtools()scanning the registry and adding it。添加僅對活動會話有效。

現在,devtools::has_devel()very simple build and link of a C++ file。因此,在沒有必要的環境(例如有效的rtools安裝)下運行devtools::has_devel()將導致失敗。在這種情況下,由於系統PATH變量未被修改,因此環境設置不正確。

確保以下是在您的系統路徑變量:

C:\Rtools\bin和一個乾淨的R對話中C:\Rtools\gcc-4.6.3\bin

檢查:

Sys.getenv("PATH") 
+0

嗯好吧,我在路徑中有'F:\\ Software \\ Rtools \\ bin'和'F:\\ Software \\ Rtools \\ gcc-4.6.3 \\ bin',當我查看它時R,你告訴我,他們也出現在Windows設置。 'C:\'沒有Rtools是否是一個問題? – luoar

+0

我建議你卸載'Rtools',清除你之前安裝的'PATH'變量並刪除任何舊的R安裝,[下載一個新的副本](https://cran.r-project.org/bin/ windows/Rtools/Rtools33.exe),然後[安裝它](https://www.biostat.wisc.edu/~kbroman/Rintro/Rwinpack.html)。 – coatless

+0

另外,請參閱:http://stackoverflow.com/questions/19885381/rtools-not-being-detected-by-r – coatless

相關問題