I am using latest R, RStudio and Rtools.
-- I have updated the environment variables. Now I can call gcc, or R from command line.
While I was trying to publi
Via R CMD check not looking for gcc in Rtools directory:
R uses a BINPREF
variable to locate certain executables, including components of RTools.
BINPREF
can be set in a number of places. In my case, it was set in C:/Users/MYUSERNAME/Documents/.R/Makevars
. Deleting the contents of this file removed a link to a previous, and since deleted, installation of RTools.
It is also worth checking the file $RPATH/etc/i386/Makeconf
(swap i386 for x64 if you have a 64-bit installation), which will be re-created with each new installation of R. Note the line
BINPREF ?= c:/Rtools/mingw_32/bin/
, which (via the ?=
operator) will set the value of BINPREF
if it is not already set, as it was in the Makevars file mentioned above.
A temporary fix is to replace BINPREF ?=
with BINPREF =
,
but as the Makeconf file is overwritten when R is updated, you'll have to remember to do this each time. Better to edit, or delete, the Makevars file for a permanent change.
I have no idea why RStudio has such kind of problems from time to time but there is a manual work-around described here:
https://github.com/rwinlib/r-base/wiki/Testing-Packages-with-Experimental-R-Devel-Build-for-Windows
Basically you have to set two environment variables to point to the correct installation path of Rtools:
Sys.setenv(PATH = paste("C:/Rtools/bin", Sys.getenv("PATH"), sep=";"))
Sys.setenv(BINPREF = "C:/Rtools/mingw_$(WIN)/bin/")
To avoid losing this change after restarting RStudio you could modify your (Windows) environment variables instead or add the following rows to your .Renviron
file that is executed at each startup of R.
BTW: The $(WIN)
part is no typo but required so that R can inject "32" or "64" depending on the R version you are using (32 or 64 bit).
Edit 1: See also this r-bloggers article published recently: https://www.r-bloggers.com/quirks-about-running-rcpp-on-windows-through-rstudio/
Note that there are new potential kinds of problems (from R 3.3 onwards), since R (not RStudio, but R) adds a BINPREF
variable and modifies the Path
variable by default, see the Renviron.site
file for the latter, on Windows typically e.g. under C:\Program Files\R\R-3.4.3\etc
:
PATH="C:\Rtools\bin;${PATH}"
This might easily conflict for people with a custom path and/or multiple versions of Rtools installed, so I have commented this out with a #
.
For the BINPREF
problem, see the Makeconf
file, e.g. under C:\Program Files\R\R-3.4.3\etc\x64
:
BINPREF ?= c:/Rtools/mingw_64/bin/
I have then modified this to c:/Rtools34/mingw_64/bin/
, which is where I have installed my Rtools34
.
You can do the same for the Makeconf
file under the 32-bit arch. sub-directory.