15

I am running into a simple setup problem with Rcpp and I cannot get it to work. I tried to follow this example http://www.r-bloggers.com/user2013-the-rcpp-tutorial/ But when executing this code:

library(Rcpp)
evalCpp("1 + 1", showOutput= TRUE)

I get this output

C:/R/R-30~1.1/bin/x64/R CMD SHLIB -o "sourceCpp_33280.dll" "file8d01b0a675b.cpp" 
Error in sourceCpp(code = code, env = env, rebuild = rebuild, showOutput = showOutput,  : 
  Error 1 occurred building shared library.
WARNING: Rtools is required to build R packages but is not currently installed. 
Please download and install the appropriate version of Rtools before proceeding:

I have done the following things in an attempt to make it work:

  • installed Rtools 31 with install.Rtools()
  • installed R in C:\R\R-3.0.1
  • library files are stored in C:\R\R-3.0.1\library
  • installed Rstudio in C:\R\RStudio
  • placed my script in C:\R

most similar issues seem to suggest that a space was in the file path, therefore i moved pretty much everything I could. But still it fails to locate Rtools. I tried it on my laptop and on my desktop and both don't work, so there is probably something structural I am doing wrong.

Timo Koole
  • 151
  • 1
  • 1
  • 3

1 Answers1

6

Looks like neither your R binaries nor Rtools directories are in your system's PATH environment variable. Try this:

> writeLines(strsplit(Sys.getenv("PATH"), ";")[[1L]])
C:\R\Rtools\bin
C:\R\Rtools\gcc-4.6.3\bin
C:\R\R-devel\bin\x64
[... and so on ...]

If your directories C:\R\R-3.0.1\bin\x64\ and C:\R\Rtools\bin\ & C:\R\Rtools\gcc-*.*.*\bin\ (replace \gcc-*-*-*\ with your version of the gcc-binaries) are not listed, the needed components can't be found. To be on the safe side, also create a system variable called CYGWIN with the value nodosfilewarning.

After changing/creating the PATH and CYGWIN variables, reboot. Then it should work and you can place your sources anywhere on your machine and also compile them manually using R CMD SHLIB.

MJMaier
  • 71
  • 1
  • 4
  • I encountered a similar problem. As Dirk suggested in the comments to the question, updating path in cmd.exe (see http://stackoverflow.com/questions/8358265/how-to-update-path-variable-permanently-from-cmd-windows) helped `find_rtools()` from `devtools` to succeed. See also http://stackoverflow.com/questions/19885381/rtools-not-being-detected-by-r – mts Oct 12 '15 at 14:35
  • Since R3.3 an additional variable must be set, see: http://stackoverflow.com/a/44035904/4468078 – R Yoda May 17 '17 at 22:56