Fatal error on new laptop with transferred library

I am trying to install the ‘rethinking’ package following these instructions: GitHub - rmcelreath/rethinking: Statistical Rethinking course and book package.
I cannot run rstan without my session encountering a fatal error and aborting.

I have a new laptop (windows10, R 4.2.1) and transferred my R library from old computer (windows10, R4.1.0). This has worked successfully for other packages, but I believe this has caused some issues for stan. I’m not sure how to set things straight.

I uninstalled rethinking, rStan, StanHeaders, devTools, rstantools, packages, but there may be some dependencies that I missed.
I installed Rtools42 and check the configuration re the

[1] ""

I have used the repo to try to install packages and restart the R session after I remove a package before trying to install it again.

remove.packages(c("StanHeaders", "rstan"))
install.packages("StanHeaders", repos = c("https://mc-stan.org/r-packages/", getOption("repos")))
install.packages("rstan", repos = c("https://mc-stan.org/r-packages/", getOption("repos")))

After installing rstan and StanHeaders, I get this for the Makevars:

#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/myName/OneDrive - myOrg/Documents/.R/Makevars': No such file or directory

Error in loadNamespace(x) : there is no package called ‘devtools’

^the first result is the same message I get on my old laptop that doesn’t abort and runs stan. The second, makes sense since I removed the devtools package.

What do you get from:

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

I get the bomb icon and a message R session has aborted.

I think the issue here is going to be the fact that the packages in your transferred library were built/installed under 4.1, and you’re now working with 4.2. The RTools toolchain changed between the two versions, so packages built under the old toolchain might experience issues when working with packages under the new toolchain.

The first step here is going to be removing and reinstalling some of the key dependencies for rstan. Can you restart your R session, making sure that no packages or objects get loaded, and run:

install.packages(c("BH","Rcpp","RcppEigen","RcppParallel"), type = "source" )

Then try the example model again?

Aha! It worked.
How would I figure out which dependencies to reinstall on my own? How would I determine if they were key dependencies?

It’s the packages that provide some C++ functionality that rstan needs for compiling models, you can refer to the LinkingTo section of the package description on CRAN for this: CRAN - Package rstan


1 Like