Skip to content

get_datagrid() fails on random effects with tokens #1156

@ryanzomorrodi

Description

@ryanzomorrodi

I was trying to make a spaghetti plot of sorts like this when I got the error below (minimal example):

library(modelbased)
library(lme4)

ri_model <- lmer(
  mpg ~ 1 + wt + (1 | cyl),
  mtcars,
  REML = FALSE
)

estimate_relation(
  ri_model,
  by = c("wt", "cyl = [sample 2]"),
  ci = NULL
) |>
  plot()
#> Error:
#> ! Variable `cyl` was not found in the data. Please check the spelling.

From the traceback it seems to be an issue with get_datagrid()

  1. ├─... %>% plot()
  2. ├─base::plot(.)
  3. └─modelbased::estimate_relation(...)
  4.   └─modelbased:::.estimate_predicted(...)
  5.     ├─insight::get_datagrid(...)
  6.     └─insight:::get_datagrid.default(...)
  7.       ├─insight::get_datagrid(...)
  8.       └─insight:::get_datagrid.data.frame(...)
  9.         ├─base::do.call(...)
 10.         └─base::lapply(by, .get_datagrid_clean_target, x = x, digits = digits)
 11.           └─insight (local) FUN(X[[i]], ...)
 12.             └─insight::format_error(...)
 13.               └─insight::format_alert(..., type = "error")

Sure enough it is

get_datagrid(
  ri_model,
  by = c("wt", "cyl = [sample 2]")
)
#> Error:
#> ! Variable `cyl` was not found in the data. Please check the spelling.

Everything seems to work fine when I get rid of the token.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Bug 🐛Something isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions