9
votes

I'm pretty new to R so apologies for a stupid question. I'm trying to get rcpp running but I'm stuck in an endless loop of R asking me to re-install RTools.

I broadly followed the code in this blog post, although first time off I installed everything by hand & I've subsequently re-installed everything a few times over. I'm running Windows 7, R version 3.1.2, R Studio Version 0.98.1091 (not that this should matter much) and RTools 3.1.

An edited highlight of what my console looks like is as follows:

> library(installr) 
Welcome to installr version 0.15.3...

> install.Rtools()
Loading required package: devtools
No need to install Rtools - You've got the relevant version of Rtools installed

> find_rtools()
[1] TRUE

> library(Rcpp)
> evalCpp("1+1")

Error in sourceCpp(code = code, env = env, rebuild = rebuild, showOutput = showOutput,  :
Error 65535 occurred building shared library.

At which point a dialog box pops up saying:

Install Build Tools Compiling C/C++ code for R requires installation of additional build tools. Do you want to install the additional tools now?

And then I get directed to download and re-install RTools 3.1 from cran all over again.

I've seen that this can be an issue with the PATH variable but I've tried various things including:

  1. Nothing (extra) in the PATH variable
  2. Including both references to R (C:\Program Files\R\R-3.1.2\bin\x64) and RTools (C:\RBuildTools\3.1\bin;C:\RBuildTools\3.1\gcc-4.6.3\bin;) in the PATH. Once with RTools first, once with R first
  3. Including just a reference to RTools in the PATH as the initial install file directed me to do.

Any ideas on things to try would be gratefully accepted!

EDIT

Following Dirk's comment it looks like I might have a problem with how RTools is installed. I've followed the instructions from several blogs / tutorials on how to install RTools; all to no avail (yet!)

This GitHub page gives some instructions on how install and check that the installation has worked. I've followed all the checks (see below for copy of the console) and it looks like I have a working install of RTools, but when I try to run evalCPP() again I get the same error as before directing me to install RTools.

> Sys.getenv('PATH')
[1] "C:\\Program Files\\R\\R-3.1.2\\bin\\x64;C:\\RTools\\bin;C:\\RTools\\gcc-4.6.3\\bin;C:\\WINDOWS\\system32;C:\\WINDOWS;C:\\WINDOWS\\System32\\Wbem;C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\;C:\\Program Files (x86)\\Enterprise Vault\\EVClient\\;C:\\Program Files (x86)\\Microsoft SQL Server\\100\\Tools\\Binn\\VSShell\\Common7\\IDE\\;C:\\Program Files (x86)\\Microsoft SQL Server\\100\\Tools\\Binn\\;C:\\Program Files\\Microsoft SQL Server\\100\\Tools\\Binn\\;C:\\Program Files (x86)\\Microsoft SQL Server\\100\\DTS\\Binn\\;C:\\Program Files (x86)\\Microsoft Visual Studio 9.0\\Common7\\IDE\\PrivateAssemblies\\;C:\\Program Files\\Microsoft SQL Server\\110\\Tools\\Binn\\;C:\\Program Files\\Microsoft\\Web Platform Installer\\;C:\\Program Files (x86)\\Microsoft SDKs\\TypeScript\\1.0\\;C:\\Program Files\\Microsoft SQL Server\\100\\DTS\\Binn\\"
Warning message:
printing of extremely long output is truncated

> system('g++ -v')
Using built-in specs.
COLLECT_GCC=C:\RTools\GCC-46~1.3\bin\G__~1.EXE
COLLECT_LTO_WRAPPER=c:/rtools/gcc-46~1.3/bin/../libexec/gcc/i686-w64-mingw32/4.6.3/lto-wrapper.exe
Target: i686-w64-mingw32
Configured with: /data/gannet/ripley/Sources/mingw-test3/src/gcc/configure --host=i686-w64-mingw32 --build=x86_64-linux-gnu --target=i686-w64-mingw32 --with-sysroot=/data/gannet/ripley/Sources/mingw-test3/mingw32mingw32/mingw32 --prefix=/data/gannet/ripley/Sources/mingw-test3/mingw32mingw32/mingw32 --with-gmp=/data/gannet/ripley/Sources/mingw-test3/mingw32mingw32/prereq_install --with-mpfr=/data/gannet/ripley/Sources/mingw-test3/mingw32mingw32/prereq_install --with-mpc=/data/gannet/ripley/Sources/mingw-test3/mingw32mingw32/prereq_install --disable-shared --enable-static --enable-targets=all --enable-languages=c,c++,fortran --enable-libgomp --enable-sjlj-exceptions --enable-fully-dynamic-string --disable-nls --disable-werror --enable-checking=release --disable-win32-registry --disable-rpath --disable-werror CFLAGS='-O2 -mtune=core2 -fomit-frame-pointer' LDFLAGS=
Thread model: win32
gcc version 4.6.3 20111208 (prerelease) (GCC) 

> system('where make')
C:\Rtools\bin\make.exe

I've also had a look at Appendix D of R Installation and Admin. I can't see anything in here I've not already tried except for section D.4 which implies I might need to rebuild rcpp from source using my installed RTools. I don't have time to do this right away but will give it a try unless people say this route is not worth my time.

EDIT v2

So I tried building rcpp from source ... and that didn't work either. I downloaded both the package source and windows binaries from the CRAN Rcpp package page. In the R console I now get:

> install.packages(pkgs = "C:/Rcpp_0.11.4.tar.gz", repos = NULL, contriburl = NULL, type = "source", verbose = TRUE)
Installing package into ‘C:/Users/james.macadie/Documents/R/win-library/3.1’
(as ‘lib’ is unspecified)
system (cmd0): C:/PROGRA~1/R/R-31~1.2/bin/x64/R CMD INSTALL
Warning in install.packages :
  package ‘C:/Rcpp_0.11.4.tar.gz’ is not available (for R version 3.1.2)

I guess my active questions now boil down to:

  • Reading the whole of the post above can anyone tell me how to fix things so it just works? Or, failing that...
  • What tests can I run to check I really do have Rtools installed correctly? Everything I have found on the internet suggests I do: system('where make') etc. However, the evidence of being unable to run evalCpp or other rccp functions suggests I don't.
  • What am I doing wrong when building from source? Should I try the command line option?

EDIT v3

Running evalCpp with showOutput= TRUE and verbose = TRUE I think I've tracked the error back to R CMD SHLIB not working. I followed this blog, which shows how to work with the command line R directly. However when I get to the line R CMD SHLIB sequence_examples.c the execution just skips straight to the next command line without doing anything, generating any files in the directory or throwing any errors. I tried running the --help options at the command line but get the same sort of error:

C:\Users\james.macadie> R --help


Or: R CMD command args

where 'command' is one of:
  INSTALL  Install add-on packages
  REMOVE   Remove add-on packages
  SHLIB    Make a DLL for use with dynload
  BATCH    Run R in batch mode
  build    Build add-on packages
  check    Check add-on packages
  Rprof    Post process R profiling files
  Rdconv   Convert Rd format to various other formats
  Rdiff    difference R output files
  Rd2pdf   Convert Rd format to PDF
  Rd2txt   Convert Rd format to pretty text
  Stangle   Extract S/R code from vignette
  Sweave    Process vignette documentation
  config   Obtain configuration information about R
  open     Open a file via Windows file associations
  texify   Process a latex file

Use
  R CMD command --help
for usage information for each command.


C:\Users\james.macadie> R CMD SHLIB --help

C:\Users\james.macadie>

N.B. for people reading the earlier code samples higher up this post I have changed a few things since those code snapshots:

  • I've installed R directly into C:\R. It used to be in C:\Program Files\R\ but as has been suggested file paths with spaces in can cause problems
  • I'm referencing Rtools under C:\Rtools\ and not C:\RBuildTools\

Thanks for any suggestions, as ever

4
This is documented in a number of places, including the R manuals, as well as numerous tutorials. If what you tried did not work for you, maybe try another one? Rcpp requires nothing special, but you must have Rtools working.Dirk Eddelbuettel
Try a different version of Rtools. If you are using Rtools32.exe, say, then try uninstalling it and installing Rtools31.exe by downloading it from cran.r-project.org/bin/windows/Rtools and running the installer you just downloaded. Be sure to start a fresh session of R and if you are launching R from a cmd session then relaunch that first.G. Grothendieck
Unfortunately I've already tried Rtools32.exeJames MacAdie

4 Answers

7
votes

Had the same endless loop issue when trying to install Twitter's BreakoutDetection (which is also written in cpp)

fixed by executing the following

Sys.setenv(PATH="%PATH%;C:/Rtools/gcc-4.6.3/bin;c:/Rtools/bin")

and then answering "no" when presented with the following prompt:

"Install Build Tools Compiling C/C++ code for R requires installation of additional build tools. Do you want to install the additional tools now?"

Didn't try these actions independently so not sure if either on their own would have fixed the issue

1
votes

I found that ensuring all of these were in my path fixed it. I did this with RStudio closed; I didn't reboot after.

C:\Program Files\R\R-3.1.3\bin\x64
C:\Program Files\R\R-3.1.3\bin
C:\RBuildTools\3.2\bin
C:\RBuildTools\3.2\gcc-4.6.3\bin64
C:\RBuildTools\3.2\gcc-4.6.3\bin
C:\RBuildTools\3.2\gcc-4.6.3\i686-w64-mingw32\bin

These are on my Win7-64bit computer. YMMV, and I'm mostly posting this to ensure others see it if they are having the same issue.

0
votes

In the end it was something a bit left-field. Inspired by the following post, I had a look at the ComSpec environment variable. Not quite sure how, but I had it set to "cmd.exe".

Removing the double quotes, so it said cmd.exe, and then rebooting fixed everything.

Thanks to all who've tried to help.

0
votes

I experienced the same problem, I fixed this problem by adding Rtools dir into env variables:

Sys.setenv(BINPREF = "C:/Rtools/mingw_$(WIN)/bin/")