【问题标题】:Why do I need to run find_rtools() before has_devel() = TRUE?为什么我需要在 has_devel() = TRUE 之前运行 find_rtools()?
【发布时间】:2016-09-10 15:12:59
【问题描述】:

我尝试按照http://adv-r.had.co.nz/Rcpp.html 中的指南来了解 Rcpp 但我总是需要在任何 Rcpp 函数起作用之前运行devtools::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 提示我安装其他构建工具(但当我说是时没有任何反应)。看起来某些 make 命令失败了,但 system("where make") 给出了我 PATH 中的路径。 当我这样做时

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 的开始

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\\"

【问题讨论】:

  • 这条路径来自干净的 R 会话吗? find_rtools() 仅修改该会话的路径。如果您希望它永久工作而无需运行 devtools,请通过环境变量对话框(在 Windows 开始菜单中)更改您的路径。
  • 是的,这是来自一个干净的会话。但是路径中缺少哪个目录,Rtools 里面好像至少有一些目录?!

标签: r rcpp devtools


【解决方案1】:

基本上,您没有将 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\binC:\Rtools\gcc-4.6.3\bin

在干净的 R 会话中检查:

Sys.getenv("PATH")

【讨论】:

  • 嗯,好吧,当我按照您告诉我的那样在 R 中查找时,路径中有 F:\\Software\\Rtools\\binF:\\Software\\Rtools\\gcc-4.6.3\\bin,它们也出现在 Windows 设置中。 `C:` 中没有 Rtools 会不会有问题?
  • 我建议您卸载 Rtools,从以前的安装中清除您的 PATH 变量并删除所有旧的 R 安装,download a new copy,然后是 install it
  • 现在也试过了,还是不行。这是我仍然得到的错误代码:c:/Rtools/mingw_64/bin/gcc -I"F:/Software/R-3.3.0/include" -DNDEBUG -I"d:/Compiler/gcc-4.9.3/local330/include" -O2 -Wall -std=gnu99 -mtune=core2 -c foo.c -o foo.o c:/Rtools/mingw_64/bin/gcc: not found make: *** [foo.o] Error 127 Noob 问题,但为什么它试图在 C 上而不是在路径中查找东西F?
  • 因此,要么您没有清理您的 PATH 变量,要么在安装 rtools 时将不同的位置添加到您的 PATH 变量中不正确的位置。无论如何,请清理 rtoolsPATH 变量并再次尝试安装,但请密切注意“添加到 PATH”步骤。
猜你喜欢
  • 2014-02-17
  • 2020-06-15
  • 1970-01-01
  • 1970-01-01
  • 2015-08-19
  • 1970-01-01
  • 2014-04-10
  • 1970-01-01
  • 2012-10-18
相关资源
最近更新 更多