Rds imported model works incorrectly with marginaleffects

hey folks
I’m trying to use a fitted brms model, saved to .rds file with marginaleffects package.

After saving and loading the model, generating posterior predictions wouldn’t work if I use non-default newdata parameter, see the code below

brm_model = readRDS('ouad_brm_model.rds')
library(marginaleffects)
conditional_preds <- predictions(
  brm_model,
  newdata = datagrid(gender = c("F", "M")), # any non-default parameter returns zeros in estimates
  by = "gender", 
  re_formula = NA
) %>%
  posteriordraws()

conditional_preds %>% head()

R version 4.3.0 (2023-04-21), marginaleffects_0.9.0, brms_2.19.0. Thanks in advance for any ideas!

My guess is that the dataset is no longer in the global environment, so marginaleffects cannot retrieve it.

The datagrid() function also accepts a newdata argument (in addition to the newdata argument in predictions()), so you can feed your data frame explicitly to datagrid().

If that doesn’t work, you can send me a message on Github with a full replicable example (including data). I rarely visit this forum, so may not see your response.