When I fix my package (containing precompiled stan models) makevars.win with the following line, package building and functions using the precompiled models works fine:
PKG_LIBS = $(shell "$(R_HOME)/bin$(R_ARCH_BIN)/Rscript" -e "cat(paste0(system.file('lib/x64', package = 'rstan', mustWork = TRUE),'/libStanServices.a'))") -L$(shell "$(R_HOME)/bin$(R_ARCH_BIN)/Rscript" -e "cat(system.file('libs/x64', package = 'StanHeaders', mustWork = TRUE))") -lStanheaders -L$(shell "$(R_HOME)/bin$(R_ARCH_BIN)/Rscript" -e "cat(system.file('lib/x64', package = 'RcppParallel', mustWork = TRUE))") -ltbb $(shell "$(R_HOME)/bin$(R_ARCH_BIN)/Rscript" -e "RcppParallel::RcppParallelLibs()") $(shell "$(R_HOME)/bin$(R_ARCH_BIN)/Rscript" -e "StanHeaders:::LdFlags()")
However, when I try the supposed fix of:
Sys.setenv(PKG_LIBS = Sys.getenv("LOCAL_LIBS"))
or more conveniently for a package, putting this code before any compilation requiring code:
if(.Platform$OS.type=="windows" && R.Version()$major >=4 && R.Version()$minor >= 2 &&
compareVersion(as.character(packageVersion('rstan')[[1]]),'2.25.0') == -1){
Sys.setenv(PKG_LIBS=
paste0('\"',system.file('lib/x64', package = 'rstan', mustWork = TRUE),'/libStanServices.a','\"',
' -L','\"',system.file('libs/x64', package = 'StanHeaders', mustWork = TRUE),'\"',
' -lStanHeaders -L','\"',system.file('lib/x64', package = 'RcppParallel', mustWork = TRUE),'\"',
' -ltbb'))
}
Compilation of further models now succeeds (where before it would give a compile error) but now the R session crashes when I try to sample or optimize, in both 1 core and multicore cases. Any ideas? Updates in question are pushed to master of GitHub - cdriveraus/ctsem: Hierarchical continuous time state space modelling