Determine required packages for a model

req_pkgs(x, ...)

# S3 method for model_spec
req_pkgs(x, ...)

# S3 method for model_fit
req_pkgs(x, ...)

Arguments

x

A model specification or fit.

...

Not used.

Value

A character string of package names (if any).

Details

For a model specification, the engine must be set.

The list does not include the parsnip package.

Examples

should_fail <- try(req_pkgs(linear_reg()), silent = TRUE) should_fail
#> [1] "Error : Please set an engine.\n" #> attr(,"class") #> [1] "try-error" #> attr(,"condition") #> <error/rlang_error> #> Please set an engine. #> Backtrace: #> 1. pkgdown::deploy_to_branch(new_process = FALSE) #> 2. pkgdown::build_site(...) #> 3. pkgdown:::build_site_local(...) #> 4. pkgdown::build_reference(...) #> 5. purrr::map(...) #> 6. pkgdown:::.f(.x[[i]], ...) #> 7. pkgdown:::data_reference_topic(...) #> 8. pkgdown:::run_examples(...) #> 9. pkgdown:::highlight_examples(code, topic, env = env) #> 10. evaluate::evaluate(x, child_env(env), new_device = TRUE) #> 11. evaluate:::evaluate_call(...) #> 21. [ base::eval(...) ] with 1 more call #> 29. parsnip:::req_pkgs.model_spec(linear_reg())
linear_reg() %>% set_engine("glmnet") %>% req_pkgs()
#> [1] "glmnet"
linear_reg() %>% set_engine("lm") %>% fit(mpg ~ ., data = mtcars) %>% req_pkgs()
#> [1] "stats"