Cmdstanr not compiling with R 4.3.0 but is 4.2.2 on linux

My question is similar to Cmdstanr under R4.3 and Rtools 4.3 - Interfaces / CmdStan - The Stan Forums (mc-stan.org) but I am a Linux-based, cloud hosted (by my employer) Posit RStudio Pro.

Basically, cmdstanr works under 4.2.2, but will not compile not 4.3.0. However, if I compile the file under 4.2.2, it will run under 4.3.0

I think I am using the newest version of cmdstanr and Stan from GitHub.

Here is my error on 4.3:

> occ_3_hm <- cmdstan_model("../occstan_hm/stan_files/occupancy_hm_3_a.stan",
+                           cpp_options = list(stan_threads = TRUE))
Compiling Stan program...
Syntax error in '/tmp/RtmprLVa83/model-14661544256.stan', line 2, column 0, include error:
   -------------------------------------------------
     1:  functions{
     2:  #include /scale_cholesky_factor.stan
         ^
     3:  #include /occupancy_3_function.stan
     4:  #include /detect_3.stan
   -------------------------------------------------

Could not find include file '/scale_cholesky_factor.stan' in specified include paths.
Current include paths: None
make: *** [make/program:50: /tmp/RtmprLVa83/model-14661544256.hpp] Error 1

Error: An error occured during compilation! See the message above for more information.

Session info not working:

> sessionInfo()
R version 4.3.0 (2023-04-21)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 20.04.6 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.9.0 
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.9.0

locale:
 [1] LC_CTYPE=C.UTF-8       LC_NUMERIC=C           LC_TIME=C.UTF-8       
 [4] LC_COLLATE=C.UTF-8     LC_MONETARY=C.UTF-8    LC_MESSAGES=C.UTF-8   
 [7] LC_PAPER=C.UTF-8       LC_NAME=C              LC_ADDRESS=C          
[10] LC_TELEPHONE=C         LC_MEASUREMENT=C.UTF-8 LC_IDENTIFICATION=C   

time zone: Etc/UTC
tzcode source: system (glibc)

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

other attached packages:
 [1] cmdstanr_0.5.3  ggthemes_4.2.4  lubridate_1.9.2 forcats_1.0.0   stringr_1.5.0  
 [6] dplyr_1.1.2     purrr_1.0.1     readr_2.1.4     tidyr_1.3.0     tibble_3.2.1   
[11] ggplot2_3.4.2   tidyverse_2.0.0

loaded via a namespace (and not attached):
 [1] tensorA_0.36.2       utf8_1.2.3           generics_0.1.3       stringi_1.7.12      
 [5] hms_1.1.3            magrittr_2.0.3       grid_4.3.0           timechange_0.2.0    
 [9] jsonlite_1.8.7       processx_3.8.2       backports_1.4.1      ps_1.7.5            
[13] fansi_1.0.4          scales_1.2.1         abind_1.4-5          cli_3.6.1           
[17] rlang_1.1.1          crayon_1.5.2         bit64_4.0.5          munsell_0.5.0       
[21] withr_2.5.0          parallel_4.3.0       tools_4.3.0          tzdb_0.4.0          
[25] checkmate_2.2.0      colorspace_2.1-0     vctrs_0.6.3          posterior_1.4.1     
[29] R6_2.5.1             lifecycle_1.0.3      bit_4.0.5            vroom_1.6.3         
[33] pkgconfig_2.0.3      pillar_1.9.0         gtable_0.3.3         glue_1.6.2          
[37] xfun_0.39            tidyselect_1.2.0     rstudioapi_0.14      knitr_1.43          
[41] farver_2.1.1         bayesplot_1.10.0     compiler_4.3.0       distributional_0.3.2

This same code works with R 4.2.2, session info working:

> sessionInfo()
R version 4.2.2 (2022-10-31)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 20.04.6 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.9.0
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.9.0

locale:
 [1] LC_CTYPE=C.UTF-8       LC_NUMERIC=C           LC_TIME=C.UTF-8       
 [4] LC_COLLATE=C.UTF-8     LC_MONETARY=C.UTF-8    LC_MESSAGES=C.UTF-8   
 [7] LC_PAPER=C.UTF-8       LC_NAME=C              LC_ADDRESS=C          
[10] LC_TELEPHONE=C         LC_MEASUREMENT=C.UTF-8 LC_IDENTIFICATION=C   

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

other attached packages:
 [1] cmdstanr_0.5.3  ggthemes_4.2.4  forcats_1.0.0   stringr_1.5.0   dplyr_1.1.0    
 [6] purrr_1.0.1     readr_2.1.4     tidyr_1.3.0     tibble_3.2.1    ggplot2_3.4.2  
[11] tidyverse_1.3.2

loaded via a namespace (and not attached):
 [1] lubridate_1.9.2      ps_1.7.5             assertthat_0.2.1     utf8_1.2.3          
 [5] R6_2.5.1             cellranger_1.1.0     backports_1.4.1      reprex_2.0.2        
 [9] httr_1.4.4           pillar_1.9.0         rlang_1.1.0          googlesheets4_1.0.1 
[13] readxl_1.4.2         data.table_1.14.8    rstudioapi_0.14      checkmate_2.1.0     
[17] googledrive_2.0.0    bit_4.0.5            munsell_0.5.0        broom_1.0.3         
[21] compiler_4.2.2       modelr_0.1.10        xfun_0.38            pkgconfig_2.0.3     
[25] tidyselect_1.2.0     tensorA_0.36.2       fansi_1.0.4          crayon_1.5.2        
[29] tzdb_0.3.0           dbplyr_2.3.0         withr_2.5.0          grid_4.2.2          
[33] distributional_0.3.2 jsonlite_1.8.4       gtable_0.3.3         lifecycle_1.0.3     
[37] DBI_1.1.3            magrittr_2.0.3       posterior_1.4.1      scales_1.2.1        
[41] cli_3.6.1            stringi_1.7.12       vroom_1.6.1          farver_2.1.1        
[45] fs_1.6.1             xml2_1.3.3           ellipsis_0.3.2       generics_0.1.3      
[49] vctrs_0.6.2          tools_4.2.2          bit64_4.0.5          glue_1.6.2          
[53] hms_1.1.2            parallel_4.2.2       processx_3.8.1       abind_1.4-5         
[57] timechange_0.2.0     colorspace_2.1-0     gargle_1.3.0         bayesplot_1.10.0    
[61] rvest_1.0.3          knitr_1.42           haven_2.5.1    

I guess my question is, what should I do? I’ve tried (last week):

  • Upgrading cmdstanr
  • Reinstalling/upgrading Stan

So, right now I’m just using the old version of R.

@Jonah might know. We seem to be having more issues with the latest cmdstanr for some reason. Is your Stan program a bunch of includes or is that some artifact of cmdstanr? If it jus can’t find your include files, then maybe you can give it a directory of places to look, because I think it looks in the local directories otherwise, not parallel to the model you specified.

The doc for the model call

redirects to here with R’s ... arg convention to give you arguments for this function

I would try providing a path to the include directories there.

@Bob_Carpenter, thank you for getting back to me.

cmdstanr can find the main file, but cannot find the function files I have with #include using the path from the main model file.

I am using the same version of cmdstanr on 4.2.2 as 4.3.0, but only 4.3.0 does not work, which makes this weird.

I will try absolute file paths when I have time and report back.

Can you try with the latest version (0.6.0)? We fixed some issues with the include paths after 0.5.3

@andrjohns Thank you! This worked (I finally had time to check).