Installing RStan on Windows10

hi there - i’m new to Stan and trying to set up RStan for the first time, but running into a hitch right at the start:
I’ve followed the instructions on using RStudio, and it was fine until I ran the line:
pkgbuild::has_build_tools(debug = TRUE)

it loaded all sorts of content but at the end I got:
trying URL ‘
Content type ‘application/x-msdownload’ length 108622512 bytes (103.6 MB)
downloaded 103.6 MB

And the instructions say not to go further til this is “TRUE”
Any tips?
thanks! :)

If that returns FALSE, then there should be more to the error message.

thanks - but there isn’t?! that’s why I was confused - no information on what went wrong…?

I realize this may not be the answer you were looking for, but since you seem not to have a final one so far and it seems like getting this sort of “unix native” apps working on Windows can be a pain, using the Windows Subsystem for Linux (WSL, or “bash on Windows”) may be a solution to get Stan to work on Windows 10, and otherwise having a proper linux terminal if you think that would be useful more generally. It probably requires admin rights on your machine, at least to enable “developer mode”, but you can find detailed instructions on the official microsoft documentation page.

I have never installed RStan on it (or anywhere for that matter), but cmdStan and PyStan for linux (as well as any linux command line software) work without any issues on it. You should need to have an R installation separate for the on Windows since most things other than the file system don’t really interact between the WSL and the Windows OS.

I think it was saying that it was FALSE that it could find the build tools and then it downloaded them. What does it say when you do pkgbuild::has_build_tools(debug = TRUE) again, possibly after a restart of RStudio.

thanks for your replies!
I tried this command line and got “TRUE” - so does that maybe mean that it has worked better than it appeared…?

I was also having no end of trouble trying to get stan working on a windows 10 machine last night. Was working a month or two ago, but either updates to stan or updates to windows broke things. I ended up having to use an older approach of installing Rtools manually and putting c:\Rtools\mingw_64\bin in my path to get it to find g++.

1 Like

I think it appeared to work.

okay great thanks! I appreciate all the feedback - and will likely be back on here as soon as I run into my next snag… :)

Anyone help here?

  • Windows 10
  • R 3.6.0
  • Rtools 3.5 at C:/RBuildTools
  • First two entries of PATH are C:/RBuildTools/3.5/bin;C:/RBuildTools/3.5/mingw_64/bin;
  • Sys.which(‘g++’), system(‘g++ -v’) and other tests confirm g++ is being found
  • pkgbuild::has_build_tools(debug = TRUE) Fails!! It wants to reinstall Rtools again… even if I do that, it still fails.

I would appreciate any tips!

I don’t think you need to put those two things at the front of the PATH anymore. Try it without that.

Thanks, Ben. With these removed, I get the following behaviors:

  • pkgbuild::has_build_tools(debug = TRUE) still fails
  • pkgbuild::has_rtools(debug = TRUE) returns the following
Scanning R CMD config CC...
'.exe' does not exist
Scanning path...
Scanning registry...
Found C:/RBuildTools/3.5 for 3.5 
Rtools version 
[1] TRUE
  • Building packages from source fails as well, for example
install.packages("rstan", type = "source")
* installing *source* package 'rstan' ...
** package 'rstan' successfully unpacked and MD5 sums checked
** using staged installation
** libs

*** arch - i386
C:/RBuildTools/3.5/mingw_32/bin/g++ -O2 -march=native -mtune=native  -I"C:/R/R-36~1.0/include" -DNDEBUG -I"../inst/include" -I"`"C:/R/R-36~1.0/bin/i386/Rscript" --vanilla -e "cat(system.file('include', 'src', package = 'StanHeaders'))"`" -DBOOST_DISABLE_ASSERTS -DBOOST_PHOENIX_NO_VARIADIC_EXPRESSION -I"C:/R/R-3.6.0/library/Rcpp/include" -I"C:/R/R-3.6.0/library/RcppEigen/include" -I"C:/R/R-3.6.0/library/BH/include" -I"C:/R/R-3.6.0/library/StanHeaders/include"        -O3 -march=native -c chains.cpp -o chains.o
     61 [main] sh 12632 fork: child -1 - CreateProcessW failed for 'C:\RBuildTools\3.5\bin\sh.exe', errno 13
