26

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 publish an app from the RStudio, I get the following error,

Preparing to deploy application...DONE Uploading bundle for application: 64015...Error: * Application depends on package "Rtools" but it is not installed. Please resolve before continuing. Execution halted

-- I have tried this,On Console,

> find_rtools(T)
Scanning path...
ls : D:\Rtools\bin\ls.exe 
gcc: D:\Rtools\GCC-46~1.3\bin\gcc.exe 
VERSION.txt
Rtools version 3.3.0.1959 
Version: 3.3 
[1] TRUE

So, Rtools seems basically there!

-- I have checked environment variables, those are OK, as I also mentioned R and gcc can be started from command line

Yet, I tried to install and check from within RStudio using installr package, it says,

> install.Rtools()
No need to install Rtools - You've got the relevant version of Rtools installed
> 

-- This is not a possible duplication of this, Rtools not being detected by R I have tried all these. Did not work.

Please suggest a solution. Thank you very much for your time.

Community
  • 1
  • 1
Droid-Bird
  • 1,417
  • 5
  • 19
  • 43
  • What exactly is the command you are running that returns the error? It's looking for an "'Rtools' package" which seems different that just looking for Rtools to be installed. Did you write your own package? Did you specify the dependencies correctly? – MrFlick Oct 13 '15 at 14:24
  • A lot of people make similar mistakes, Rtools is not a package. Its development environment that you need to install. You may read more from here, https://cran.r-project.org/bin/windows/Rtools/ – Droid-Bird Oct 13 '15 at 16:44
  • I have tested the same on two computers. No luck! What am I missing? – Droid-Bird Oct 15 '15 at 12:10
  • I have similar problems and not yet a solution (with R3.4.0 and RStudio 1.0.143). Funny thing: If I execute `devtools::find_rtools(F, T)` RTools is found (until I restart the R session). – R Yoda May 17 '17 at 21:50
  • The issue is a bug with RStudio not recognizing the custom RTools directory. Try to keep it with `C:/` if at all possible. I think a fix was added in V1.1.0 >= – coatless May 17 '17 at 22:49

4 Answers4

34

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

Ensure that for the BINPREF path, the final slash is included after 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/

Benisburgers
  • 352
  • 4
  • 17
R Yoda
  • 8,358
  • 2
  • 50
  • 87
  • The issue with this solution is it negates the fact that the OP is using a custom install path `D:/` instead of `C:/`. As indicated in the above comment, this is a known issue with RStudio versions < 1.1.0 – coatless May 17 '17 at 22:57
  • 1
    @coatless You are right, I have declared my answer as "work-around" now. I thought it would be helpful for others with similar problems (I have lost hours to diagnose and solve this) – R Yoda May 18 '17 at 21:13
  • 1
    As an update, I had to slightly modify the above paths bc it's now called `RBuildtools` + version number, not just `Rtools`: `> Sys.setenv(BINPREF = "C:/RBuildtools/3.4/mingw_$(WIN)/bin/") > Sys.setenv(PATH = paste("C:/RBuildtools/3.4/bin", Sys.getenv("PATH"), sep=";"))` – spops Feb 09 '18 at 21:20
  • 1
    @spops Is `RBuildtools` a custom path or the default one that Rtools proposes during installation (I am asking because I am not aware of any change in the default installation path of Rtools)? – R Yoda Feb 10 '18 at 08:44
  • That was a custom path that I made that fixed the issue for me - I remember telling the installer to modify the Path during installation but maybe I botched it somehow? Or, because I was installing a *really* picky package, it just couldn't find it? – spops Feb 10 '18 at 18:49
  • `RBuildTools/3.4` is the default location that gets suggested if you install Rtools through RStudio. If you just download Rtools from `r-project.org` and run the exe, it will not suggest this – RolandASc Feb 27 '18 at 14:23
  • 4
    Note that the final slash is apparently _very important_. I was wondering for a few minutes what this `bing++` was that couldn't be found – lucidbrot Jul 17 '18 at 15:38
  • With the last version of Rtools: ``Sys.setenv(PATH = paste("C:/rtools40/ucrt64/bin", Sys.getenv("PATH"), sep=";"))`` – user4624500 May 23 '21 at 08:35
3

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.

RolandASc
  • 3,863
  • 1
  • 11
  • 30
1

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.

Martin Smith
  • 3,687
  • 1
  • 24
  • 51
1

After searching a lot solutions, finally I delete .Renviron file in C:\Users\My name\Documents. Then rtools40 works.

Xiaorui Zhu
  • 161
  • 7
  • that's funny. i find it's really hard to work with R. In this example, some people suggest you to add .Renviron but others suggest you delete. Worst of all , the official document is not adequate to address these issues. – FrankZhu Sep 02 '22 at 13:57