Problem with rstan & R-4.0.5 on Windows

After updating to R-4.0.5 rstan has broken. Code which previously was working crashes when calling stan. It seems the problem is some environment variable but I am unable to corrrect it.
(This happens for every model)

The error message is as follows:

Translate model to C++ and compile to DSO:

stanDso ← stan_model( model_code=modelString )

Error in inDL(x, as.logical(local), as.logical(now), …): unable to load shared object ‘C:/Users/josep/AppData/Local/Temp/Rtmpw5K3Oc/file413c70f952de.dll’:
LoadLibrary failure: A dynamic link library (DLL) initialization routine failed.

Traceback:

  1. stan_model(model_code = modelString)

  2. cxxfunctionplus(signature(), body = paste(" return Rcpp::wrap("",
    . model_name, “”);", sep = “”), includes = inc, plugin = “rstan”,
    . save_dso = save_dso | auto_write, module_name = paste(“stan_fit4”,
    . model_cppname, “_mod”, sep = “”), verbose = verbose)

  3. pkgbuild::with_build_tools(cxxfunction(sig = sig, body = body,
    . plugin = plugin, includes = includes, settings = settings,
    . …, verbose = verbose), required = rstan_options(“required”) &&
    . !identical(Sys.getenv(“WINDOWS”), “TRUE”) && !identical(Sys.getenv(“R_PACKAGE_SOURCE”),
    . “”))

  4. withr::with_path(rtools_path(), code)

  5. force(code)

  6. cxxfunction(sig = sig, body = body, plugin = plugin, includes = includes,
    . settings = settings, …, verbose = verbose)

  7. dyn.load(libLFile)

  8. inDL(x, as.logical(local), as.logical(now), …)
    Error in sink(type = “output”): invalid connection
    Traceback:

  9. stan_model(model_code = modelString)

  10. cxxfunctionplus(signature(), body = paste(" return Rcpp::wrap("",
    . model_name, “”);", sep = “”), includes = inc, plugin = “rstan”,
    . save_dso = save_dso | auto_write, module_name = paste(“stan_fit4”,
    . model_cppname, “_mod”, sep = “”), verbose = verbose)

  11. sink(type = “output”)

Can you restart R (making sure that rstan doesn’t get loaded) and run:

remove.packages(c("StanHeaders", "rstan")) 

# Compile packages using all cores 
Sys.setenv(MAKEFLAGS = paste0("-j",parallel::detectCores()))

install.packages(c("StanHeaders","rstan"),type="source")
1 Like

Thanks so much! It worked!!

I must say however, that whereas rstan compilation finished Ok, it gave an ENORMOUS quantity of fearful warnings and errors.

1 Like

Great! Those are fine to ignore