Error running RStan in RStudio (as of today!)

Have been happily running RStan via the Richard McElreath Rethinking package, but today it started giving me 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/Ben 10/Documents/R/win-library/4.0/rstan/lib/x64/libStanServices.a(stan_fit.o):stan_fit.cpp:(.data$_ZZN5boost4math6detail9bessel_j0IeEET_S3_E2P1[_ZZN5boost4math6detail9bessel_j0IeEET_S3_E2P1]+0x0): multiple definition of boost::math::detail::bessel_j0<long double>(long double)::P1'; file23583f457e5e.o:file23583f457e5e.cpp:(.rdata$_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/Ben 10/Documents/R/win-library/4.0/rstan/lib/x64/libStanServices.a(stan_fit.o):stan_fit.cpp:(.data$_ZZN5boost4math6detail9bessel_j0IeEET_S3_E2QS[_ZZN5boost4math6detail9bessel_j0IeEET_S3_E2QS]+0x0): multiple definition of boost::math::detail::bessel_j0(long double)::QS’; file23583f457e5e.o:file23583f45
Error in sink(type = “output”) : invalid connection

From this code line (which has run fine before)

m1 <- ulam(flist, data = dat, chains = 4, cores = 2, iter = 10000, file = "m1")

All my packages are up to date.

Info:

Sys.getenv(“PATH”)
[1] “C:\rtools40\usr\bin;C:\Program Files\R\R-4.0.2\bin\x64;C:\Program Files (x86)\Common Files\Oracle\Java\javapath_target_1598185937;C:\ProgramData\Oracle\Java\javapath;C:\Program Files\Common Files\microsoft shared\Windows Live;C:\Program Files (x86)\Common Files\Microsoft Shared\Windows Live;C:\Windows\System32;C:\Windows;C:\Windows\System32\wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Program Files (x86)\Intel\OpenCL SDK\2.0\bin\x86;C:\Program Files (x86)\Intel\OpenCL SDK\2.0\bin\x64;C:\Program Files (x86)\Windows Live\Shared;C:\Windows\System32\OpenSSH;C:\Program Files\Git\cmd;C:\Program Files\MATLAB\R2020b\bin;C:\Users\Ben 10\AppData\Local\Microsoft\WindowsApps;C:\Program Files (x86)\EaseUS\Todo Backup\bin\x64"”

