H:/rtools40/usr/mingw_/bin/g++ not found

readLines(“~/.Rprofile”)
[1] “Sys.setenv(BINPREF = "H:/Rtools/mingw_(WIN)/bin/\")" [2] "Sys.setenv(BINPREF = \"H:/Rtools/mingw_(WIN)/bin/")”

readLines(“~/.Renviron”)
[1] “PATH="{RTOOLS40_HOME}\\usr\\bin;{PATH}"”

Thanks! The issue is that the BINPREF environment variable is telling R to look for the compiler in the old RTools directory. In your home directory (usually your Documents folder) there will be a file called .Rprofile, delete that file and then restart R and try your model again

okay

i cannot find the .Rprofile. I can see .Rhistory and .Rdata

is .R same as .Rprofile

We can try to delete it a different way. Can you post the output from:

unlink("~/.Rprofile")
readLines("~/.Rprofile")

unlink(“~/.Rprofile”)
readLines(“~/.Rprofile”)
cannot open file ‘H://.Rprofile’: No such file or directoryError in file(con, “r”) : cannot open the connection

Great, that means the unlink command successfully deleted the file. Can you restart R and try your model again?

okay

Thank you andrjohn, it is working and analysing my dataset well.
Thanks

2 Likes

Thanks @andrjohns. Your diagnosis solved a similar problem on my end where the same rstan code would run just fine from inside a particular R project but threw errors like @ChinyUgo’s when run from inside the default R Studio path. In my case, the later path had bad content inside its .Rprofile.

Hello @andrjohns , I got the same error today. I am not sure why this has happened, I managed to edit one of my models. And something went wrong, so I reinstalled rstan and its dependencies but the usual example line gave me the following error. I spent the whole day troubleshooting this using this post, and an earlier installation post I found but with no luck.

The code I ran is :

example(stan_model, package = "rstan", run.dontrun = TRUE)

This is the error messege I recieved:

Compilation ERROR, function(s)/method(s) not created!
Error in compileCode(f, code, language = language, verbose = verbose) : 
  In file included from <command-line>:C:/Users/R/R-4.0.3/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:13:10: fatal error: Eigen/Dense: No such file or directory #include <Eigen/Dense>          ^~~~~~~~~~~~~compilation terminated.make: *** [C:/Users/R/R-40~1.3/etc/x64/Makeconf:229: file6cf050fc5087.o] Error 1
In addition: Warning message:
In system(paste(CXX, ARGS), ignore.stdout = TRUE, ignore.stderr = TRUE) :
  'C:/Users/R-34~1.3/rtools40/usr/mingw_/bin/g++' not found

Additional info that could be needed:

  • Operating System Windows 10
  • RStan Version 2.21.2
  • Stan Headers version 2.21.0-7
  • RcppParallel version 5.0.2
  • 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 ‘\network\userhome\students4\My Documents/.R/Makevars’: No such file or directory

I managed to find out where the problem was coming form. For some reason my default library path changed to the network, and was accessing older files and Packages causing the error I posted. I had to change my libPath to my old library in C drive, then reinstall rstan with the recommended withr Package 2.2.0. And that resolved it for me. I initially had a clash because withr was used by two packages I have ‘StreamMetabolizer’ and ‘rstan’. So I installed the Stream one with the newer withr. Then uninstall it and installed it again with the older withr version. This allowed the model to work. I just have the following two warnings now, which I have no idea why they happen. Shall I be concerned about them?

Warning messages:
1: In find.package(package, lib.loc, verbose = verbose) :
package ‘base’ found more than once, using the first from
“C:/Users/R/R-40~1.3/library/base”,
“C:/Users/R/R-4.0.3/library/base”

2: In system(paste(CXX, ARGS), ignore.stdout = TRUE, ignore.stderr = TRUE) :
‘C:/Users/R-34~1.3/rtools40/usr/mingw_/bin/g++’ not found

1 Like