Installation error rstan 2.21.8 when updating from 2.21.2

Hi there,

I was hoping to update my laptop rstan from 2.21.2 to 2.21.8 so that it better accommodates integer arrays. (The code int person[Nobs]; threw an error in the earlier version but worked fine in the newer one.) I removed the old package and did
install_version('rstan', version = '2.21.8', type = 'source') but received a large chunk of compilation errors. The head of these errors looked like these

The last bit of these errors looked like this.

In file included from C:/Users/Marco/OneDrive/Documents/R/win-library/3.6/StanHeaders/include/stan/math/prim/meta.hpp:65:0,
                 from C:/Users/Marco/OneDrive/Documents/R/win-library/3.6/StanHeaders/include/stan/math/prim/mat/fun/csr_extract_u.hpp:4,
                 from sparse_extractors.cpp:2:
C:/Users/Marco/OneDrive/Documents/R/win-library/3.6/StanHeaders/include/stan/math/prim/scal/meta/scalar_type_pre.hpp:12:9: error: expected nested-name-specifier before 'type'
   using type = T_container;
         ^
C:/Users/Marco/OneDrive/Documents/R/win-library/3.6/StanHeaders/include/stan/math/prim/scal/meta/scalar_type_pre.hpp:17:9: error: expected nested-name-specifier before 'type'
   using type = typename scalar_type_helper_pre<
         ^
C:/Users/Marco/OneDrive/Documents/R/win-library/3.6/StanHeaders/include/stan/math/prim/scal/meta/scalar_type_pre.hpp:32:9: error: expected nested-name-specifier before 'type'
   using type = typename internal::scalar_type_helper_pre<
         ^
In file included from C:/Users/Marco/OneDrive/Documents/R/win-library/3.6/StanHeaders/include/stan/math/prim/meta.hpp:68:0,
                 from C:/Users/Marco/OneDrive/Documents/R/win-library/3.6/StanHeaders/include/stan/math/prim/mat/fun/csr_extract_u.hpp:4,
                 from sparse_extractors.cpp:2:
C:/Users/Marco/OneDrive/Documents/R/win-library/3.6/StanHeaders/include/stan/math/prim/scal/meta/StdVectorBuilder.hpp:37:9: error: expected nested-name-specifier before 'helper'
   using helper
         ^
C:/Users/Marco/OneDrive/Documents/R/win-library/3.6/StanHeaders/include/stan/math/prim/scal/meta/StdVectorBuilder.hpp:42:9: error: expected nested-name-specifier before 'type'
   using type = typename helper::type;
         ^
C:/Users/Marco/OneDrive/Documents/R/win-library/3.6/StanHeaders/include/stan/math/prim/scal/meta/StdVectorBuilder.hpp:43:3: error: 'helper' does not name a type
   helper a;
   ^
C:/Users/Marco/OneDrive/Documents/R/win-library/3.6/StanHeaders/include/stan/math/prim/scal/meta/StdVectorBuilder.hpp:49:10: error: 'type' does not name a type
   inline type data() { return a.data(); }
          ^
C:/Users/Marco/OneDrive/Documents/R/win-library/3.6/StanHeaders/include/stan/math/prim/scal/meta/StdVectorBuilder.hpp: In constructor 'stan::StdVectorBuilder<used, T1, T2, T3, T4, T5, T6, T7>::StdVectorBuilder(size_t)':
C:/Users/Marco/OneDrive/Documents/R/win-library/3.6/StanHeaders/include/stan/math/prim/scal/meta/StdVectorBuilder.hpp:45:41: error: class 'stan::StdVectorBuilder<used, T1, T2, T3, T4, T5, T6, T7>' does not have any field named 'a'
   explicit StdVectorBuilder(size_t n) : a(n) {}
                                         ^
C:/Users/Marco/OneDrive/Documents/R/win-library/3.6/StanHeaders/include/stan/math/prim/scal/meta/StdVectorBuilder.hpp: In member function 'T1& stan::StdVectorBuilder<used, T1, T2, T3, T4, T5, T6, T7>::operator[](size_t)':
C:/Users/Marco/OneDrive/Documents/R/win-library/3.6/StanHeaders/include/stan/math/prim/scal/meta/StdVectorBuilder.hpp:47:37: error: 'a' was not declared in this scope
   T1& operator[](size_t i) { return a[i]; }
                                     ^
