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