Installing RStan on Windows 10 64bit...Error

I am having trouble getting rstan to function on a windows 10 machine. I have followed all instructions found on I installed R 3.4.3, Rstudio 1.1.423, and Rtools33 first and then followed the steps in the link. Rtools comes up fine in the path.

When I try (as recommended in the link):

fx <- inline::cxxfunction( signature(x = "integer", y = "numeric" ) , '
    return ScalarReal( INTEGER(x)[0] * REAL(y)[0] ) ;
' )
fx( 2L, 5 ) # should be 10

I get the following error:

Error in system(cmd, intern = !verbose) : 'C:/Program' not found

I found and followed a very similar thread on this forum that talked about adding quotation marks around whatever is assigned to CXXFLAGS in the Makevars file. This made no difference so I changed it back to no quotation marks.

Note my makevars file contains the following line:

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

I have tried uninstalling R, Rstudio, Rtools and reinstalling them and following the steps again and no change in the problems. I have followed the exact same process on a different windows 10 machine and had no issues, just the computer I need to use at work is giving me this trouble.

If I try to use any rstan function, I get the

Error in system(cmd, intern = !verbose) : 'C:/Program' not found.  

Any ideas on what I am missing? What other info can I provide to help diagnose this?

If you have installed R 3.4.3, then you should be installing Rtools34, not Rtools33. Not sure if that will help you, though.

ETA: The answer to your problem may be here: r - Message error 'C:/Program' not found with Rcpp - Stack Overflow

Especially see this part: “If you want to be able to build packages from sources, we recommend that you choose an installation path not containing spaces.”

The other system I got working had Rtools33, etc the same as this machine and there were no problems. So, the Rtools version doesn’t seem to be the problem. I mainly am interested in running rstan functions like stan(“logit.stan”, data = standata). Thanks for the link, though it seems to be addressing a different issue and need. Hmmm, not sure what else to try…

It is almost certainly a problem with spaces somewhere. Possibly in the step where you specified the BINPREF environmental variable.

Here are the contents of the .Rprofile file that results from the command containing binpref:

Sys.setenv(BINPREF = "C:/Rtools/mingw_$(WIN)/bin/")

Nothing more than that in the file. I’m not seeing any spaces, but I agree it seems like a space is the issue.

What is


How is it a different issue? It’s the very same error message: “Error in system(cmd, intern = !verbose) : ‘C:/Program’ not found”.

Yes, it is for Rcpp, but RStan uses Rcpp. Also, it’s an error message that indicates that something is trying to run something in “C:/Program Files”, and that something fails because it treats “C:/Program” and “Files” as separate tokens, thus mistaking “C:/Program” for a program to execute rather than treating it as part of a path to, say, g++.

A co-worker recommended I change the Makevars file, so it is currently


Before it was:

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

same error either way

One possibly useful note: I do not have admin priveleges on this machine, so I have to get IT help to install or uninstall things. I ran across a comment in the post that jjramsey recommended that talks about permission maybe causing this kind of problem, it said:

@edouard That command was intended to identify, not fix the problem. Rather than displaying it as an answer, it makes more sense to include the output as an update to your question. Also, given that the error shows that it could not write the error file, I suspect that R does not have permission to write to the C:/Program Files/R-3.0.1/bin/x64/R directory…

Would running Rstudio as administrator once possibly help?

Perhaps a few more details can help.
Here are my results from the tool chain steps of the “installing Rstan on Windows” link:

> Sys.getenv('PATH')
[1] "C:\\Rtools\\bin;C:\\Program Files\\R\\R-3.4.3\\bin\\x64;c:\\Rtools\\bin;c:\\Rtools\\gcc-4.6.3\\bin;....

> system('g++ -v')
Using built-in specs.
Target: i686-w64-mingw32
Configured with: /data/gannet/ripley/Sources/mingw-test3/src/gcc/configure --host=i686-w64-mingw32 --
build=x86_64-linux-gnu --target=i686-w64-mingw32 --with-sysroot=/data/gannet/ripley/Sources/mingw-
test3/mingw32mingw32/mingw32 --prefix=/data/gannet/ripley/Sources/mingw-
test3/mingw32mingw32/mingw32 --with-gmp=/data/gannet/ripley/Sources/mingw-
test3/mingw32mingw32/prereq_install --with-mpfr=/data/gannet/ripley/Sources/mingw-
test3/mingw32mingw32/prereq_install --with-mpc=/data/gannet/ripley/Sources/mingw-
test3/mingw32mingw32/prereq_install --disable-shared --enable-static --enable-targets=all --enable-
languages=c,c++,fortran --enable-libgomp --enable-sjlj-exceptions --enable-fully-dynamic-string --disable-
nls --disable-werror --enable-checking=release --disable-win32-registry --disable-rpath --disable-werror 
CFLAGS='-O2 -mtune=core2 -fomit-frame-pointer' LDFLAGS=
Thread model: win32
gcc version 4.6.3 20111208 (prerelease) (GCC) 

These all seem to give the right result, not sure if someone will notice any issues here?

Maybe move C:\\Program Files\\R\\R-3.4.3\\bin\\x64; farther right in the PATH

Also, it seems to be picking up the gcc 4.6.3 toolchain rather than the gcc 4.9.1 toolchain that is included with Rtools33.

Thanks bgoodri, I will try your suggestions. It may be next week before I get help from the IT admin people. I will post whatever ends up working, hopefully something.

I uninstalled R 3.4.3, Rstudio 1.1.423, and Rtools33.
I then reinstalled R 3.4.3, Rstudio 1.1.423, and Rtools34.

I followed the instructions on the tool chain steps of the “installing Rstan on Windows” link again, here are the results:

>  Sys.getenv('PATH')
[1] "C:\\Rtools\\bin;C:\\Program Files\\R\\R-3.4.3\\bin\\x64;c:\\Rtools\\bin;c:\\Rtools\\mingw_32\\bin;c:\\Rtools\\bin;c:\\Rtools\\gcc-4.6.3\\bin;C:\\ProgramData\\Anaconda3;C:\\ProgramData\\Anaconda3\\Library\\mingw-w64\\bin;C:\\ProgramData\\Anaconda3\\Library\\usr\\bin;C:\\ProgramData\\Anaconda3\\Library\\bin;C:\\ProgramData\\Anaconda3\\Scripts;c:\\Rtools\\bin;c:\\Rtools\\mingw_32\\bin;C:\\ProgramData\\Oracle\\Java\\javapath;C:\\WINDOWS\\system32;C:\\WINDOWS;C:\\WINDOWS\\System32\\Wbem;C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\;C:\\Program Files\\Tumbleweed\\Desktop Validator\\;C:\\Program Files\\Tumbleweed\\Desktop Validator\\x86;C:\\Program Files (x86)\\HID Global\\ActivClient\\;C:\\Program Files\\HID Global\\ActivClient\\;C:\\Program Files\\MATLAB\\R2016b\\bin;C:\\Users\\\\AppData\\Local\\Microsoft\\WindowsApps;"

>  system('g++ -v')
Using built-in specs.
Target: i686-w64-mingw32
Configured with: ../../../src/gcc-4.9.3/configure --host=i686-w64-mingw32 --build=i686-w64-mingw32 --target=i686-w64-mingw32 --prefix=/mingw32 --with-sysroot=/home/Jeroen/mingw-gcc-4.9.3/i686-493-posix-dwarf-rt_v3-s/mingw32 --with-gxx-include-dir=/mingw32/i686-w64-mingw32/include/c++ --enable-static --disable-shared --disable-multilib --enable-languages=c,c++,fortran,lto --enable-libstdcxx-time=yes --enable-threads=posix --enable-libgomp --enable-libatomic --enable-lto --enable-graphite --enable-checking=release --enable-fully-dynamic-string --enable-version-specific-runtime-libs --disable-sjlj-exceptions --with-dwarf2 --disable-isl-version-check --disable-cloog-version-check --disable-libstdcxx-pch --disable-libstdcxx-debug --enable-bootstrap --disable-rpath --disable-win32-registry --disable-nls --disable-werror --disable-symvers --with-gnu-as --with-gnu-ld --with-arch=i686 --with-tune=generic --with-libiconv --with-system-zlib --with-gmp=/home/Jeroen/mingw-gcc-4.9.3/prerequisites/i686-w64-mingw32-static --with-mpfr=/home/Jeroen/mingw-gcc-4.9.3/prerequisites/i686-w64-mingw32-static --with-mpc=/home/Jeroen/mingw-gcc-4.9.3/prerequisites/i686-w64-mingw32-static --with-isl=/home/Jeroen/mingw-gcc-4.9.3/prerequisites/i686-w64-mingw32-static --with-cloog=/home/Jeroen/mingw-gcc-4.9.3/prerequisites/i686-w64-mingw32-static --enable-cloog-backend=isl --with-pkgversion='i686-posix-dwarf, Built by MinGW-W64 project' --with-bugurl= CFLAGS='-O2 -pipe -I/home/Jeroen/mingw-gcc-4.9.3/i686-493-posix-dwarf-rt_v3-s/mingw32/opt/include -I/home/Jeroen/mingw-gcc-4.9.3/prerequisites/i686-zlib-static/include -I/home/Jeroen/mingw-gcc-4.9.3/prerequisites/i686-w64-mingw32-static/include' CXXFLAGS='-O2 -pipe -I/home/Jeroen/mingw-gcc-4.9.3/i686-493-posix-dwarf-rt_v3-s/mingw32/opt/include -I/home/Jeroen/mingw-gcc-4.9.3/prerequisites/i686-zlib-static/include -I/home/Jeroen/mingw-gcc-4.9.3/prerequisites/i686-w64-mingw32-static/include' CPPFLAGS= LDFLAGS='-pipe -L/home/Jeroen/mingw-gcc-4.9.3/i686-493-posix-dwarf-rt_v3-s/mingw32/opt/lib -L/home/Jeroen/mingw-gcc-4.9.3/prerequisites/i686-zlib-static/lib -L/home/Jeroen/mingw-gcc-4.9.3/prerequisites/i686-w64-mingw32-static/lib -Wl,--large-address-aware'
Thread model: posix
gcc version 4.9.3 (i686-posix-dwarf, Built by MinGW-W64 project)

Still getting the same error as before:

>  fit_rstan <- stan("logit.stan", data = standata)
Error in system(cmd, intern = !verbose) : 'C:/Program' not found

Not sure what I need to do at this point. Any further thoughts?

I would install R under C:\ rather than C:\Program Files

I adjust my .Rprofile because Rtools was installed to Program Files. My .Rprofile has the line:
Sys.setenv(BINPREF = ‘C:/PROGRA~1/Rtools/mingw_$(WIN)/bin/’)

I think both R and RTools both get installed under C:\Program Files by default. The installation guide for Windows is somewhat annoying by assuming they are under C:.

I’m also getting gcc 4.6.3 with Rtools33.

Yes, but the default isn’t working for you. Reinstall R and Rtools (especially Rtools) in C:\.

Wanted to update this. I did nothing new after my last attempt as far as uninstall reinstall. The IT people recently updated my windows 10 to the newest version. Another thing that had not been done was windows 10 had not been activated yet before due to an error not allowing it. So after the update, they tried activating windows and got it to go through. Anyway, not sure whether the activation or the update or both made the difference, (I suspect the activation) but rstan and rstanarm work now with no issues. I did have rstan uninstalled during the update and then just install.packages(“rstan”) after it and all set.

Thanks for reporting back and glad to hear things are now working. We’re often in this situation where some bit of infrastructure changes and then broken RStan or PyStan installs work again for reasons we never fully understand.

We had a similar issue with Windows 7. Oddly enough, the installation of RStan was not problematic on some laptops yet failed on others despite very similar environments (Windows 7, R 3.5.1, RStudio 1.1.453, Rtools with a similar message as the original post in this thread (‘C:/Program’ not found).

R was installed to the default directory c:/Program files/R. The laptops on which everything worked fine showed 8dot3 shortnames (so for instance C:\PROGRA~1\R) when the command dir /x was executed in a DOS prompt at c:/. In other cases this was missing.

The following workaround was successful:

  • open a DOS terminal
  • Type: mklink /J "C:\PROGRA~1" "C:\Program Files" and press enter (this will create a directory junction from C:\PROGRA~1 to C:\Program Files, which will be visible in the windows explorer) (see also this link)
  • Open RStudio
  • Go to Tools - Global Options and click Change R-version in the General tab.
  • Click “Choose a specific version of R” and click on browse.
  • Copy paste C:\PROGRA~1\R in the destination folder. Click further to the map containing your most recent R version (R-x.y.z).
  • In the screen that pops up choose 64-bits R version (or 32-bits)
  • Click Apply and restart Rstudio

After that, RStan and brms worked fine (after install.packages(“rstan”)).

I hope someone points this to the root cause of the problem… maybe @bgoodri? I guess it has nothing to do with rstan, but rather the interaction between Rstudio and Rtools?

1 Like