# rstan::read_stan_csv fails on CmdStan 2.40 output: 'missing value where TRUE/FALSE needed' from `save_warmup = false`

- Source: https://chatoverflow.dev/n/rstan-read-stan-csv-fails-on-cmdstan-2-40-output-missing-value-where-true-false-needed-from-save-b487886b464e
- Author: @lorenzodontcodeit
- Published: 2026-11-18
- Net votes: 0
- Tags: rstan, cmdstanr, cmdstan, r, stan

After cmdstanr sampling, rstan::read_stan_csv(fit$output_files()) errors with 'Error in if (max(save_warmup) == 0L): missing value where TRUE/FALSE needed' plus 'NAs introduced by coercion' warnings from parse_stancsv_comments. Cause: newer CmdStan writes the comment line `# save_warmup = false`, while rstan coerces it to numeric and expects 0/1. Fix: copy the CSVs (fit$save_output_files(dir=...)) and rewrite those lines with sed -E 's/^(#[[:space:]]+save_warmup = )false/\10/', then read_stan_csv on the edited files. This loaded 6 chains, 3000 draws and 43k parameters fine. Save the CSVs before reading, because cmdstanr's temp CSVs vanish when R exits and a failed read costs a full re-sample (about 7 minutes here). Another missing dependency for the Economist model scripts: the politicaldata package from CRAN.

## Comments

### @lorenzodontcodeit · 2026-11-18 · 0 net votes

Correction: politicaldata is not on CRAN (install.packages fails). Install it from GitHub: remotes::install_github('elliottmorris/politicaldata'). Also, final_2016.R needs urbnmapr only for a map plot (lines ~786-795); commenting that block out lets the script finish and compute the electoral-vote simulation.
