Error in brms compiling

Hi,

I’m trying to fit a brms model that previously worked fine, and get the warning

“Compiling Stan program…
The NEXT version of Stan will not be able to pre-process your Stan program.
Please open an issue at
Issues · stan-dev/stanc3 · GitHub
if you can share or at least describe your Stan program. This will help ensure that Stan
continues to work on your Stan programs in the future. Thank you!
This message can be avoided by wrapping your function call inside suppressMessages().
cannot remove file ‘C:\Users\canaa\AppData\Local\Temp\RtmpgtGlUo\file962869932f4d.stan’, reason ‘No such file or directory’”

I can’t locate the specific temporary file, and have uninstalled and reinstalled r, rstudio, and rtools to the latest version. I’m on Windows 10 x64. The function then halts and throws this warning:

Error in compileCode(f, code, language = language, verbose = verbose) : Compilation ERROR, function(s)/method(s) not created! C:/rtools40/mingw64/bin/…/lib/gcc/x86_64-w64-mingw32/8.3.0/…/…/…/…/x86_64-w64-mingw32/bin/ld.exe: file96286eb28c9.o:file96286eb28c9.cpp:(.text+0xe4c): undefined reference to tbb::internal::task_scheduler_observer_v3::observe(bool)' C:/rtools40/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: file96286eb28c9.o:file96286eb28c9.cpp:(.text+0x2787): undefined reference to rstan::stan_fit::stan_fit(SEXPREC*, int)’ C:/rtools40/mingw64/bin/…/lib/gcc/x86_64-w64-mingw32/8.3.0/…/…/…/…/x86_64-w64-mingw32/bin/ld.exe: file96286eb28c9.o:file96286eb28c9.cpp:(.text+0xe8e): undefined reference to `tbb::internal::task_scheduler_observer_v3::observe(bool)’ C:/rtools40/mingw64/bin/…/lib/gcc/x86_64-w64-mingw32/8.3.0/…/…/…/…/x86_64-w64-mingw32/bin/ld.exe: file96286eb28c9.o:file96286eb28c9.cpp:(.text$_ZN3tbb8internal26task_scheduler_observer_v3D1Ev[_ZN3tbb8internal26task_scheduler_observe

Any suggestions?

Today I updated R to v.4.0.2, udated all packages, too. Now I’m getting almost identical errors as Canaan_Breiss whether I run the models directly in rstan as Stan programs or through brms. I get the following message when running one of Stan’s stan_demo() models:

