Issues running kfold() after saving and reloading a brmsfit object

I am having an issue running brms::kfold() after running a brms fit object with cmdrstan backend (and threads), saving and then reloading from file. A reproducible example:

library(brms)

data("epilepsy")

m <- brm(formula = count ~ 1 + (1|patient), data = epilepsy, backend = "cmdstanr", threads = threading(2), file = "m.Rds")

#restart R or exit and reopen R
#reload brms
library(brms)
m <- readRDS("m.Rds")

kfold(m)

Fitting model 1 out of 10
Fitting model 2 out of 10
Fitting model 3 out of 10
Fitting model 4 out of 10
Fitting model 5 out of 10
Fitting model 6 out of 10
Fitting model 7 out of 10
Fitting model 8 out of 10
Fitting model 9 out of 10
Fitting model 10 out of 10
Start sampling
Error: Model not compiled. Try running the compile() method first.

The issue here is that my brmsfit objects must be loaded from file as they are not run on my machine.

Any tips/tricks/workarounds would be greatly appreciated!

Thanks in advance!

  • Operating System: macOS catalina
  • R version 4.0.3
  • brms Version: 2.16.2

The m object stores path to the executable model binary which I assume is stored in a temporary directory and when you restart R it can’t found anymore. That hint brms gives you Try running the compile() method first. might work, but I haven’t tested. I’m pinging @paul.buerkner in case if he can confirm whether it is possible to re-compile the model based on the information available in the brms object.