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:

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:\.