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

**URL:** <https://discourse.mc-stan.org/t/error-in-compilecode-f-code-language-language-verbose-verbose-error-in-sink-type-output-invalid-connection/20255>\
**Category:** Modeling\
**Tags:** rstan\
**Created:** [January 15, 2021, 2:03pm UTC](https://discourse.mc-stan.org/t/error-in-compilecode-f-code-language-language-verbose-verbose-error-in-sink-type-output-invalid-connection/20255 "2021-01-15T14:03:58Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Emily](https://avatars.discourse-cdn.com/v4/letter/e/8c91f0/32.png) [@Emily](https://discourse.mc-stan.org/u/Emily)\
**Post date:** [January 15, 2021, 2:03pm UTC](https://discourse.mc-stan.org/t/error-in-compilecode-f-code-language-language-verbose-verbose-error-in-sink-type-output-invalid-connection/20255/1 "2021-01-15T14:03:58Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Emily](https://avatars.discourse-cdn.com/v4/letter/e/8c91f0/32.png) [@Emily](https://discourse.mc-stan.org/u/Emily)\
**Post date:** [January 20, 2021, 10:44am UTC](https://discourse.mc-stan.org/t/error-in-compilecode-f-code-language-language-verbose-verbose-error-in-sink-type-output-invalid-connection/20255/2 "2021-01-20T10:44:10Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![andrjohns](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/andrjohns/32/15297_2.png) [@andrjohns](https://discourse.mc-stan.org/u/andrjohns)\
**Post date:** [January 20, 2021, 3:36pm UTC](https://discourse.mc-stan.org/t/error-in-compilecode-f-code-language-language-verbose-verbose-error-in-sink-type-output-invalid-connection/20255/3 "2021-01-20T15:36:51Z")

</div>

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")

```

---

<div class="post-metadata">

**Author:** ![Emily](https://avatars.discourse-cdn.com/v4/letter/e/8c91f0/32.png) [@Emily](https://discourse.mc-stan.org/u/Emily)\
**Post date:** [February 1, 2021, 11:47am UTC](https://discourse.mc-stan.org/t/error-in-compilecode-f-code-language-language-verbose-verbose-error-in-sink-type-output-invalid-connection/20255/4 "2021-02-01T11:47:34Z")

</div>

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