usemodels icon indicating copy to clipboard operation
usemodels copied to clipboard

[idea] return a list + print method

Open Athospd opened this issue 5 years ago • 1 comments

Hello @topepo

Imagine if foo <- usemodels::use_xgboost(mpg~., mtcars) would return a list of code chunks, like

foo <- list();
foo$recipe <- "xgb_recipe <- 
  recipe(formula = mpg ~ ., data = mtcars) %>% 
  step_zv(all_predictors()) "
foo$recipe
#> [1] "xgb_recipe <- \n  recipe(formula = mpg ~ ., data = mtcars) %>% \n  step_zv(all_predictors()) "
cat(foo$recipe)
#> xgb_recipe <- 
#>   recipe(formula = mpg ~ ., data = mtcars) %>% 
#>   step_zv(all_predictors())

Created on 2020-06-18 by the reprex package (v0.3.0)

It would suit perfectly for build custom rstudio snippets programatically, like this one by @RobertMyles https://www.robertmylesmcdonnell.com/content/posts/modelscript/

The cat()'s could live inside a print() S3 method...

I would love to contribute with this if it sounds like a good idea.

Athospd avatar Jun 18 '20 16:06 Athospd

Great idea. Go for it!

topepo avatar Aug 17 '20 19:08 topepo