RStan Always trying to download RTools when it's already installed

I have RTools downloaded to my documents folder rather than directly on C due to permission issues (corporate access issues). Every time I try to run a Stan model, I get the “Install Build Tools” dialog box. How can I configure my settings so that Stan will look in the appropriate place for RTools? (I have tried a lot of various configurations with RStudio and the PATH variable but I won’t go into all of them here if someone knows the right way to do it).

Pre-reqs for questions below:

  • Windows 10
  • RStan Version 2.18.2
  • Output of writeLines(readLines(file.path(Sys.getenv("HOME"), ".R/Makevars")))

CXXFLAGS=-O3 -Wno-unused-variable -Wno-unused-function -Wno-unused-local-typedefs

CXXFLAGS=-O3 -Wno-unused-variable -Wno-unused-function -Wno-unused-local-typedefs

CXXFLAGS=-O3 -Wno-unused-variable -Wno-unused-function -Wno-unused-local-typedefs

  • Output of devtools::session_info("rstan")

Session info ------------------------------------------------------------------------------------------------
setting value
version R version 3.5.1 (2018-07-02)
system x86_64, mingw32
ui RStudio (1.2.1114)
language (EN)
collate English_United States.1252
tz America/New_York
date 2019-02-12

Packages ----------------------------------------------------------------------------------------------------
package * version date source
assertthat 0.2.0 2017-04-11 CRAN (R 3.5.0)
backports 1.1.2 2017-12-13 CRAN (R 3.5.0)
base64enc 0.1-3 2015-07-28 CRAN (R 3.5.0)
BH 1.66.0-1 2018-02-13 CRAN (R 3.5.0)
callr 3.0.0 2018-08-24 CRAN (R 3.5.1)
cli 1.0.1 2018-09-25 CRAN (R 3.5.1)
colorspace 1.3-2 2016-12-14 CRAN (R 3.5.1)
compiler 3.5.1 2018-07-02 local
crayon 1.3.4 2017-09-16 CRAN (R 3.5.0)
desc 1.2.0 2018-05-01 CRAN (R 3.5.1)
digest 0.6.17 2018-09-12 CRAN (R 3.5.1)
fansi 0.3.0 2018-08-13 CRAN (R 3.5.1)
ggplot2 3.0.0 2018-07-03 CRAN (R 3.5.1)
glue 1.3.0 2018-07-17 CRAN (R 3.5.1)
graphics * 3.5.1 2018-07-02 local
grDevices * 3.5.1 2018-07-02 local
grid 3.5.1 2018-07-02 local
gridExtra 2.3 2017-09-09 CRAN (R 3.5.1)
gtable 0.2.0 2016-02-26 CRAN (R 3.5.1)
inline 0.3.15 2018-05-18 CRAN (R 3.5.1)
labeling 0.3 2014-08-23 CRAN (R 3.5.0)
lattice 0.20-35 2017-03-25 CRAN (R 3.5.1)
lazyeval 0.2.1 2017-10-29 CRAN (R 3.5.1)
loo 2.0.0 2018-04-11 CRAN (R 3.5.1)
magrittr 1.5 2014-11-22 CRAN (R 3.5.0)
MASS 7.3-50 2018-04-30 CRAN (R 3.5.1)
Matrix 1.2-14 2018-04-13 CRAN (R 3.5.1)
matrixStats 0.54.0 2018-07-23 CRAN (R 3.5.1)
methods * 3.5.1 2018-07-02 local
mgcv 1.8-24 2018-06-23 CRAN (R 3.5.1)
munsell 0.5.0 2018-06-12 CRAN (R 3.5.1)
nlme 3.1-137 2018-04-07 CRAN (R 3.5.1)
parallel 3.5.1 2018-07-02 local
pillar 1.3.0 2018-07-14 CRAN (R 3.5.1)
pkgbuild 1.0.1 2018-09-18 CRAN (R 3.5.1)
plyr 1.8.4 2016-06-08 CRAN (R 3.5.1)
processx 3.2.0 2018-08-16 CRAN (R 3.5.1)
ps 1.1.0 2018-08-10 CRAN (R 3.5.1)
R6 2.3.0 2018-10-04 CRAN (R 3.5.1)
RColorBrewer 1.1-2 2014-12-07 CRAN (R 3.5.0)
Rcpp 0.12.19 2018-10-01 CRAN (R 3.5.1)
RcppEigen 0.3.3.4.0 2018-02-07 CRAN (R 3.5.1)
reshape2 1.4.3 2017-12-11 CRAN (R 3.5.1)
rlang 0.2.2 2018-08-16 CRAN (R 3.5.1)
rprojroot 1.3-2 2018-01-03 CRAN (R 3.5.1)
rstan 2.18.2 2018-11-07 CRAN (R 3.5.2)
scales 1.0.0 2018-08-09 CRAN (R 3.5.1)
StanHeaders 2.18.1 2019-01-28 CRAN (R 3.5.2)
stats * 3.5.1 2018-07-02 local
stats4 3.5.1 2018-07-02 local
stringi 1.1.7 2018-03-12 CRAN (R 3.5.0)
stringr 1.3.1 2018-05-10 CRAN (R 3.5.1)
tibble 1.4.2 2018-01-22 CRAN (R 3.5.0)
tools 3.5.1 2018-07-02 local
utf8 1.1.4 2018-05-24 CRAN (R 3.5.0)
utils * 3.5.1 2018-07-02 local
viridisLite 0.3.0 2018-02-01 CRAN (R 3.5.1)
withr 2.1.2 2018-03-15 CRAN (R 3.5.0)
If you are reporting a bug (thank you!) please use the issue tracker (Issues · stan-dev/rstan · GitHub) instead of the forums.