In file included from C:/Users/Marco/OneDrive/Documents/R/win-library/3.6/StanHeaders/include/stan/math/prim/meta.hpp:69:0,
                 from C:/Users/Marco/OneDrive/Documents/R/win-library/3.6/StanHeaders/include/stan/math/prim/mat/fun/csr_extract_u.hpp:4,
                 from sparse_extractors.cpp:2:
C:/Users/Marco/OneDrive/Documents/R/win-library/3.6/StanHeaders/include/stan/math/prim/scal/meta/VectorBuilder.hpp: At global scope:
C:/Users/Marco/OneDrive/Documents/R/win-library/3.6/StanHeaders/include/stan/math/prim/scal/meta/VectorBuilder.hpp:25:43: warning: variadic templates only available with -std=c++11 or -std=gnu++11
 template <bool used, typename T1, typename... Args>
                                           ^
C:/Users/Marco/OneDrive/Documents/R/win-library/3.6/StanHeaders/include/stan/math/prim/scal/meta/VectorBuilder.hpp:28:9: error: expected nested-name-specifier before 'helper'
   using helper = VectorBuilderHelper<T1, used, contains_vector<Args...>::value>;
         ^
C:/Users/Marco/OneDrive/Documents/R/win-library/3.6/StanHeaders/include/stan/math/prim/scal/meta/VectorBuilder.hpp:31:9: error: expected nested-name-specifier before 'type'
   using type = typename helper::type;
         ^
C:/Users/Marco/OneDrive/Documents/R/win-library/3.6/StanHeaders/include/stan/math/prim/scal/meta/VectorBuilder.hpp:32:3: error: 'helper' does not name a type
   helper a;
   ^
C:/Users/Marco/OneDrive/Documents/R/win-library/3.6/StanHeaders/include/stan/math/prim/scal/meta/VectorBuilder.hpp:38:10: error: 'type' does not name a type
   inline type data() { return a.data(); }
          ^
C:/Users/Marco/OneDrive/Documents/R/win-library/3.6/StanHeaders/include/stan/math/prim/scal/meta/VectorBuilder.hpp: In constructor 'stan::VectorBuilder<used, T1, Args>::VectorBuilder(size_t)':
C:/Users/Marco/OneDrive/Documents/R/win-library/3.6/StanHeaders/include/stan/math/prim/scal/meta/VectorBuilder.hpp:34:38: error: class 'stan::VectorBuilder<used, T1, Args>' does not have any field named 'a'
   explicit VectorBuilder(size_t n) : a(n) {}
                                      ^
C:/Users/Marco/OneDrive/Documents/R/win-library/3.6/StanHeaders/include/stan/math/prim/scal/meta/VectorBuilder.hpp: In member function 'T1& stan::VectorBuilder<used, T1, Args>::operator[](size_t)':
C:/Users/Marco/OneDrive/Documents/R/win-library/3.6/StanHeaders/include/stan/math/prim/scal/meta/VectorBuilder.hpp:36:37: error: 'a' was not declared in this scope
   T1& operator[](size_t i) { return a[i]; }
                                     ^
make: *** [C:/PROGRA~1/R/R-36~1.3/etc/x64/Makeconf:215: sparse_extractors.o] Error 1
ERROR: compilation failed for package 'rstan'

It seems to say something was not loaded correctly? I have Rtools35 and was able to install jsonlite from source as the official guide asked. My OneDrive was paused during this installation. I looked up posts about such errors and tried to change my Makevars file. For the errors above my Makevars file looks like this

CXX14=$(BINPREF)g++ -O2 -march=native -mtune=native
CXX11FLAGS=-O3

Also I read somewhere I should add a space to the g above to make the first line CXX14=$(BINPREF) g++ -O2 -march=native -mtune=native. With that change the errors become shorter

