Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Data can only be called 'df' in the {drake} and {targets} packages #598

Closed
gorkang opened this issue Sep 24, 2020 · 2 comments
Closed

Data can only be called 'df' in the {drake} and {targets} packages #598

gorkang opened this issue Sep 24, 2020 · 2 comments

Comments

@gorkang
Copy link

gorkang commented Sep 24, 2020

When using workflow packages {drake} and {targets}, the only way to be able to use lme4::lmer() is if the data is called df. If the data frame used has any other name, you get an error.

I reported this issue to the {targets} developer here ropensci/targets#160 and he suggested to check here.

Please see reproducible examples below.

library(drake)
library(lme4)

plan_OK <- drake_plan(
  df = sleepstudy,
  mod = lme4::lmer("Reaction ~ Days + (Days | Subject)", df))

plan_BAD <- drake_plan(
  DF = sleepstudy,
  mod = lme4::lmer("Reaction ~ Days + (Days | Subject)", DF))

make(plan_OK)
make(plan_BAD)

plan_OK works fine, but plan_BAD gives the following error:

Error: target mod failed.
diagnose(mod)$error$message:
use of NULL environment is defunct
diagnose(mod)$error$calls:
lme4::lFormula(formula = "Reaction ~ Days + (Days | Subject)",
data = DF, control = list("nloptwrap", TRUE, 1e-05, TRUE,
FALSE, list("ignore", "stop", "ignore", "stop", "stop",
"message+drop.cols", "warning", "stop"), list(list(
"warning", 0.002, NULL), list("message", 1e-04),
list("warning", 1e-06)), list()))
lme4:::checkFormulaData(formula, data, checkLHS = control$check.formula.LHS ==
"stop")
lme4:::allvarex(environment(formula))
base::vapply(vvec, varex, NA, env)
lme4:::FUN(X[[i]], ...)
base::exists(v, envir = env, inherits = FALSE)

The same happens in {targets}, a newer package similar in scope to {drake}:

library(targets)
library(lme4)

tar_script({
  library(targets)
  tar_option_set(packages = c("targets", "lme4"))

  tar_pipeline(
    tar_target(df2,  sleepstudy),
    tar_target(model, lme4::lmer(Reaction ~ Days + (Days | Subject), data = df2))
  )
})

tar_make()

If data is called df, it works, otherwise (as in the example above), fails with the error :

Error : 'data' not found, and some variables missing from formula environment .
Error: callr subprocess failed: 'data' not found, and some variables missing from formula environment .

@bbolker
Copy link
Member

bbolker commented Sep 24, 2020

This actually seems to be resolved already in the development version: try remotes::install_github("lme4/lme4") and see how it goes?

The new version will be released in the fairly near future (i.e., probably a couple of weeks)

@gorkang
Copy link
Author

gorkang commented Sep 25, 2020

It is indeed solved in the development version! I looked around the closed issues but did not find anything obviously related. Sorry for not checking before. Thanks!

@gorkang gorkang closed this as completed Sep 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants