Hello. I am trying to install rstan fresh on a new machine. I have followed all the steps given here (RStan Getting Started · stan-dev/rstan Wiki · GitHub) but I cannot get the test model to run (example(stan_model, package = "rstan", run.dontrun = TRUE), nor can I get any of my own models to run.
Using my own models, I get the following error:
Error in compileCode(f, code, language = language, verbose = verbose) : Error in sink(type = "output") : invalid connection
To be clear, I have tried to install rstan both normally and from source. From what I can tell, it actually installs without any issues.
Operating system: Windows 11
RStan version: 2.21.8 seems to be installed
Output of writeLines(readLines(file.path(Sys.getenv("HOME"), ".R/Makevars"))):
Error in file(con, "r") : cannot open the connection In addition: Warning message: In file(con, "r") : cannot open file 'C:/Users/user/Documents/.R/Makevars': No such file or directory
There are binary versions available but the source versions are later:
binary source needs_compilation
StanHeaders 2.21.0-7 2.26.22 TRUE
rstan 2.21.8 2.26.22 TRUE
installing the source packages ‘StanHeaders’, ‘rstan’
Warning in install.packages :
installation of package ‘StanHeaders’ had non-zero exit status
Warning in install.packages :
installation of package ‘rstan’ had non-zero exit status
The downloaded source packages are in
‘C:\Users\user\AppData\Local\Temp\RtmpwJGzkf\downloaded_packages’
I have. I installed version Rtools 43 (presumably this is the version I would want?). Just to double check, I uninstalled it and reinstalled it just now and the error is still persisting.
All the output it gives me is just what I pasted above, so maybe not that helpful…
Warning in install.packages :
installation of package ‘Rcpp’ had non-zero exit status
This means that it did not install successfully, and it’s just reverted to the existing binary package. This isn’t an rstan issue, it’s your R or Rtools installation
Do you have any .Renviron or .Rprofile files where you’ve changed settings?
I only installed R fresh yesterday as this is a new machine, so I haven’t changed anything knowingly. Is there something I can check to make sure everything in the background is set up correctly?
pkgbuild::check_build_tools(debug = TRUE)
Scanning R CMD config CC…
cc_path:
‘’ does not exist
Scanning path…
ls: C:\rtools43\usr\bin\ls.exe
gcc_path: C:\rtools43\X86_64~1.POS\bin\gcc.exe
Scanning registry…
Found C:/rtools42 for 4.2
Found C:/rtools43 for 4.3.5550
Your system is ready to build packages!
pkgbuild::check_compiler(debug = TRUE)
Trying to compile a simple C file
Running “C:/PROGRA~1/R/R-43~1.0/bin/x64/Rcmd.exe” SHLIB foo.c
Error: Failed to compile C code
It seems to be referring also to rtools42 which I think I installed by mistake first but then uninstalled and deleted the files. I wonder if that is causing problems?
Running the code you pasted prompted the installation of a C++ compiler. I click yes and it seems to download something, but the code gives this error:
Wow, it really doesn’t want to find your toolchain. All I can think of now is to check your path and config, after that the only option might be to try completely uninstalling and re-installing both R and Rtools.
readLines("~/.Rprofile"): Error in file(con, “r”) : cannot open the connection
In addition: Warning message:
In file(con, “r”) :
cannot open file ‘C:/Users/user/Documents/.Rprofile’: No such file or directory
I don’t mind doing a fresh install if it’s needed. I’ve never had this much trouble getting stan installed though, its weird.
Ah, it looks like you do have an .Renviron file with a setting changed.
Can you delete that file in your home directory (usually your documents folder), then restart R and try running pkgbuild::check_compiler(debug = TRUE) again?