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

Yeah, I had this working yesterday, now it’s not working. I’m reading from a CSV from cmdstan. This is really slowing me down.

This is not a solution. Any suggestions?

I’m using WSL:

Windows 11 Pro
version: 25H2
OS build: 26200.7628

No idea… it was fine last night.

Can you say more about what you’re doing and how it’s breaking?

Run cmdstan in terminal on wsl.

I have rstudio open, the file is in a c: User directory.

I have stan files on WSL, which is kinda like a mounted drive.

I’m writing a json file to the WSL ubuntu drive, pathway “//wsl.localhost/Ubuntu/blahblah…”

And I’m running a stan model, which is fine, output.csv. Then I read in the Stan file:

fit = cmdstanr::read_cmdstan_csv(“//wsl.localhost/Ubuntu/home/blahblah/output.csv”), and it’s giving me this:

Assertion on ‘files’ failed: ’
output.csv’ not readable.

Prior to this, I was getting the assertion on ‘files’ failed.

I’m copying the output and the R file over from the ubuntu drive to see it can’t find the pathways, etc. Right now sending the CSV to windows.

Hold on. I had this working yesterday I’m not sure what I did.

Alright the R file and the cmdstan output both either have to be on the windows drive or the wsl Ubuntu mounted drive.

solved thanks