Sys.getenv(“BINPREF”)
[1] “”
readLines(“~/.R/Makevars.win”)
cannot open file ‘C:/Users/Ben 10/Documents/.R/Makevars.win’: No such file or directoryError in file(con, “r”) : cannot open the connection
readLines(“~/.Rprofile”)
cannot open file ‘C:/Users/Ben 10/Documents/.Rprofile’: No such file or directoryError in file(con, “r”) : cannot open the connection
readLines(“~/.Renviron”)
[1] “PATH="{RTOOLS40_HOME}\\usr\\bin;{PATH}"”
devtools::session_info(“rstan”)

  • Session info -----------------------------------------------------------------------------------------------

  • Packages ---------------------------------------------------------------------------------------------------
    package * version date lib source
    assertthat 0.2.1 2019-03-21 [1] CRAN (R 4.0.0)
    backports 1.2.1 2020-12-09 [1] CRAN (R 4.0.3)
    BH 1.75.0-0 2021-01-11 [1] CRAN (R 4.0.3)
    callr 3.6.0 2021-03-28 [1] CRAN (R 4.0.2)
    checkmate 2.0.0 2020-02-06 [1] CRAN (R 4.0.2)
    cli 2.3.1 2021-02-23 [1] CRAN (R 4.0.4)
    colorspace 2.0-0 2020-11-11 [1] CRAN (R 4.0.4)
    crayon 1.4.1 2021-02-08 [1] CRAN (R 4.0.4)
    curl 4.3 2019-12-02 [1] CRAN (R 4.0.0)
    desc 1.3.0 2021-03-05 [1] CRAN (R 4.0.4)
    digest 0.6.27 2020-10-24 [1] CRAN (R 4.0.3)
    ellipsis 0.3.1 2020-05-15 [1] CRAN (R 4.0.2)
    fansi 0.4.2 2021-01-15 [1] CRAN (R 4.0.4)
    farver 2.1.0 2021-02-28 [1] CRAN (R 4.0.4)
    ggplot2 * 3.3.3 2020-12-30 [1] CRAN (R 4.0.4)
    glue 1.4.2 2020-08-27 [1] CRAN (R 4.0.3)
    gridExtra 2.3 2017-09-09 [1] CRAN (R 4.0.0)
    gtable 0.3.0 2019-03-25 [1] CRAN (R 4.0.0)
    inline 0.3.17 2020-12-01 [1] CRAN (R 4.0.4)
    isoband 0.2.4 2021-03-03 [1] CRAN (R 4.0.4)
    jsonlite 1.7.2 2020-12-09 [1] CRAN (R 4.0.4)
    labeling 0.4.2 2020-10-20 [1] CRAN (R 4.0.3)
    lattice 0.20-41 2020-04-02 [2] CRAN (R 4.0.2)
    lifecycle 1.0.0 2021-02-15 [1] CRAN (R 4.0.4)
    loo 2.4.1 2020-12-09 [1] CRAN (R 4.0.4)
    magrittr 2.0.1 2020-11-17 [1] CRAN (R 4.0.4)
    MASS 7.3-53.1 2021-02-12 [1] CRAN (R 4.0.4)
    Matrix * 1.2-18 2019-11-27 [2] CRAN (R 4.0.2)
    matrixStats 0.58.0 2021-01-29 [1] CRAN (R 4.0.4)
    mgcv 1.8-31 2019-11-09 [2] CRAN (R 4.0.2)
    munsell 0.5.0 2018-06-12 [1] CRAN (R 4.0.0)
    nlme 3.1-148 2020-05-24 [2] CRAN (R 4.0.2)
    pillar 1.5.1 2021-03-05 [1] CRAN (R 4.0.4)
    pkgbuild 1.2.0 2020-12-15 [1] CRAN (R 4.0.4)
    pkgconfig 2.0.3 2019-09-22 [1] CRAN (R 4.0.0)
    prettyunits 1.1.1 2020-01-24 [1] CRAN (R 4.0.0)
    processx 3.5.0 2021-03-23 [1] CRAN (R 4.0.2)
    ps 1.6.0 2021-02-28 [1] CRAN (R 4.0.4)
    R6 2.5.0 2020-10-28 [1] CRAN (R 4.0.4)
    RColorBrewer 1.1-2 2014-12-07 [1] CRAN (R 4.0.0)
    Rcpp 1.0.6 2021-01-15 [1] CRAN (R 4.0.4)
    RcppEigen 0.3.3.9.1 2020-12-17 [1] CRAN (R 4.0.4)
    RcppParallel 5.0.3 2021-02-24 [1] CRAN (R 4.0.2)
    rlang 0.4.10 2020-12-30 [1] CRAN (R 4.0.4)
    rprojroot 2.0.2 2020-11-15 [1] CRAN (R 4.0.4)
    rstan * 2.21.2 2020-07-27 [1] CRAN (R 4.0.2)
    scales 1.1.1 2020-05-11 [1] CRAN (R 4.0.2)
    StanHeaders * 2.21.0-7 2020-12-17 [1] CRAN (R 4.0.4)
    tibble * 3.1.0 2021-02-25 [1] CRAN (R 4.0.4)
    utf8 1.2.1 2021-03-12 [1] CRAN (R 4.0.4)
    V8 3.4.0 2020-11-04 [1] CRAN (R 4.0.4)
    vctrs 0.3.7 2021-03-29 [1] CRAN (R 4.0.2)
    viridisLite 0.3.0 2018-02-01 [1] CRAN (R 4.0.0)
    withr 2.4.1 2021-01-26 [1] CRAN (R 4.0.4)

[1] C:/Users/Ben 10/Documents/R/win-library/4.0
[2] C:/Program Files/R/R-4.0.2/library

Had the same problem on my LINUX machine too, but on Windows I solved it just by reinstalling Stan version 2.21.2

1 Like

Hi, sorry for not getting to you earlier. I am now a bit confused - did you manage to resolve the problem by yourself or are you still having trouble?

1 Like

On linux, when you see a error having to do with libStanServices.a, just reinstall three packages:

install.packages("V8")
install.packages("StanHeaders")
install.packages("rstan")

In that order, and not all at once (as in, don’t do install.packages(c(“V8”,“StanHeaders”,“rstan”)))

1 Like

@martinmodrak thanks for your reply - reinstalling Stan worked thank you

@Stephen_Martin presumably that will be quicker than reinstalling the whole thing? Great - I will try that.

Paul.