2016-05-14 53 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

相关问题