Rstan fit Error in compileCode(f, code, language = language, verbose = verbose)

Yes, this is what I followed. I tried it several times after uninstall but no success. (I’m using R 4.2.1 but no RStudio.) Is there anything else I could try please?

What’s the output from packageVersion("rstan")?

2.21.7

That link I posted says that the CRAN version is not compatible and you need to install the preview version (2.26). Can you try following the installation steps in the link?

Thank you very much for helping out. I think the reason for confusion was that, after installing the preview version (which is what actually happens under the title " Configuring C++ Toolchain"), I followed the next step given on both guide pages (β€œInstalling RStan”). So I must have over-written version 2.26.13 with the older version. I did not realize that I should not follow this last step - the pages were not clear on that. Anyhow, many thanks again for taking the time for answering all these noob questions! <3

That is what solved for me! Thank you!

I have this problem: Error in compileCode(f, code, language = language, verbose = verbose) :
C:\rtools42_1\x86_64-w64-mingw32.static.posix\bin/ld.exe: file9690354c5486.o:file9690354c5486.cpp:(.text$_ZN3tbb8internal26task_scheduler_observer_v3D0Ev[_ZN3tbb8internal26task_scheduler_observer_v3D0Ev]+0x1d): undefined reference to tbb::internal::task_scheduler_observer_v3::observe(bool)'C:\rtools42_1\x86_64-w64-mingw32.static.posix\bin/ld.exe: file9690354c5486.o:file9690354c5486.cpp:(.text$_ZN3tbb10interface623task_scheduler_observerD1Ev[_ZN3tbb10interface623task_scheduler_observerD1Ev]+0x1d): undefined reference to tbb::internal::task_scheduler_observer_v3::observe(bool)'C:\rtools42_1\x86_64-w64-mingw32.static.posix\bin/ld.exe: file9690354c5486.o:file9690354c5486.cpp:(.text$_ZN3tbb10interface623task_scheduler_observerD1Ev[_ZN3tbb10interface623task_scheduler_observerD1Ev]+0x3a): undefined reference to `tbb::internal::task_scheduler_observer_v3::observe(bool)'C:\rtools42_1\x86_64-w64-mingw32.static.posix\bin/ld.exe: file9690354c5486.o:file9690354c5486.cpp:(.text$_ZN3tbb10i
Error in sink(type = β€œoutput”) : invalid connection

I already tried: install.packages(c(β€œStanHeaders”,β€œrstan”),type=β€œsource”), but I still get the same error.

Any help is much appreciated!

1 Like

I tried to reinstall R, Rstudio, Rtools, but it still didn’t work. Thank you for your help Error in compileCode (f, code, language = language … My rstan get wrong suddenly, and I have try to update R, love language test Rstudio, … Error in compileCode I’m super confused what this error is about, I’m following this Error in compileCode ( f , *code , language = language , verbose = verbose ) : Compilation ERROR , function(s)/method(s) not created!

I have had similar issue, and after going through every solution mentioned above, i still cannot figure it out. I was using the example2 given in ?rstan and the error says:

Error in compileCode(f, code, language = language, verbose = verbose) : 
                            ^file34c673744a1d.cpp:641:60: note: in instantiation of member function 'rstan::stan_fit<model34c6703b88bf__namespace::model34c6703b88bf_, boost::random::additive_combine_engine<boost::random::linear_congruential_engine<unsigned int, 40014, 0, 2147483563>, boost::random::linear_congruential_engine<unsigned int, 40692, 0, 2147483399>>>::standalone_gqs' requested here                               boost::random::ecuyer1988>::standalone_gqs);                                                           ^106 warnings and 1 error generated.make: *** [file34c673744a1d.o] Error 1
Error in sink(type = "output") : invalid connection

Given by the aforementioned solutions, I tried

remove.packages(c(β€œStanHeaders”, β€œrstan”))
install.packages(β€œrstan”, repos = c(β€œRepository for distributing (some) stan-dev R packages | r-packages”, getOption(β€œrepos”)))

and there is still the error.

So I tried running this command if (!requireNamespace("devtools")) { install.packages("devtools") } devtools::session_info("rstan")
and the result says:

devtools::session_info(β€œrstan”)
─ Session info ───────────────────────────────────────────────────────────────────────────────────────────
setting value
version R version 4.2.3 (2023-03-15)
os macOS 14.0
system x86_64, darwin17.0
ui RStudio
language (EN)
collate en_US.UTF-8
ctype en_US.UTF-8
tz Asia/Shanghai
date 2023-10-25
rstudio 2023.03.0+386 Cherry Blossom (desktop)
pandoc 2.19.2 @ /Applications/RStudio.app/Contents/Resources/app/quarto/bin/tools/ (via rmarkdown)
─ Packages ───────────────────────────────────────────────────────────────────────────────────────────────
package * version date (UTC) lib source
backports 1.4.1 2021-12-13 [1] CRAN (R 4.2.0)
BH 1.78.0-0 2021-12-15 [1] CRAN (R 4.2.0)
callr 3.7.3 2022-11-02 [1] CRAN (R 4.2.1)
checkmate 2.1.0 2022-04-21 [1] CRAN (R 4.2.0)
cli 3.6.1 2023-03-23 [1] CRAN (R 4.2.0)
colorspace 2.0-3 2022-02-21 [1] CRAN (R 4.2.0)
crayon 1.5.2 2022-09-29 [1] CRAN (R 4.2.0)
desc 1.4.2 2022-09-08 [1] CRAN (R 4.2.0)
fansi 1.0.4 2023-01-22 [1] CRAN (R 4.2.0)
farver 2.1.1 2022-07-06 [1] CRAN (R 4.2.0)
ggplot2 3.4.2 2023-04-03 [1] CRAN (R 4.2.0)
glue 1.6.2 2022-02-24 [1] CRAN (R 4.2.0)
gridExtra 2.3 2017-09-09 [1] CRAN (R 4.2.0)
gtable 0.3.1 2022-09-01 [1] CRAN (R 4.2.0)
inline 0.3.19 2021-05-31 [1] CRAN (R 4.2.0)
isoband 0.2.7 2022-12-20 [1] CRAN (R 4.2.0)
jsonlite 1.8.4 2022-12-06 [1] CRAN (R 4.2.0)
labeling 0.4.2 2020-10-20 [1] CRAN (R 4.2.0)
lattice 0.20-45 2021-09-22 [1] CRAN (R 4.2.3)
lifecycle 1.0.3 2022-10-07 [1] CRAN (R 4.2.0)
loo 2.5.1 2022-03-24 [1] CRAN (R 4.2.0)
magrittr 2.0.3 2022-03-30 [1] CRAN (R 4.2.0)
MASS 7.3-58.2 2023-01-23 [1] CRAN (R 4.2.3)
Matrix 1.5-3 2022-11-11 [1] CRAN (R 4.2.3)
matrixStats 0.63.0 2022-11-18 [1] CRAN (R 4.2.0)
mgcv 1.8-42 2023-03-02 [1] CRAN (R 4.2.3)
munsell 0.5.0 2018-06-12 [1] CRAN (R 4.2.0)
nlme 3.1-162 2023-01-31 [1] CRAN (R 4.2.3)
pillar 1.9.0 2023-03-22 [1] CRAN (R 4.2.0)
pkgbuild 1.4.0 2022-11-27 [1] CRAN (R 4.2.0)
pkgconfig 2.0.3 2019-09-22 [1] CRAN (R 4.2.0)
prettyunits 1.1.1 2020-01-24 [1] CRAN (R 4.2.0)
processx 3.8.0 2022-10-26 [1] CRAN (R 4.2.0)
ps 1.7.2 2022-10-26 [1] CRAN (R 4.2.0)
QuickJSR 1.0.7 2023-10-15 [1] CRAN (R 4.2.0)
R6 2.5.1 2021-08-19 [1] CRAN (R 4.2.0)
RColorBrewer 1.1-3 2022-04-03 [1] CRAN (R 4.2.0)
Rcpp 1.0.10 2023-01-22 [1] CRAN (R 4.2.0)
RcppEigen 0.3.3.9.3 2022-11-05 [1] CRAN (R 4.2.0)
RcppParallel 5.1.5 2022-01-05 [1] CRAN (R 4.2.0)
rlang 1.1.0 2023-03-14 [1] CRAN (R 4.2.1)
rprojroot 2.0.3 2022-04-02 [1] CRAN (R 4.2.0)
rstan * 2.32.3 2023-10-15 [1] CRAN (R 4.2.0)
scales 1.2.1 2022-08-20 [1] CRAN (R 4.2.0)
StanHeaders * 2.26.28 2023-09-07 [1] CRAN (R 4.2.3)
tibble 3.2.1 2023-03-20 [1] CRAN (R 4.2.0)
utf8 1.2.3 2023-01-31 [1] CRAN (R 4.2.0)
vctrs 0.6.1 2023-03-22 [1] CRAN (R 4.2.0)
viridisLite 0.4.1 2022-08-22 [1] CRAN (R 4.2.0)
withr 2.5.0 2022-03-03 [1] CRAN (R 4.2.0)
[1] /Library/Frameworks/R.framework/Versions/4.2/Resources/library

Therefore I assume that there is no version issue. So I am confused. To be mentioned, the Python environment I apply in R collapsed everytime I open the program, so I do not know whether it has something to do with this.
Thank you so much!!