Is it possible to extract or recover data from cmdstan compiled program or cmdstanr RDS file?

I’ve created some Stan models and I’m using CmdStan, via CmdStanR, to carry out sampling. The sampling stuff is working great.

After sampling, I am saving an RDS file via mysampleoutput$save_object (where mysampleoutput is the variable holding the stuff returned by mymodel$sample).

I am looking at some RDS files created some time ago and I am wondering if it is possible to extract the data which were supplied to mymodel$sample.

I looked at names(mysampleoutput) but I don’t recognize anything about obtaining the data. (I see there is mysampleoutput$data_file but that just returns the path to a data file, presumably one into which the data were copied.)

Is there some other function which I can call to extract data from mysampleoutput?

Or, another plausible possibility, is there a way to extract data from the CmdStan program which was created by cmdstanr? (I see there is a data option for the CmdStan program, but it seems to exist only to specify an input file; I don’t see an option to return the data which were specified at the time the program was created.)

If neither of these two approaches works, is it correct to say that the data are not captured anywhere? It’s okay if the answer is yes, I just need to know what’s going on. If the data are not captured or cannot be extracted, I will be more careful to save the data when constructing a model; I just need to know if that’s necessary.

Thank you for any light you can shed on this question, I appreciate your help very much.

Robert Dodier

that is correct.

data, i.e., the variables declared in the Stan program’s data block, are supplied as inputs at runtime. the output contains all non-local variables declared in the parameters, transformed parameters, and generated quantities block.

the CmdStanPy and CmdStanR interfaces provide utilities which can write out the input data in JSON format, so in these interfaces, the functions are there which would allow you to implement something which would save both data input files, Stan program file, all config settings, and resulting output files.