What does

pkgbuild::rtools_path()

say?

pkgbuild::rtools_path()
Error in get(name, envir = cache) : object ‘rtools_path’ not found

pkgbuild::has_rtools(debug = TRUE)
Scanning R CMD config CC…
cc_path:
‘.exe’ does not exist
Scanning path…
Scanning registry…
Found C:/Users/josephdean/Documents/Rtools for 3.5
VERSION.txt
Rtools version 3.5.0.4
[1] TRUE

The problem may have something to do with the spaces in “Rtools for 3.5”. Can you try installing ot to C:/Users/josephdean/Documents/Rtools35 or something like that?

The folder name is just “Rtools”, so I think the ‘for 3.5’ is added text from the function.

I’ve sometimes had issue with Windows and the trailing / (or lack of) for the path in various settings.

the same problem, try many times, can not solve

Do you have the same problem if you simply do

pkgbuild::with_build_tools(print("hello"), debug = TRUE)

from RStudio?

when i do
pkgbuild::with_build_tools(print(“hello”), debug = TRUE)
the rstudio ask me to install rtools again and again

That command gives the following and pulls up the install rtools dialog box:

pkgbuild::with_build_tools(print(“hello”), debug = TRUE)
Error: Could not find tools necessary to compile a package

And this happens again even after you click through the install rtools dialog?

I think someone with this problem needs to open an issue at

with the reproducible pkgbuild::with_build_tools(print(“hello”), debug = TRUE) example. I don’t think it actually involves Stan.

1 Like

Yeah, unfortunately clicking through is not an option, since it ends with trying to install Rtools to C:, which is a dead end because I don’t have write permission there. This is why I’ve installed into Documents which seems to be at the root of my problems.

RStudio should be installing Rtools to a writable location that it knows where it is and does not need to reinstall it. If not, it is a bug but I don’t think it is a bug with Stan.

Thanks, issue opened:

https://github.com/r-lib/pkgbuild/issues/65

This is an old thread, but I had a similar issue with rstudio asking me to install rtools every time I ran a stan model, whereas with an older R version it was working just fine.
I ended up fixing the problem by running:
options(buildtools.check = function(action) TRUE )
Hope this may help others bumping into this problem.

11 Likes

Thanks nschiett! After being stuck on this for a while, this worked. You are my hero.

1 Like

Thanks for this solution!