Eight schools example fails after new rstan install

After a fresh install of rstan with
R version 4.2.1
RTools 4.2
Rstudio version 2022.02.0 Build 443

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

I can successfully run the example
example(stan_model, package = "rstan", run.dontrun = TRUE)

and the rats example

y <- as.matrix(read.table('temp/rats.txt', header = TRUE))
x <- c(8, 15, 22, 29, 36)
xbar <- mean(x)
N <- nrow(y)
T <- ncol(y)
rats_fit <- stan(file='temp/rats.stan', data = list(N=N, T=T, y=y, x=x, xbar=xbar))

But the Eight Schools example fails:

schools_dat <- list(J = 8, 
                          y = c(28,  8, -3,  7, -1,  1, 18, 12),
                          sigma = c(15, 10, 16, 11,  9, 11, 10, 18))
      
fit <- rstan::stan(file = 'temp/schools.stan', data = schools_dat)
Error in stanc(file = file, model_code = model_code, model_name = model_name,  : 
  parser failed badly

  • Operating System
    Windows 10 Enterprise 
    Version 21H2
    OS build 19044.2130
    
  • RStan Version
    rstan_2.26.13
    StanHeaders_2.26.13
    
  • 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/.../.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 States.utf8
     ctype    English_United States.utf8
     tz       America/New_York
     date     2022-11-14
     rstudio  2022.02.0+443 Prairie Trillium (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.2     2022-08-22 [1] CRAN (R 4.2.1)
     checkmate      2.1.0     2022-04-21 [1] CRAN (R 4.2.1)
     cli            3.4.1     2022-09-23 [1] CRAN (R 4.2.1)
     colorspace     2.0-3     2022-02-21 [1] CRAN (R 4.2.1)
     crayon         1.5.2     2022-09-29 [1] CRAN (R 4.2.1)
     curl           4.3.3     2022-10-06 [1] CRAN (R 4.2.1)
     desc           1.4.2     2022-09-08 [1] CRAN (R 4.2.2)
     digest         0.6.29    2021-12-01 [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.1     2022-09-01 [1] CRAN (R 4.2.1)
     inline         0.3.19    2021-05-31 [1] CRAN (R 4.2.2)
     isoband        0.2.6     2022-10-06 [1] CRAN (R 4.2.1)
     jsonlite       1.8.2     2022-10-02 [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 [1] CRAN (R 4.2.1)
     lifecycle      1.0.3     2022-10-07 [1] CRAN (R 4.2.1)
     loo            2.5.1     2022-03-24 [1] CRAN (R 4.2.2)
     magrittr       2.0.3     2022-03-30 [1] CRAN (R 4.2.1)
     MASS           7.3-58.1  2022-08-03 [1] CRAN (R 4.2.1)
     Matrix         1.5-1     2022-09-13 [1] CRAN (R 4.2.1)
     matrixStats    0.62.0    2022-04-19 [1] CRAN (R 4.2.2)
     mgcv           1.8-40    2022-03-29 [1] CRAN (R 4.2.1)
     munsell        0.5.0     2018-06-12 [1] CRAN (R 4.2.1)
     nlme           3.1-160   2022-10-10 [1] CRAN (R 4.2.1)
     pillar         1.8.1     2022-08-19 [1] CRAN (R 4.2.1)
     pkgbuild       1.3.1     2021-12-20 [1] CRAN (R 4.2.2)
     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.6     2022-09-24 [1] CRAN (R 4.2.1)
     rprojroot      2.0.3     2022-04-02 [1] CRAN (R 4.2.2)
     rstan        * 2.26.13   2022-06-25 [1] local
     scales         1.2.1     2022-08-20 [1] CRAN (R 4.2.1)
     StanHeaders  * 2.26.13   2022-06-25 [1] local
     tibble         3.1.8     2022-07-22 [1] CRAN (R 4.2.1)
     utf8           1.2.2     2021-07-24 [1] CRAN (R 4.2.1)
     V8             4.2.2     2022-11-03 [1] CRAN (R 4.2.2)
     vctrs          0.5.0     2022-10-22 [1] CRAN (R 4.2.2)
     viridisLite    0.4.1     2022-08-22 [1] CRAN (R 4.2.1)
     withr          2.5.0     2022-03-03 [1] CRAN (R 4.2.1)
    
     [1] C:/R-4.2.1/library
    

Can you post the output from:

cat(readLines("temp/schools.stan"), sep="\n")

I copied-and-pasted it from the example:

// https://github.com/stan-dev/rstan/wiki/RStan-Getting-Started#example-1-eight-schools
data {
  int<lower=0> J;         // number of schools
  real y[J];              // estimated treatment effects
  real<lower=0> sigma[J]; // standard error of effect estimates
}
parameters {
  real mu;                // population treatment effect
  real<lower=0> tau;      // standard deviation in treatment effects
  vector[J] eta;          // unscaled deviation from mu by school
}
transformed parameters {
  vector[J] theta = mu + tau * eta;        // school treatment effects
}
model {
  target += normal_lpdf(eta | 0, 1);       // prior log-density
  target += normal_lpdf(y | theta, sigma); // log-likelihood
}

Ah, it looks like we still have parsing issues when there’s a # in the file. If you remove the URL at the top of the file, it should compile fine

1 Like