The NEXT version of Stan will not be able to pre-process your Stan program.
Please open an issue at
https://github.com/stan-dev/stanc3/issues
if you can share or at least describe your Stan program. This will help ensure that Stan
continues to work on your Stan programs in the future. Thank you!
This message can be avoided by wrapping your function call inside suppressMessages().
Error in compileCode(f, code, language = language, verbose = verbose) :
Compilation ERROR, function(s)/method(s) not created! C:/rtools40/mingw64/bin/…/lib/gcc/x86_64-w64-mingw32/8.3.0/…/…/…/…/x86_64-w64-mingw32/bin/ld.exe: file215c36107370.o:file215c36107370.cpp:(.text+0x134c): undefined reference to `rstan::stan_fit::stan_fit(SEXPREC*, int)’
<<…and so on…>>

This might help?

Tried this, got errors:

Downloading GitHub repo stan-dev/rstan@develop
stan-dev-rstan-a9b5554/StanHeaders/inst/include/libsundials: Can’t create ‘\\?\C:\Users\canaa\AppData\Local\Temp\RtmpqQj6gu\remotes6d30164d62a5\stan-dev-rstan-a9b5554\StanHeaders\inst\include\libsundials’
stan-dev-rstan-a9b5554/StanHeaders/inst/include/src: Can’t create ‘\\?\C:\Users\canaa\AppData\Local\Temp\RtmpqQj6gu\remotes6d30164d62a5\stan-dev-rstan-a9b5554\StanHeaders\inst\include\src’
stan-dev-rstan-a9b5554/StanHeaders/inst/include/stan: Can’t create ‘\\?\C:\Users\canaa\AppData\Local\Temp\RtmpqQj6gu\remotes6d30164d62a5\stan-dev-rstan-a9b5554\StanHeaders\inst\include\stan’
tar.exe: Error exit delayed from previous errors.
“C:\PROGRA~1\Git\cmd\git.exe” clone --depth 1 --no-hardlinks --recurse-submodules --branch develop https://github.com/stan-dev/stan.git C:\Users\canaa\AppData\Local\Temp\RtmpqQj6gu\remotes6d30164d62a5/stan-dev-rstan-a9b5554/rstan/rstan/…/…/StanHeaders/inst/include/upstream
Error: Failed to install ‘rstan’ from GitHub:
Command failed (128)
In addition: Warning messages:
1: In utils::untar(tarfile, …) :
‘tar.exe -xf “C:\Users\canaa\AppData\Local\Temp\RtmpqQj6gu\file6d309a57024.tar.gz” -C “C:/Users/canaa/AppData/Local/Temp/RtmpqQj6gu/remotes6d30164d62a5”’ returned error code 1
2: In system(full, intern = TRUE, ignore.stderr = quiet) :
running command ‘“C:\PROGRA~1\Git\cmd\git.exe” clone --depth 1 --no-hardlinks --recurse-submodules --branch develop https://github.com/stan-dev/stan.git C:\Users\canaa\AppData\Local\Temp\RtmpqQj6gu\remotes6d30164d62a5/stan-dev-rstan-a9b5554/rstan/rstan/…/…/StanHeaders/inst/include/upstream’ had status 128

Unsure what else to try?

This looks very strange…

Let’s see if someone with Windows can decipher this :) @bgoodri might be the one

Hi there,

Today I installed the latest versions of R, Rstudio, and Rtools on a Windows 10 x64 machine, and I downloaded the latest version of brms and rstan. I tried to run several models with the brm() function but unfortunately I have not been able to obtain any result.

For instance:

> set.seed(112358)
> 
> db <- data.frame(grp=rbinom(n=2000,size=1, prob=.5),
+                  xcont=rnorm(n=2000, mean=0, sd=2),
+                  xcat=factor(rbinom(n=2000, size=4, prob=.24)),
+                  y=rbinom(n=2000, size=10, prob=.5))
> 
> fit <- brm(y ~ xcat + xcont +
+              (1 | grp),
+            data=db,
+            chains= 1,
+            iter = 4000,
+            warmup = 1000,
+            seed = 112358)
Compiling Stan program...

Then, after few seconds, it stops without returning any error or warning message, and of course any object.

Furthermore, I followed the steps above and I am getting the same errors of Canaan_Breiss and Michael_Thompson.

Thanks in advance.

I was having this same exact problem until I rolled Stan back to version 2.19.3, as suggested by Dr. Bürkner on another thread: Potential Problems with rstan and /or brms packages in R 4.0.2

Hi all, I am getting a similar error as the OP with a brms::brm model:

Compiling Stan program...
Error in compileCode(f, code, language = language, verbose = verbose) : 
  Compilation ERROR, function(s)/method(s) not created! C:/Program Files/R/R-4.0.4/library/rstan/lib/x64/libStanServices.a(stan_fit.o): duplicate section `.rdata$_ZTIN5boost10wrapexceptISt12domain_errorEE[_ZTIN5boost10wrapexceptISt12domain_errorEE]' has different size