sh: fork: Permission denied
  • I have set permissions to C:/RBuildTools and C:/R to full control for my user name. I get these same type of errors when logged in as administrator.

Feeling pretty stuck here! I’ve reinstalled Rtools, R… also reinstalled Windows 10.

Try specifying the INSTALL_opts = "--no-multiarch" argument when you call install.packages.

Interesting – ok, now it does go to x64, but still have this permissions issue:

>   install.packages("rstan", type = "source", INSTALL_opts = "--no-multiarch")
trying URL ''
Content type 'application/x-gzip' length 838052 bytes (818 KB)
downloaded 818 KB

* installing *source* package 'rstan' ...
** package 'rstan' successfully unpacked and MD5 sums checked
** using staged installation
** libs
C:/RBuildTools/3.5/mingw_64/bin/g++ -O2 -march=native -mtune=native  -I"C:/R/R-36~1.0/include" -DNDEBUG -I"../inst/include" -I"`"C:/R/R-36~1.0/bin/x64/Rscript" --vanilla -e "cat(system.file('include', 'src', package = 'StanHeaders'))"`" -DBOOST_DISABLE_ASSERTS -DBOOST_PHOENIX_NO_VARIADIC_EXPRESSION -I"C:/R/R-3.6.0/library/Rcpp/include" -I"C:/R/R-3.6.0/library/RcppEigen/include" -I"C:/R/R-3.6.0/library/BH/include" -I"C:/R/R-3.6.0/library/StanHeaders/include"        -O3 -march=native -c chains.cpp -o chains.o
     27 [main] sh 8112 fork: child -1 - CreateProcessW failed for 'C:\RBuildTools\3.5\bin\sh.exe', errno 13
sh: fork: Permission denied
In file included from C:/R/R-3.6.0/library/BH/include/boost/random/detail/integer_log2.hpp:19:0,
                 from C:/R/R-3.6.0/library/BH/include/boost/random/detail/large_arithmetic.hpp:19,
                 from C:/R/R-3.6.0/library/BH/include/boost/random/detail/const_mod.hpp:23,
                 from C:/R/R-3.6.0/library/BH/include/boost/random/linear_congruential.hpp:30,
                 from C:/R/R-3.6.0/library/BH/include/boost/random/additive_combine.hpp:27,
                 from chains.cpp:29:
C:/R/R-3.6.0/library/BH/include/boost/pending/integer_log2.hpp:7:89: note: #pragma message: This header is deprecated. Use <boost/integer/integer_log2.hpp> instead.
C:/RBuildTools/3.5/mingw_64/bin/g++ -O2 -march=native -mtune=native  -I"C:/R/R-36~1.0/include" -DNDEBUG -I"../inst/include" -I"`"C:/R/R-36~1.0/bin/x64/Rscript" --vanilla -e "cat(system.file('include', 'src', package = 'StanHeaders'))"`" -DBOOST_DISABLE_ASSERTS -DBOOST_PHOENIX_NO_VARIADIC_EXPRESSION -I"C:/R/R-3.6.0/library/Rcpp/include" -I"C:/R/R-3.6.0/library/RcppEigen/include" -I"C:/R/R-3.6.0/library/BH/include" -I"C:/R/R-3.6.0/library/StanHeaders/include"        -O3 -march=native -c init.cpp -o init.o
     78 [main] sh 10804 fork: child -1 - CreateProcessW failed for 'C:\RBuildTools\3.5\bin\sh.exe', errno 13
sh: fork: Permission denied

On a win pc yesterday i had to put both rtools/bin and rtools/mingw64/bin in the path to get it to stop asking to install rtools…

Interesting — you had Rtools installed as C:/Rtools, and not C:/RBuildTools?

That sounds like a bug with pkgbuild and / or R 3.6.

I’ll try stepping down to 3.5.3, good idea

I don’t know anything about the CreateProcessW. There are Google hits for it, but I’ve never seen pop up before.

The Stack Overflow discussions seem to indicate that there might be an interaction with my organization’s anti-virus software. However, others in my organization are able to build packages from source and compile C++ code, so I’m not sure what’s going on.

I’ll try the previous version of R first, then try adding C:/RBuildTools back into the path, then as Charles has done, go back to C:/Rtools and put that in the path.