Can't run rstan


R version 3.5.2 (2018-12-20) – “Eggshell Igloo”
Platform: x86_64-w64-mingw32/x64 (64-bit)

RTools version: Rtools version

Rstan version: rstan (Version 2.18.2, GitRev: 2e1f913d3ca3)

Initial path entries: PATH=c:\programFiles\R\Rtools\bin;c:\programfiles\R\Rtools\mingw_64\bin; …

I’m running the same versions of R in the same folders on two Win7 machines.
On one, where I’m not an administrator, I can successfully run rstan on
the 8schools example. On the other, where I am an administrator,
I get the following error:

fit <- stan(file=“8schools.stan”,
iter=1000, chains=4)

Error in file(con, “r”) : cannot open the connection
In addition: Warning messages:
1: In system(cmd, intern = !verbose) :
running command ‘C:/ProgramFiles/RNew/R-3.5.2/bin/x64/R CMD SHLIB filee485fe91fd7.cpp 2> filee485fe91fd7.cpp.err.txt’ had status 65535
2: In file(con, “r”) :
cannot open file ‘filee485fe91fd7.cpp.err.txt’: No such file or directory
Error in sink(type = “output”) : invalid connection

(Both run from rgui.exe in R’s x64 folder). One thing I’ve noticed
is that on the second (problem) machine, I get the following response
to a test for RTools:

Scanning R CMD config CC…
‘.exe’ does not exist
Scanning path…
ls: c:\PROGRA~4\R\Rtools\bin\ls.exe
gcc_path: c:\PROGRA~4\R\Rtools\mingw_64\bin\gcc.exe
Rtools version
Version: 3.4
Found compatible gcc on path
[1] TRUE

while on the working system, it finds a cc_path, which
however, matches the gcc_path entry above (so a gcc seems
to be found).

Can anyone suggest what’s going wrong when I try to
run rstan on 8schools? Or failing that, what I could
to to get more information on what’s happening?
Could it be an issue with write permissions on the



I think the problem may be from one of two reasons I encountered:

  1. With the version of RTools you are using. I had run into a similar situation - the pain page states, you can use RTools3.3. or higher even for R3.5, but for Rtools 3.3 and 3.4 did not work.
    My RStan models compiled only with RTools3.5.

  2. On Windows, if you are using R directly and not via RStudio, RTools is supposed to be installed in C:\RTools directory (RStudio uses devtools package which can handle RTools installation anywhere

I would look into one of these two as reasons for the problems you are running into. There is another consideration which RTools Windows Toolset page warns about. To quote

It is essential that the directory containing the command line tools comes first or second in the path: there are typically like-named tools88 in other directories, and they will not work. The ordering of the other directories is less important, but if in doubt, use the order above.

Our toolset contains copies of Cygwin DLLs that may conflict with other ones on your system if both are in the path at once. The normal recommendation is to delete the older ones; however, at one time we found our tools did not work with a newer version of the Cygwin DLLs, so it may be safest not to have any other version of the Cygwin DLLs in your path.

Usually such problems are encountered when a person does not have admin rights. So it is entirely possible your RTools tool chain is not correctly located in the correct order or you have conflict with other cygwin or mingw compilers.



My guess is that when you are in administrator mode, it searches differently / wrongly. I would first try uninstalling RTools 3.4 and installing RTools 3.5.


Thanks for your suggestions; but I don’t think they can be right. Remember, on the “good” win7 machine everything seems to match the setup on the “bad” machine: in particular: using RTools 3.4; running R directly (not via RStudio); RTools is not in c:\Rtools; and on the “bad” machine RTools directories are first and second in the path.

Does anyone know how to get a more informative error messages (adding “verbose” to the call to stan produces additional information once stan is running, but doesn’t help for my problem). Can I for example start a command session and try to run the compilation part from there? And if so, how?


@pviton I just reread the RTools document and it states clearly to avoid installing RTools in directories that have spaces. The Program Files location in your output has that space. Since a lot of these toolsets are ported from Unix to Windows unexpected consequences may arise such as machines with seemingly same configurations not performing alike.

Uninstall the RTools completely and install to C:\RTools and see if that helps. Good luck. I just went through a similar nightmarish scenario.



sree_d : Not so. In my case it’s “ProgramFiles” without a space (chosen for precisely that reason). But thanks for taking the trouble to think about this.


bgoodri: Thanks for the suggestion to try with RTools 3.5. I tried this but no luck. Can you think of anything else that could be going wrong?