Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

Model methods fail on a reloaded fit when the data was passed in memory

Open
#1,331 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

@jgabry is already working on this.

Since Oct 16, 2026.

  • #1332 by @jgabry — open

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
45/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
r
Domain
backend

Research direction

Start with the $save_object() and $init_model_methods() methods on the fit object, and with $save_data_file(), which the issue says is the only way the data survives. Reproduce by saving a fit whose data was passed as a list, reloading it in a new session, and calling $log_prob(). Done means the model methods compile on the reloaded fit when data is supplied to $init_model_methods(), and the existing save/reload tests still pass.

Written by the indexing model from the issue text.

Description

bug

A fit created with data = list(...), saved with $save_object() and reloaded in a new R session compiles the model methods and then errors:

# session 1
fit <- cmdstanr_example("logistic")
fit$save_object("fit.rds")

# session 2
fit <- readRDS("fit.rds")
fit$log_prob(rep(0, 4))
#> Error : Error in JSON parsing
#> at offset 0:
#> The document is empty.

The fitted model object only stores the path to the JSON file CmdStanR wrote in the first session's tempdir, and $save_object() reads in the draws and diagnostics but not the data (on purpose since data files can be very large). This means that in the new session the path points nowhere unless the user had previously called fit$save_data_file() before the end of the initial session.

Instead of storing the data in the fit (we want to avoid this), we can add a data argument to $init_model_methods() for the cases when it's needed.

Dominant language
R
Stars
164
Forks
69
Avg merge
1d 9h
Merged PRs (30d)
48

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from stan-dev/cmdstanr

All issues in stan-dev/cmdstanr

Similar issues

More R issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.