Why do I need to run find_rtools() before has_devel() = TRUE?

风格不统一 提交于 2019-12-12 02:27:52

问题


I try to follow the guide in http://adv-r.had.co.nz/Rcpp.html to understand Rcpp but I always need to run devtools::find_rtools() before any Rcpp function works: If I do

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;
}') 

I get an error and Rstudio prompts me to install additional build tools (but nothing happens when I say yes). It looks like some make command fails, but system("where make") gives a path that is in my PATH. When I then do

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

both devtools and Rcpp seem to be happy. Why is that and how can I fix that?

Here is the start of my 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\\"

回答1:


Basically, you did not put the rtools install location on the system PATH variable. So, devtools::find_rtools() is scanning the registry and adding it. The addition is only valid for the active session.

Now, the devtools::has_devel() is a very simple build and link of a C++ file. Thus, running devtools::has_devel() without the necessary environment (e.g. a valid rtools install) will yield a failure. In this case, the environment simply is not setup right as the system PATH variable has not been modified.

Make sure the following are in your system path variable:

C:\Rtools\bin and C:\Rtools\gcc-4.6.3\bin

Check within a clean R session:

Sys.getenv("PATH")


来源:https://stackoverflow.com/questions/37226661/why-do-i-need-to-run-find-rtools-before-has-devel-true

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!