Error in read_cmdstan_csv Assertion on 'files' failed

For some reason my previously written code doesn’t work anymore (it used to work with no problem). Here is my code:

output = readRDS('Fitted_model.rds') #Loading the fitted model

> class(output)
[1] "CmdStanMCMC" "CmdStanFit"  "R6"    

> post_matrix  <- output$draws(c("y_sim")) 
Error in read_cmdstan_csv(files = self$output_files(include_failed = FALSE),  : 
  Assertion on 'files' failed: File does not exist: '/tmp/RtmppHtKLX/k7_VIARCH-202209121104-1-3dd4e0.csv'.

Does anyone know how to fix this?

It sounds like the saved object was still pointing to the (temporary) CSV files, did you originally create Fitted_model.rds with $save_object()?

I simply used saveRDS() function. And the code used to work with no problem. I have no idea what has changed since then.

CmdStanR saves output files from sampling in a temporary directory. Depending on your operating system/settings, these will be deleted every login/every day/at random

Then how am I supposed to save the fitted model to avoid this error?

Cmdstanr provides a wrapper around saveRDs: Save fitted model object to a file — fit-method-save_object • cmdstanr

You can also save the output files and then load them again:

2 Likes