Error in file(con, "r"); editing makevars.win

Hi, I am brand new to Stan. I am using Windows 10 and have installed the latest versions of R, RStudio, Rtools, and RStan. However, when I try to run a script with RStan, I get the error message:

Error in file(con, “r”) : cannot open the connection
In addition: Warning messages:
1: In system(paste(CXX, ARGS), ignore.stdout = TRUE, ignore.stderr = TRUE) :
‘C:/rtools40/usr/mingw_/bin/g++’ not found
2: In system(cmd, intern = !verbose) :
running command ‘C:/PROGRA~1/R/R-40~1.2/bin/x64/R CMD SHLIB file5f8486d7460.cpp 2> file5f8486d7460.cpp.err.txt’ had status 1
3: In file(con, “r”) :
cannot open file ‘file5f8486d7460.cpp.err.txt’: No such file or directory
Error in sink(type = “output”) : invalid connection

This error seems to be a common one, and I have seen many suggestions on this forum and others to resolve it, most of which involve editing a makevars.win file. However, I am unable to locate this file on my computer, even though I have tried searching for it, and even if I were to find it, I’m not sure what the best edits to make are to resolve my issue. Any help would be much appreciated - thanks! :)

Hi,

welcome to Stan. Hope you will enjoy it!

see 2. case in Workarounds for current Rstan Windows issues

The workaround for this error does not require edting makevars.

2 Likes

Thank you for the quick response. After trying what it says in the linked post, I am getting:

Error in compileCode(f, code, language = language, verbose = verbose) :
g++.exe: error: Files/R/R-4.0.2/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp: No such file or directorymake: *** [C:/PROGRA~1/R/R-40~1.2/etc/x64/Makeconf:229: file6a3460c4938.o] Error 1
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

When I tried to search for this new error in the forum, I went to this post, where it recommends resolving issues with RStan on Windows by editing .R/Makevars.win, which leads me back to my original question - I am not sure how to do this.

Thanks for your help!

See 1. From the link I posted above

Yes, changing my R package library to be in a path without spaces did the trick…thank you for your help!

2 Likes