0

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\\"
Psidom
  • 209,562
  • 33
  • 339
  • 356
luoar
  • 130
  • 8
  • Is that path from a clean R session? `find_rtools()` modifies your path for that session only. If you want this to work permanently without having to run devtools, change your path via the environment variables dialog (in the Windows Start menu). – Thomas May 14 '16 at 15:16
  • Yes, that is from a clean session. But which directory is missing from the path, Rtools seems to have at least some directories in it?! – luoar May 14 '16 at 15:49

1 Answers1

2

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")
coatless
  • 20,011
  • 13
  • 69
  • 84
  • Hm ok, well I have `F:\\Software\\Rtools\\bin` and `F:\\Software\\Rtools\\gcc-4.6.3\\bin` in the path when I look it up in R as you told me to and they show up in Windows settings as well. Is it a problem to not have Rtools in `C:\`? – luoar May 14 '16 at 17:05
  • I would suggest that you uninstall `Rtools`, clean out your `PATH` variable from the previous install and delete any old R installations, [download a new copy](https://cran.r-project.org/bin/windows/Rtools/Rtools33.exe), and then [install it](https://www.biostat.wisc.edu/~kbroman/Rintro/Rwinpack.html). – coatless May 14 '16 at 17:17
  • Also, see: http://stackoverflow.com/questions/19885381/rtools-not-being-detected-by-r – coatless May 14 '16 at 17:18
  • Tried that as well now, still doesn't work.Here is the error code I still get: `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 question but why is it trying to find stuff on C instead of in the path in F? – luoar May 14 '16 at 18:45
  • So, either you didn't clean your `PATH` variable or when installing `rtools` the addition of the different locations to your `PATH` variable where not correct. Regardless, please **clean** the `PATH` variable of `rtools` and try the install again but pay close attention to the "add to PATH" step. – coatless May 14 '16 at 20:03