Can't get a functioning install with stan 2.21.0 on windows 10 and R v4.0.2 -demo can't find rtools - solved!

I 'm struggling to get Stan to run on my computer at the moment

I’ve removed the rstan package and installed as per https://github.com/stan-dev/rstan/wiki/RStan-Getting-Started
I’ve installed rtools40. When running rstan::stan_demo(1), I get the following error message:
Error in compileCode(f, code, language = language, verbose = verbose) :
sh: C:/Rtools/mingw_64/bin/g++: No such file or directorymake: *** [C:/PROGRA~1/R/R-40~1.2/etc/x64/Makeconf:229: file130c67f5cc3.o] Error 127
In addition: Warning message:
In system(paste(CXX, ARGS), ignore.stdout = TRUE, ignore.stderr = TRUE) :
‘C:/rtools40/usr/mingw_/bin/g++’ not found
Error in sink(type = “output”) : invalid connection

I had some issues with having remains of the previous version of rtools in my path, but cleaned this up, before reinstalling, and still have the above error. I cant find the paths in the above complaints when running Sys.getenv()[‘PATH’] either. Here’s the output


PATH                           C:\rtools40\usr\bin;C:\Program
                               Files\R\R-4.0.2\bin\x64;C:\Program Files (x86)\Intel\iCLS
                               Client;C:\Program Files\Intel\iCLS
                               Client;C:\ProgramData\Oracle\Java\javapath_target_97717435;C:\Program
                               Files (x86)\CodeSynthesis XSD 4.0\bin;C:\Program Files
                               (x86)\CodeSynthesis XSD
                               4.0\bin64;C:\Windows\System32;C:\MinGW\include;C:\MinGW\bin;C:\MinGW\msys\1.0\bin;C:\MinGW\lib\gcc\mingw32\3.4.5\include;C:\WinPython-64bit-3.4.3.4\python-3.4.3.amd64;C:\Python34\Scripts;C:\Program
                               Files\R\R-3.2.1\bin;C:\Program Files\MiKTeX
                               2.9\miktex\bin\x64;C:\Program Files (x86)\Windows
                               Kits\10\Windows Performance Toolkit;C:\Program Files
                               (x86)\Microsoft Visual Studio 14.0\Common7\IDE;C:\Program
                               Files (x86)\Microsoft Visual Studio 14.0\VC\bin;C:\Program
                               Files\Microsoft SQL Server\110\Tools\Binn;C:\Program Files
                               (x86)\Microsoft
                               SDKs\TypeScript\1.0;C:\local\GnuWin32\bin;C:\Program
                               Files\doxygen\bin;C:\Program Files\Git\cmd;C:\Program Files
                               (x86)\MiKTeX 2.9\miktex\bin;C:\Program
                               Files\Mercurial;C:\Program Files\TortoiseSVN\bin;C:\Program
                               Files\gs\gs9.21\bin;C:\Program Files (x86)\Pandoc;C:\Program
                               Files\Microsoft SQL
                               Server\120\Tools\Binn;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Windows\System32;C:\Windows;C:\Windows\System32\wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Windows\System32\OpenSSH;C:\Program
                               Files (x86)\GitExtensions;C:\Program Files
                               (x86)\Intel\Intel(R) Management Engine
                               Components\DAL;C:\Program Files\Intel\Intel(R) Management
                               Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R)
                               Management Engine Components\IPT;C:\Program
                               Files\Intel\Intel(R) Management Engine
                               Components\IPT;C:\Users\Gustaf.Rydevik\Documents\R\win-library\4.0\rstan\include\example-models-master\UsersGustaf.RydevikAppDataLocalMicrosoftWindowsApps;C:\Users\Gustaf.Rydevik\Documents\R\win-library\4.0\rstan\include\example-models-master\
                               c:\rtools40\bin;c:\rtools40\perl\bin;C:\rtools40\mingw64\bin

I’m now at a loss - any suggestions?

Just found this v. similar issue: Problems getting Stan to run after upgrading to R 4.0.2

From that thread, I get the following when checking BINPREF, makevars.win, and Renviron:

 Sys.getenv("BINPREF")
[1] ""
> readLines("~/.R/Makevars.win")
[1] "CXX14FLAGS += -O3 -mmmx -msse -msse2 -msse3 -mssse3 -msse4.1 -msse4.2"
> readLines("~/.Renviron")
[1] "PATH=\"${RTOOLS40_HOME}\\usr\\bin;${PATH}\""

Finally, as adviced in the thread, I looked and found an old .Rprofile file where the rtools references were, and after removing it (physically deleting it), it worked! Quest success - sorry for adding a new thread here.

2 Likes

Glad you got it working!

No worries, this is our fault. The rstan installation instructions for R 4.x don’t properly account for the settings that were recommended when installing rstan with R 3.x. Glad it’s working for you now!