tidymodels / rules

parsnip extension for rule-based models
https://rules.tidymodels.org
Other
40 stars 4 forks source link

address `devtools::load_all()` test helper objects error #50

Closed simonpcouch closed 2 years ago

simonpcouch commented 2 years ago

At the moment, with the main dev branch of the package, I see:

> devtools::load_all()
ℹ Loading rules
Error in ifelse(Chicago$Cubs_Home, "home", "away") : 
  object 'Chicago' not found

This was due to some environment / scoping issues in tests/testthat/helpers.R that I was able to reproduce on cloud and workbench as well. I opted to instead save the data objects to file and load them at the beginning of tests—this seems somewhat 3e acceptable, but I'm not super opinionated about this implementation. :)

topepo commented 2 years ago

I think that we would probably recommend that the helper file should have different functions for different data sets. So, for example,

make_ad_data <- function() {
  data("ad_data")

  ad_mod  <- ad_data %>% slice(-(1:10)) %>% select(Class, Genotype, p_tau, MMP10)
  ad_pred <- ad_data %>% slice(  1:10 ) %>% select(       Genotype, p_tau, MMP10)
  ad_mod_x <-
    model.matrix(Class ~ ., data = ad_mod)  %>%
    as.data.frame() %>%
    select(-1)
  ad_pred_x <-
    model.matrix( ~ ., data = ad_pred)  %>%
    as.data.frame() %>%
    select(-1)

  ad_mod <- as.data.frame(ad_mod)
  ad_pred <- as.data.frame(ad_pred)

  list(mod_x = ad_mod_x, pred_x = ad_pred_x, mod = ad_mod, pred = ad_pred)
}
simonpcouch commented 2 years ago

Alright, good to go!

github-actions[bot] commented 2 years ago

This pull request has been automatically locked. If you believe you have found a related problem, please file a new issue (with a reprex: https://reprex.tidyverse.org) and link to this issue.