Rstan model fails to compile - machine specific

Hi,

I’ve recently done a clean install of Rstan on my desktop.

I’m using R4.2 so I installed with:

install.packages("StanHeaders", repos = c("https://mc-stan.org/r-packages/", getOption("repos")))
install.packages("rstan", repos = c("https://mc-stan.org/r-packages/", getOption("repos")))

A model I’ve written runs fine on my work machine, however when I try and run it on my desktop (without changing anything) I get the following error:

Error in stanc(file = file, model_code = model_code, model_name = model_name,  : 
  parser failed badly

Weirdly, the test model runs fine, and I’ve also tried previous models I’ve written and they also run without issue.

  • Operating System
Sys.info()
        sysname         release         version        nodename         machine 
      "Windows"        "10 x64"   "build 19044" "FW-FIRSTBUILT"        "x86-64" 
          login            user  effective_user 
      "Freddie"       "Freddie"       "Freddie" 
  • RStan Version
R.Version()
$platform
[1] "x86_64-w64-mingw32"

$arch
[1] "x86_64"

$os
[1] "mingw32"

$crt
[1] "ucrt"

$system
[1] "x86_64, mingw32"

$status
[1] ""

$major
[1] "4"

$minor
[1] "2.1"

$year
[1] "2022"

$month
[1] "06"

$day
[1] "23"

$`svn rev`
[1] "82513"

$language
[1] "R"

$version.string
[1] "R version 4.2.1 (2022-06-23 ucrt)"

$nickname
[1] "Funny-Looking Kid"
  • Output of writeLines(readLines(file.path(Sys.getenv("HOME"), ".R/Makevars")))
Error in file(con, "r") : cannot open the connection
In addition: Warning message:
In file(con, "r") :
  cannot open file 'C:/Users/Freddie/Documents/.R/Makevars': No such file or directory
  • Output of devtools::session_info("rstan")
─ Session info ───────────────────────────────────────────────────────────────
 setting  value
 version  R version 4.2.1 (2022-06-23 ucrt)
 os       Windows 10 x64 (build 19044)
 system   x86_64, mingw32
 ui       RStudio
 language (EN)
 collate  English_United Kingdom.utf8
 ctype    English_United Kingdom.utf8
 tz       Europe/London
 date     2022-07-27
 rstudio  2022.07.0+548 Spotted Wakerobin (desktop)
 pandoc   NA

─ 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.1     2022-07-13 [1] CRAN (R 4.2.1)
 checkmate      2.1.0     2022-04-21 [1] CRAN (R 4.2.1)
 cli            3.3.0     2022-04-25 [1] CRAN (R 4.2.1)
 colorspace     2.0-3     2022-02-21 [1] CRAN (R 4.2.1)
 crayon         1.5.1     2022-03-26 [1] CRAN (R 4.2.1)
 curl           4.3.2     2021-06-23 [1] CRAN (R 4.2.1)
 desc           1.4.1     2022-03-06 [1] CRAN (R 4.2.1)
 digest         0.6.29    2021-12-01 [1] CRAN (R 4.2.1)
 ellipsis       0.3.2     2021-04-29 [1] CRAN (R 4.2.1)
 fansi          1.0.3     2022-03-24 [1] CRAN (R 4.2.1)
 farver         2.1.1     2022-07-06 [1] CRAN (R 4.2.1)
 ggplot2      * 3.3.6     2022-05-03 [1] CRAN (R 4.2.1)
 glue           1.6.2     2022-02-24 [1] CRAN (R 4.2.1)
 gridExtra      2.3       2017-09-09 [1] CRAN (R 4.2.1)
 gtable         0.3.0     2019-03-25 [1] CRAN (R 4.2.1)
 inline         0.3.19    2021-05-31 [1] CRAN (R 4.2.1)
 isoband        0.2.5     2021-07-13 [1] CRAN (R 4.2.1)
 jsonlite       1.8.0     2022-02-22 [1] CRAN (R 4.2.1)
 labeling       0.4.2     2020-10-20 [1] CRAN (R 4.2.0)
 lattice      * 0.20-45   2021-09-22 [2] CRAN (R 4.2.1)
 lifecycle      1.0.1     2021-09-24 [1] CRAN (R 4.2.1)
 loo            2.5.1     2022-03-24 [1] CRAN (R 4.2.1)
 magrittr     * 2.0.3     2022-03-30 [1] CRAN (R 4.2.1)
 MASS           7.3-57    2022-04-22 [2] CRAN (R 4.2.1)
 Matrix         1.4-1     2022-03-23 [2] CRAN (R 4.2.1)
 matrixStats    0.62.0    2022-04-19 [1] CRAN (R 4.2.1)
 mgcv           1.8-40    2022-03-29 [2] CRAN (R 4.2.1)
 munsell        0.5.0     2018-06-12 [1] CRAN (R 4.2.1)
 nlme           3.1-157   2022-03-25 [2] CRAN (R 4.2.1)
 pillar         1.7.0     2022-02-01 [1] CRAN (R 4.2.1)
 pkgbuild       1.3.1     2021-12-20 [1] CRAN (R 4.2.1)
 pkgconfig      2.0.3     2019-09-22 [1] CRAN (R 4.2.1)
 prettyunits    1.1.1     2020-01-24 [1] CRAN (R 4.2.1)
 processx       3.7.0     2022-07-07 [1] CRAN (R 4.2.1)
 ps             1.7.1     2022-06-18 [1] CRAN (R 4.2.1)
 R6             2.5.1     2021-08-19 [1] CRAN (R 4.2.1)
 RColorBrewer * 1.1-3     2022-04-03 [1] CRAN (R 4.2.0)
 Rcpp           1.0.9     2022-07-08 [1] CRAN (R 4.2.1)
 RcppEigen      0.3.3.9.2 2022-04-08 [1] CRAN (R 4.2.1)
 RcppParallel   5.1.5     2022-01-05 [1] CRAN (R 4.2.1)
 rlang          1.0.3     2022-06-27 [1] CRAN (R 4.2.1)
 rprojroot      2.0.3     2022-04-02 [1] CRAN (R 4.2.1)
 rstan        * 2.26.13   2022-06-25 [1] local
 scales       * 1.2.0     2022-04-13 [1] CRAN (R 4.2.1)
 StanHeaders  * 2.26.13   2022-06-25 [1] local
 tibble         3.1.7     2022-05-03 [1] CRAN (R 4.2.1)
 utf8           1.2.2     2021-07-24 [1] CRAN (R 4.2.1)
 V8             4.2.0     2022-05-14 [1] CRAN (R 4.2.1)
 vctrs          0.4.1     2022-04-13 [1] CRAN (R 4.2.1)
 viridisLite    0.4.0     2021-04-13 [1] CRAN (R 4.2.1)
 withr          2.5.0     2022-03-03 [1] CRAN (R 4.2.1)

 [1] C:/Users/Freddie/AppData/Local/R/win-library/4.2
 [2] C:/Program Files/R/R-4.2.1/library

(side note, the first time I ran devtools I noted RcppParallel was flagged with DLL MD5 mismatch, broken installation.
After re-installing RcppParallel from source, this flag dissapeared however the original problem persists.)

Thanks for any help!

I found this thread - I had noted sample numbers in my comments with a hash. E.g. '// Sample #1' - I removed the hashes and it runs fine! Presume this is some hangover from the prompt to replace R-style '#' comments with Stan '//' ones?

The language supports both, but we’ll be getting rid of # comments soon. RStan does some text manipulation of Stan programs that are probably breaking comments.

I would recommend moving to cmdstanr if you do not need to access log density or gradient or transforms directly—it’s easier to install and it’s up to date with Stan, whereas RStan is about 2 years behind on CRAN and 1 year behind on GitHub.

1 Like

Belated thanks Bob - have finally moved to cmdstanr and everything is running much more smoothly. Will recommend to colleagues.

1 Like