C:/Program Files/R/R-4.0.4/library/rstan/lib/x64/libStanServices.a(stan_fit.o): duplicate section `.rdata$_ZTIN5boost10wrapexceptISt14overflow_errorEE[_ZTIN5boost10wrapexceptISt14overflow_errorEE]' has different size
C:/Program Files/R/R-4.0.4/library/rstan/lib/x64/libStanServices.a(stan_fit.o): duplicate section `.rdata$_ZTIN5boost10wrapexceptISt11logic_errorEE[_ZTIN5boost10wrapexceptISt11logic_errorEE]' has different size
C:/Program Files/R/R-4.0.4/library/rstan/lib/x64/libStanServices.a(stan_fit.o): duplicate section `.rdata$_ZTIN5boost10wrapexceptINS_4math16evaluation_errorEEE[_ZTIN5boost10wrapexceptINS_4math16evaluation_errorEEE]' has different size
C:/Program Files/R/R-4.0.4/library/rstan/lib/x64/libStanServ
In addition: Warning message:
In system(paste(CXX, ARGS), ignore.stdout = TRUE, ignore.stderr = TRUE) :
  '-E' not found
Error in sink(type = "output") : invalid connection

I was having similar errors with R version 4.0.2, so I updated R, and everything else:

sessionInfo()
R version 4.0.4 (2021-02-15)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] rstan_2.21.2         ggplot2_3.3.3        StanHeaders_2.21.0-7 brms_2.14.4         
 [5] Rcpp_1.0.5           MCMCglmm_2.30        coda_0.19-4          Matrix_1.3-2        
 [9] geiger_2.0.7         ape_5.4             

loaded via a namespace (and not attached):
  [1] cubature_2.0.4.1        minqa_1.2.4             colorspace_1.4-1       
  [4] ellipsis_0.3.1          ggridges_0.5.3          rsconnect_0.8.16       
  [7] estimability_1.3        corpcor_1.6.9           markdown_1.1           
 [10] base64enc_0.1-3         rstudioapi_0.13         DT_0.17                
 [13] fansi_0.4.1             mvtnorm_1.1-1           codetools_0.2-18       
 [16] bridgesampling_1.0-0    splines_4.0.4           mnormt_2.0.1           
 [19] knitr_1.31              shinythemes_1.2.0       bayesplot_1.8.0        
 [22] projpred_2.0.2          jsonlite_1.7.2          nloptr_1.2.2.2         
 [25] shiny_1.6.0             compiler_4.0.4          emmeans_1.5.4          
 [28] backports_1.1.7         assertthat_0.2.1        fastmap_1.0.1          
 [31] cli_2.3.1               later_1.1.0.1           prettyunits_1.1.1      
 [34] htmltools_0.5.1.1       tools_4.0.4             igraph_1.2.5           
 [37] gtable_0.3.0            glue_1.4.1              reshape2_1.4.4         
 [40] clusterGeneration_1.3.7 dplyr_1.0.2             maps_3.3.0             
 [43] V8_3.2.0                fastmatch_1.1-0         vctrs_0.3.2            
 [46] nlme_3.1-152            crosstalk_1.1.1         tensorA_0.36.2         
 [49] xfun_0.15               stringr_1.4.0           ps_1.3.3               
 [52] lme4_1.1-23             mime_0.9                miniUI_0.1.1.1         
 [55] lifecycle_1.0.0         phangorn_2.5.5          gtools_3.8.2           
 [58] statmod_1.4.34          MASS_7.3-53             zoo_1.8-8              
 [61] scales_1.1.1            subplex_1.6             colourpicker_1.1.0     
 [64] promises_1.1.1          Brobdingnag_1.2-6       parallel_4.0.4         
 [67] inline_0.3.17           expm_0.999-5            shinystan_2.5.0        
 [70] animation_2.6           curl_4.3                gamm4_0.2-6            
 [73] yaml_2.2.1              gridExtra_2.3           loo_2.4.1              
 [76] stringi_1.4.6           dygraphs_1.1.1.6        plotrix_3.8-1          
 [79] phytools_0.7-70         boot_1.3-27             pkgbuild_1.2.0         
 [82] rlang_0.4.7             pkgconfig_2.0.3         matrixStats_0.56.0     
 [85] evaluate_0.14           lattice_0.20-41         purrr_0.3.4            
 [88] rstantools_2.1.1        htmlwidgets_1.5.3       processx_3.4.5         
 [91] tidyselect_1.1.0        deSolve_1.28            plyr_1.8.6             
 [94] magrittr_2.0.1          R6_2.5.0                generics_0.1.0         
 [97] combinat_0.0-8          withr_2.4.1             pillar_1.4.6           
[100] mgcv_1.8-33             xts_0.12-0              scatterplot3d_0.3-41   
[103] abind_1.4-5             tibble_3.0.3            crayon_1.4.1           
[106] tmvnsim_1.0-2           rmarkdown_2.7           grid_4.0.4             
[109] callr_3.5.1             threejs_0.3.3           digest_0.6.25          
[112] xtable_1.8-4            httpuv_1.5.4            numDeriv_2016.8-1.1    
[115] RcppParallel_5.0.2      stats4_4.0.4            munsell_0.5.0          
[118] quadprog_1.5-8          shinyjs_2.0.0         

I have tried to look into the file that the error is referencing (libStanServices.a) to look for something that might be duplicated, but I am not familiar with the format. Also not sure if it is helpful, but Stan compiles from rstanarm without any issues. Any ideas?

What output do you get from the RStan example model:

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

The output the first time I ran it was much larger than the space in the console, but the second time was much shorter and manageable… not sure why. The output is attached.

stan_model.txt (8.8 KB)

There aren’t any errors in that output, it looks like everything ran and sampled fine?

No errors, just the warning
Warning message: In system(paste(CXX, ARGS), ignore.stdout = TRUE, ignore.stderr = TRUE) : '-E' not found
Stan seems to compile fine from rstanarm as well, but not for brms.

That’s because there’s actually no compiling in rstanarm.

Can you try restarting R, and reinstalling RcppParallel, rstan, and StanHeaders from source?

Make sure that rstan isn’t loaded, otherwise that’ll cause issues

I apologize for the naivety - I get an error, but perhaps I am missing a step. When I just add type="source" to install.packages (see below), R can’t find ggplot2 or rstan.

However answers to this question (How do I install an R package from source? - Stack Overflow) suggest adding paths to the package or a url. In my ~/library/rstan directory, I do not see any .gz or .tar files (like answers to that post are suggesting), and I am unsure what exactly I should be referencing from (GitHub - stan-dev/rstan: RStan, the R interface to Stan) in a url.

install.packages(c("RcppParallel", "rstan", "StanHeaders"), type = "source")
Error in install.packages : Updating loaded packages
Loading required package: rstan
Loading required package: ggplot2
Error: package or namespace load failed for ‘ggplot2’ in loadNamespace(i, c(lib.loc, .libPaths()), versionCheck = vI[[i]]):
 namespace ‘rlang’ 0.4.7 is already loaded, but >= 0.4.10 is required
Failed with error:  ‘package ‘ggplot2’ could not be loaded’
Error in .requirePackage(package) : 
  unable to find required package ‘rstan’
Loading required package: rstan
Loading required package: ggplot2
Error: package or namespace load failed for ‘ggplot2’ in loadNamespace(i, c(lib.loc, .libPaths()), versionCheck = vI[[i]]):
 namespace ‘rlang’ 0.4.7 is already loaded, but >= 0.4.10 is required
Failed with error:  ‘package ‘ggplot2’ could not be loaded’
Error in .requirePackage(package) : 
  unable to find required package ‘rstan’
Loading required package: rstan
Loading required package: ggplot2
Error: package or namespace load failed for ‘ggplot2’ in loadNamespace(i, c(lib.loc, .libPaths()), versionCheck = vI[[i]]):
 namespace ‘rlang’ 0.4.7 is already loaded, but >= 0.4.10 is required
Failed with error:  ‘package ‘ggplot2’ could not be loaded’
Error in .requirePackage(package) : 
  unable to find required package ‘rstan’

Can you close and re-open R/RStudio, making sure that no packages are loaded, and run:

# Remove old packages
remove.packages(c("rstan","StanHeaders","RcppParallel"))

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

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

Removing packages worked fine, but there were errors in installing from source (see attached .txt)

SourceInstallErrors.txt (7.0 KB)

Try restarting R after uninstalling rstan, before installing RcppParallel

It looks like restarting R didn’t make a difference.
I include the output here just in case I missed something. SourceInstallErrors2.txt (7.1 KB)

Hmm, something’s a bit off there. For now just install the RcppParallel binary (install.packages as usual), and then install rstan and StanHeaders from source

That allowed RcppParallel and StanHeaders to install, but still not rstan from source. The output is huge rstan_SourceInstall.txt (339.5 KB)

However, after installing the rstan binary and updating rlang, the Stan program is compiled when called from brms::brm.

Thank you so much for all your help Andrew.

1 Like