* installing *source* package 'rstan' ...
** package 'rstan' successfully unpacked and MD5 sums checked
** using staged installation
** libs
sh: tail: command not found
C:/RBUILD~1/3.5/mingw_64/bin/ g++ -O2 -march=native -mtune=native  -I"C:/PROGRA~1/R/R-36~1.3/include" -DNDEBUG -I"../inst/include" -I"../inst/include/boost_not_in_BH" -I"." -DBOOST_DISABLE_ASSERTS -DBOOST_PHOENIX_NO_VARIADIC_EXPRESSION -DBOOST_NO_AUTO_PTR -DSTAN_THREADS  -I"C:/Users/Marco/OneDrive/Documents/R/win-library/3.6/Rcpp/include" -I"C:/Users/Marco/OneDrive/Documents/R/win-library/3.6/RcppEigen/include" -I"C:/Users/Marco/OneDrive/Documents/R/win-library/3.6/BH/include" -I"C:/Users/Marco/OneDrive/Documents/R/win-library/3.6/StanHeaders/include" -I"C:/Users/Marco/OneDrive/Documents/R/win-library/3.6/RcppParallel/include"     -DRCPP_PARALLEL_USE_TBB=1    -c sparse_extractors.cpp -o sparse_extractors.o
sh: C:/RBUILD~1/3.5/mingw_64/bin/: Is a directory
make: *** [C:/PROGRA~1/R/R-36~1.3/etc/x64/Makeconf:215: sparse_extractors.o] Error 126
ERROR: compilation failed for package 'rstan'

If I run the Makevars code suggested by the official installation guide CXX14FLAGS += -mtune=native -O3 -mmmx -msse -msse2 -msse3 -mssse3 -msse4.1 -msse4.2 I got the error Error in .shlib_internal(args) : C++14 standard requested but CXX14 is not defined.

I also tried to uninstall all the dependencies and started over but it was not working either. My other packages were installed with the original versions I had.

> packageVersion('StanHeaders')
[1] ‘2.21.0.7’
> packageVersion('Rcpp')
[1] ‘1.0.6’
> packageVersion('RcppEigen')
[1] ‘0.3.3.9.1’

So now I am out of measures about how to fix this issue after half a day looking into this. Any tips on how to proceed with this issue would be much appreciated!

> session_info()
- Session info -------------------------------------------------------------------------------------------------------------------------------------
 setting  value                       
 version  R version 3.6.3 (2020-02-29)
 os       Windows 10 x64              
 system   x86_64, mingw32             
 ui       RStudio                     
 language (EN)                        
 collate  English_United States.1252  
 ctype    English_United States.1252  
 tz       America/New_York            
 date     2024-01-17                  
- Packages -----------------------------------------------------------------------------------------------------------------------------------------
 package     * version   date       lib source        
 assertthat    0.2.1     2019-03-21 [1] CRAN (R 3.6.0)
 backports     1.1.6     2020-04-05 [1] CRAN (R 3.6.3)
 blob          1.2.1     2020-01-20 [1] CRAN (R 3.6.2)
 brio          1.1.2     2021-04-23 [1] CRAN (R 3.6.3)
 callr         3.7.2     2022-08-22 [1] CRAN (R 3.6.3)
 cli           3.4.1     2022-09-23 [1] CRAN (R 3.6.3)
 cluster       2.1.0     2019-06-19 [2] CRAN (R 3.6.3)
 DBI           1.1.0     2019-12-15 [1] CRAN (R 3.6.2)
 dcurver       0.9.1     2018-04-23 [1] CRAN (R 3.6.1)
 Deriv         3.8.5     2018-06-11 [1] CRAN (R 3.6.1)
 desc          1.4.2     2022-09-08 [1] CRAN (R 3.6.3)
 devtools    * 2.2.1     2019-09-24 [1] CRAN (R 3.6.2)
 digest        0.6.19    2019-05-20 [1] CRAN (R 3.6.0)
 dplyr         1.0.6     2021-05-05 [1] CRAN (R 3.6.3)
 ellipsis      0.3.2     2021-04-29 [1] CRAN (R 3.6.3)
 fansi         0.4.0     2018-10-05 [1] CRAN (R 3.6.0)
 fs            1.3.1     2019-05-06 [1] CRAN (R 3.6.0)
 generics      0.0.2     2018-11-29 [1] CRAN (R 3.6.0)
 glue          1.4.2     2020-08-27 [1] CRAN (R 3.6.3)
 GPArotation   2014.11-1 2014-11-25 [1] CRAN (R 3.6.0)
 gridExtra     2.3       2017-09-09 [1] CRAN (R 3.6.0)
 gtable        0.3.0     2019-03-25 [1] CRAN (R 3.6.0)
 lattice       0.20-38   2018-11-04 [2] CRAN (R 3.6.3)
 lavaan        0.6-17    2023-12-20 [1] CRAN (R 3.6.3)
 lifecycle     1.0.3     2022-10-07 [1] CRAN (R 3.6.3)
 magrittr      2.0.1     2020-11-17 [1] CRAN (R 3.6.3)
 MASS          7.3-51.5  2019-12-20 [2] CRAN (R 3.6.3)
 Matrix        1.3-3     2021-05-04 [1] CRAN (R 3.6.3)
 memoise       1.1.0     2017-04-21 [1] CRAN (R 3.6.1)
 mgcv          1.8-31    2019-11-09 [2] CRAN (R 3.6.3)
 mirt          1.41      2023-10-17 [1] CRAN (R 3.6.3)
 mnormt        1.5-5     2016-10-15 [1] CRAN (R 3.6.0)
 nlme          3.1-144   2020-02-06 [2] CRAN (R 3.6.3)
 pbapply       1.5-0     2021-09-16 [1] CRAN (R 3.6.2)
 pbivnorm      0.6.0     2015-01-23 [1] CRAN (R 3.6.0)
 permute       0.9-5     2019-03-12 [1] CRAN (R 3.6.1)
 pillar        1.8.1     2022-08-19 [1] CRAN (R 3.6.3)
 pkgbuild      1.4.3     2023-12-10 [1] CRAN (R 3.6.3)
 pkgconfig     2.0.2     2018-08-16 [1] CRAN (R 3.6.0)
 pkgload       1.0.2     2018-10-29 [1] CRAN (R 3.6.1)
 processx      3.7.0     2022-07-07 [1] CRAN (R 3.6.3)
 ps            1.6.0     2021-02-28 [1] CRAN (R 3.6.3)
 purrr         0.3.3     2019-10-18 [1] CRAN (R 3.6.1)
 quadprog      1.5-8     2019-11-20 [1] CRAN (R 3.6.1)
 r2glmm        0.1.2     2017-08-05 [1] CRAN (R 3.6.3)
 R6            2.5.1     2021-08-19 [1] CRAN (R 3.6.2)
 Rcpp          1.0.6     2021-01-15 [1] CRAN (R 3.6.3)
 remotes       2.1.0     2019-06-24 [1] CRAN (R 3.6.1)
 rlang         1.0.6     2022-09-24 [1] CRAN (R 3.6.3)
 rprojroot     1.3-2     2018-01-03 [1] CRAN (R 3.6.0)
 rstudioapi    0.14      2022-08-22 [1] CRAN (R 3.6.3)
 sessioninfo   1.1.1     2018-11-05 [1] CRAN (R 3.6.1)
 testthat      3.1.4     2022-04-26 [1] CRAN (R 3.6.3)
 tibble        3.0.4     2020-10-12 [1] CRAN (R 3.6.3)
 tidyselect    1.2.0     2022-10-10 [1] CRAN (R 3.6.3)
 usethis     * 2.1.6     2022-05-25 [1] CRAN (R 3.6.3)
 utf8          1.1.4     2018-05-24 [1] CRAN (R 3.6.0)
 vctrs         0.5.2     2023-01-23 [1] CRAN (R 3.6.3)
 vegan         2.5-6     2019-09-01 [1] CRAN (R 3.6.1)
 withr         2.2.0     2020-04-20 [1] CRAN (R 3.6.3)

[1] C:/Users/Marco/OneDrive/Documents/R/win-library/3.6
[2] C:/Program Files/R/R-3.6.3/library

Just to check before we start with the debugging, are you able to upgrade to a newer R version? R3.6 is no longer officially supported by R, and makes a lot of other things a bit more difficult

Thanks for the suggestion. I just updated to R 4.2.1 along with Rtools 42. I removed my Makevars and have > Sys.getenv("BINPREF") [1] "". Now the package installed but I get a compilation error when trying out the suggested example(stan_model,...) compilation

Compilation ERROR, function(s)/method(s) not created!
Error in compileCode(f, code, language = language, verbose = verbose) : 
  C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: file5c2818ef1b60.o:file5c2818ef1b60.cpp:(.text$_ZN3tbb8internal26task_scheduler_observer_v3D0Ev[_ZN3tbb8internal26task_scheduler_observer_v3D0Ev]+0x1d): undefined reference to `tbb::internal::task_scheduler_observer_v3::observe(bool)'C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: file5c2818ef1b60.o:file5c2818ef1b60.cpp:(.text$_ZN3tbb10interface623task_scheduler_observerD1Ev[_ZN3tbb10interface623task_scheduler_observerD1Ev]+0x1d): undefined reference to `tbb::internal::task_scheduler_observer_v3::observe(bool)'C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: file5c2818ef1b60.o:file5c2818ef1b60.cpp:(.text$_ZN3tbb10interface623task_scheduler_observerD1Ev[_ZN3tbb10interface623task_scheduler_observerD1Ev]+0x3a): undefined reference to `tbb::internal::task_scheduler_observer_v3::observe(bool)'C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: file5c2818ef1b60.o:file5c2818ef1b60.cpp:(.text$_ZN3tbb10interface

Here is my configuration. I specifically did these versions of R, rstan, and StanHeaders because these were pre-installed on our remote Linux computing cluster and have worked well so far, so I am hoping to match that environment. Thanks for any other suggestions!

> sessionInfo()
R version 4.2.1 (2022-06-23 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19045)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.utf8  LC_CTYPE=English_United States.utf8    LC_MONETARY=English_United States.utf8
[4] LC_NUMERIC=C                           LC_TIME=English_United States.utf8    

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

other attached packages:
[1] dplyr_1.1.4          tidyr_1.3.0          data.table_1.14.10   rstan_2.21.8         ggplot2_3.4.4        StanHeaders_2.21.0-7

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.12        pillar_1.9.0       compiler_4.2.1     tools_4.2.1        pkgbuild_1.4.3     lifecycle_1.0.4    tibble_3.2.1      
 [8] gtable_0.3.4       pkgconfig_2.0.3    rlang_1.1.3        cli_3.6.2          rstudioapi_0.15.0  parallel_4.2.1     loo_2.6.0         
[15] gridExtra_2.3      withr_3.0.0        generics_0.1.3     vctrs_0.6.5        stats4_4.2.1       grid_4.2.1         tidyselect_1.2.0  
[22] glue_1.7.0         inline_0.3.19      R6_2.5.1           fansi_1.0.6        r2glmm_0.1.2       purrr_1.0.2        magrittr_2.0.3    
[29] scales_1.3.0       codetools_0.2-19   matrixStats_1.2.0  colorspace_2.1-0   utf8_1.2.4         RcppParallel_5.1.7 munsell_0.5.0   

You’ll need to update your rstan and StanHeaders versions, since that linking issue has already been resolved

Installing the latest rstan into R 4.2 from CRAN indeed worked. That was a simple solution.

The github page on configuring toolchains (Configuring C Toolchain for Windows · stan-dev/rstan Wiki · GitHub) left me the impression that I could stick with R 3.6 and update rstan to a newer version, but now I know that is not the case.

Just to follow up, does the github release page Releases · stan-dev/stan · GitHub provide the most details regarding changes from rstan 2.21 to 2.35? My previous models still compiled on 2.32.5, but I wonder what the likelihood is to see changes in speed and/or results when fitting the model in this version. Edit: just saw that the reference manual listed some removed functions.

I must have not followed the package development for a while, but thanks again I literally have the Stan development team in my dissertation acknowledgement :)