rfailed-installationrstanrtools

Rtools 4.0 not found during package installation


For many R packages I try to install (on my Windows 10 machine), I get a warning:

> install.packages('rstan')
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 thought this was just an erroneous error message since the installation seemed to proceed anyway, but recently I tried to install a package (rstan) and found it completely nonfunctional. My hunch is that since rstan relies completely on compiling code with rcpp, maybe I only got away with the previous packages because I wasn't using the functions in them that relied on Rtools.

I reinstalled Rtools 4.0, and devtools::find_rtools() returns TRUE. But when I run Sys.getenv()['PATH'] there is no Rtools on the path. There isn't a place in the installation process to tell it I want Rtools on the path either, so these instructions don't help - the menus they refer to don't exist for me. So I thought this might be an issue where the new Rtools 4.0 doesn't put itself on the system path. But the problem persisted even after I directly edited the Windows path environment variables (both system and user versions) to include the path given to me by pkgbuild::rtools_path() (C:\rtools40\usr\bin, a path which both exists and appears to be correct).

This doesn't seem to be the same problem as Rtools 4.0 (Rstudio falsely claims it was deleted), since there are no claims Rtools was deleted. It's also not the same as Rtools not being detected by R as far as I can tell: I'm not leaving any features out of my Rtools installation - I'm not even getting the option to in my install wizard.

Would appreciate any advice or recommendations.


Solution

  • Rtools40 requires that you add its bin directory to your PATH variable. The full instructions are here.

    You can update your ~/.Renviron file with any of the following methods:

    You can do that manually by opening ~/.Renviron and putting the following in it:

    PATH="${RTOOLS40_HOME}\usr\bin;${PATH}"
    

    You can also use R (Gui or RStudio or Shell) with the following:

    writeLines(
        'PATH="${RTOOLS40_HOME}\\usr\\bin;${PATH}"',
        con = file("~/.Renviron", open = "a")
    )
    

    Both of these methods require a restart of R.