Error in compileCode(f, code, language = language, verbose = verbose) & Error in sink(type = "output") : invalid connection

Hi there!
I am new to using stan and I am getting the same error code others are getting with the rstan package. I have tried the solutions from previous posts but these haven’t worked.
I am using R.4.0.3 on Windows

sessionInfo()
R version 4.0.3 (2020-10-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 18362)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 LC_MONETARY=English_United States.1252 LC_NUMERIC=C
[5] LC_TIME=English_United States.1252
system code page: 65001

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

other attached packages:
[1] cowplot_1.1.1 dplyr_1.0.1 gdata_2.18.0 rstan_2.21.2 StanHeaders_2.21.0-7 ggplot2_3.3.2 lubridate_1.7.9
[8] brms_2.14.4 Rcpp_1.0.5

loaded via a namespace (and not attached):
[1] minqa_1.2.4 colorspace_1.4-1 ellipsis_0.3.1 ggridges_0.5.3 rsconnect_0.8.16 rprojroot_2.0.2 markdown_1.1
[8] base64enc_0.1-3 fs_1.5.0 rstudioapi_0.11 farver_2.0.3 remotes_2.2.0 DT_0.17 fansi_0.4.1
[15] mvtnorm_1.1-1 bridgesampling_1.0-0 codetools_0.2-16 splines_4.0.3 shinythemes_1.1.2 pkgload_1.1.0 bayesplot_1.8.0
[22] projpred_2.0.2 jsonlite_1.7.2 nloptr_1.2.2.2 shiny_1.5.0 compiler_4.0.3 backports_1.1.7 assertthat_0.2.1
[29] Matrix_1.2-18 fastmap_1.0.1 cli_2.0.2 later_1.1.0.1 htmltools_0.5.0 prettyunits_1.1.1 tools_4.0.3
[36] igraph_1.2.6 coda_0.19-4 gtable_0.3.0 glue_1.4.2 reshape2_1.4.4 V8_3.4.0 vctrs_0.3.2
[43] nlme_3.1-149 crosstalk_1.1.0.1 stringr_1.4.0 ps_1.5.0 testthat_2.3.2 lme4_1.1-26 mime_0.9
[50] miniUI_0.1.1.1 lifecycle_0.2.0 gtools_3.8.2 devtools_2.3.2 statmod_1.4.35 MASS_7.3-53 zoo_1.8-8
[57] scales_1.1.1 colourpicker_1.1.0 promises_1.1.1 Brobdingnag_1.2-6 inline_0.3.17 shinystan_2.5.0 gamm4_0.2-6
[64] curl_4.3 memoise_1.1.0 gridExtra_2.3 loo_2.4.1 stringi_1.5.3 dygraphs_1.1.1.6 desc_1.2.0
[71] boot_1.3-25 pkgbuild_1.2.0 rlang_0.4.7 pkgconfig_2.0.3 matrixStats_0.56.0 lattice_0.20-41 purrr_0.3.4
[78] labeling_0.3 rstantools_2.1.1 htmlwidgets_1.5.2 processx_3.4.5 tidyselect_1.1.0 plyr_1.8.6 magrittr_2.0.1
[85] R6_2.4.1 generics_0.1.0 pillar_1.4.6 withr_2.2.0 mgcv_1.8-33 xts_0.12.1 abind_1.4-5
[92] tibble_3.0.3 crayon_1.3.4 usethis_2.0.0 grid_4.0.3 callr_3.5.1 threejs_0.3.3 digest_0.6.25
[99] xtable_1.8-4 httpuv_1.5.4 RcppParallel_5.0.2 stats4_4.0.3 munsell_0.5.0 sessioninfo_1.1.1 shinyjs_2.0.0

I have the rtools40 version

When I run the model:

model1=brm(drift~cumm_step,data=drift_data2,iter=2000,inits = 0,
control=list(adapt_delta=0.9999999999999999, max_treedepth = 11))

I get this error:

Error in compileCode(f, code, language = language, verbose = verbose) :
C:/rtools40/mingw64/bin/…/lib/gcc/x86_64-w64-mingw32/8.3.0/…/…/…/…/x86_64-w64-mingw32/bin/ld.exe: C:/Users/egrout/Documents/R/win-library/4.0/rstan/lib/x64/libStanServices.a(stan_fit.o):stan_fit.cpp:(.rdata$_ZZN5boost4math6detail9bessel_j0IeEET_S3_E2P1[ZZN5boost4math6detail9bessel_j0IeEET_S3_E2P1]+0x0): multiple definition of boost::math::detail::bessel_j0<long double>(long double)::P1'; file14881f482858.o:file14881f482858.cpp:(.data$_ZZN5boost4math6detail9bessel_j0IeEET_S3_E2P1[_ZZN5boost4math6detail9bessel_j0IeEET_S3_E2P1]+0x0): first defined hereC:/rtools40/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Users/egrout/Documents/R/win-library/4.0/rstan/lib/x64/libStanServices.a(stan_fit.o):stan_fit.cpp:(.rdata$_ZZN5boost4math6detail9bessel_j0IeEET_S3_E2QC[_ZZN5boost4math6detail9bessel_j0IeEET_S3_E2QC]+0x0): multiple definition of boost::math::detail::bessel_j0(long double)::QC’; file14881f482858.o:file14881f4
In addition: Warning message:
In system(paste(CXX, ARGS), ignore.stdout = TRUE, ignore.stderr = TRUE) :
'C:/rtools40/usr/mingw
/bin/g++’ not found
Error in sink(type = “output”) : invalid connection

If anyone knows how to solve this error, I would be super grateful.

Thanks in advance!
-Emily

Hi there, can anyone help with this issue? Thanks in advance :)

Hi Emily, sorry we missed this! To fix this you need to reinstall RStan and StanHeaders from source:

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

Thank you so much! It’s working now :)

1 Like