Determine required packages for a model
Usage
# S3 method for model_spec
required_pkgs(x, infra = TRUE, ...)
# S3 method for model_fit
required_pkgs(x, infra = TRUE, ...)
Arguments
- x
A model specification or fit.
- infra
Should parsnip itself be included in the result?
- ...
Not used.
Examples
should_fail <- try(required_pkgs(linear_reg(engine = NULL)), silent = TRUE)
should_fail
#> [1] "Error in required_pkgs(linear_reg(engine = NULL)) : Please set an engine.\n"
#> attr(,"class")
#> [1] "try-error"
#> attr(,"condition")
#> <error/rlang_error>
#> Error in `required_pkgs()`:
#> ! Please set an engine.
#> ---
#> Backtrace:
#> 1. pkgdown::build_site_github_pages(new_process = FALSE, install = FALSE)
#> 2. pkgdown::build_site(...)
#> 3. pkgdown:::build_site_local(...)
#> 4. pkgdown::build_reference(...)
#> 5. purrr::map(...)
#> 6. pkgdown .f(.x[[i]], ...)
#> 8. pkgdown:::data_reference_topic(...)
#> 9. pkgdown:::run_examples(...)
#> 10. pkgdown:::highlight_examples(code, topic, env = env)
#> 11. downlit::evaluate_and_highlight(...)
#> 12. evaluate::evaluate(code, child_env(env), new_device = TRUE, output_handler = output_handler)
#> 13. evaluate:::evaluate_call(...)
#> 23. evaluate:::eval_with_user_handlers(expr, envir, enclos, user_handlers)
#> 24. [ base::eval(...) ] with 1 more call
#> 32. parsnip:::required_pkgs.model_spec(linear_reg(engine = NULL))
linear_reg() %>%
set_engine("glmnet") %>%
required_pkgs()
#> [1] "parsnip" "glmnet"
linear_reg() %>%
set_engine("glmnet") %>%
required_pkgs(infra = FALSE)
#> [1] "glmnet"
linear_reg() %>%
set_engine("lm") %>%
fit(mpg ~ ., data = mtcars) %>%
required_pkgs()
#> [1] "parsnip" "stats"