Skip to content

Commit

Permalink
drop_modeltime_model business-science#160
Browse files Browse the repository at this point in the history
  • Loading branch information
AlbertoAlmuinha committed Aug 8, 2022
1 parent ebbe08f commit 13f00ae
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 1 deletion.
2 changes: 1 addition & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ export(damping)
export(damping_smooth)
export(default_forecast_accuracy_metric_set)
export(distribution)
export(drop_modeltime_model)
export(enquo)
export(enquos)
export(error)
Expand Down Expand Up @@ -306,7 +307,6 @@ export(window_function_predict_impl)
export(window_reg)
export(xgboost_impl)
export(xgboost_predict)
import(StanHeaders)
importFrom(magrittr,"%>%")
importFrom(parsnip,fit)
importFrom(parsnip,fit_xy)
Expand Down
46 changes: 46 additions & 0 deletions R/helpers-modeltime_table.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#' @seealso
#' - [combine_modeltime_tables()]: Combine 2 or more Modeltime Tables together
#' - [add_modeltime_model()]: Adds a new row with a new model to a Modeltime Table
#' - [drop_modeltime_model()]: Drop one or more models from a Modeltime Table
#' - [update_modeltime_description()]: Updates a description for a model inside a Modeltime Table
#' - [update_modeltime_model()]: Updates a model inside a Modeltime Table
#' - [pull_modeltime_model()]: Extracts a model from a Modeltime Table
Expand Down Expand Up @@ -112,6 +113,7 @@ combine_modeltime_tables <- function(...) {
#' @seealso
#' - [combine_modeltime_tables()]: Combine 2 or more Modeltime Tables together
#' - [add_modeltime_model()]: Adds a new row with a new model to a Modeltime Table
#' - [drop_modeltime_model()]: Drop one or more models from a Modeltime Table
#' - [update_modeltime_description()]: Updates a description for a model inside a Modeltime Table
#' - [update_modeltime_model()]: Updates a model inside a Modeltime Table
#' - [pull_modeltime_model()]: Extracts a model from a Modeltime Table
Expand Down Expand Up @@ -144,6 +146,47 @@ add_modeltime_model <- function(object, model, location = "bottom") {

}

# DROP MODEL -----

#' Drop a Model from a Modeltime Table
#'
#' @param object A Modeltime Table (class `mdl_time_tbl`)
#' @param .model_id A numeric value matching the .model_id that you want to drop
#'
#' @seealso
#' - [combine_modeltime_tables()]: Combine 2 or more Modeltime Tables together
#' - [add_modeltime_model()]: Adds a new row with a new model to a Modeltime Table
#' - [drop_modeltime_model()]: Drop one or more models from a Modeltime Table
#' - [update_modeltime_description()]: Updates a description for a model inside a Modeltime Table
#' - [update_modeltime_model()]: Updates a model inside a Modeltime Table
#' - [pull_modeltime_model()]: Extracts a model from a Modeltime Table
#'
#' @examples
#' \donttest{
#' library(tidymodels)
#'
#'
#' m750_models %>%
#' drop_modeltime_model(.model_id = c(2,3))
#' }
#'
#' @export
drop_modeltime_model <- function(object, .model_id) {

if (!rlang::is_bare_numeric(.model_id)){
rlang::abort(".model_id must be numeric")
}

if (!is_modeltime_table(object)){
rlang::abort("object must be a 'modeltime_table'")
}

ret <- object %>%
dplyr::filter(!(.model_id %in% !!.model_id))

return(ret)

}

# UPDATE MODEL ----

Expand All @@ -157,6 +200,7 @@ add_modeltime_model <- function(object, model, location = "bottom") {
#' @seealso
#' - [combine_modeltime_tables()]: Combine 2 or more Modeltime Tables together
#' - [add_modeltime_model()]: Adds a new row with a new model to a Modeltime Table
#' - [drop_modeltime_model()]: Drop one or more models from a Modeltime Table
#' - [update_modeltime_description()]: Updates a description for a model inside a Modeltime Table
#' - [update_modeltime_model()]: Updates a model inside a Modeltime Table
#' - [pull_modeltime_model()]: Extracts a model from a Modeltime Table
Expand Down Expand Up @@ -213,6 +257,7 @@ update_modeltime_model.mdl_time_tbl <- function(object, .model_id, .new_model) {
#' @seealso
#' - [combine_modeltime_tables()]: Combine 2 or more Modeltime Tables together
#' - [add_modeltime_model()]: Adds a new row with a new model to a Modeltime Table
#' - [drop_modeltime_model()]: Drop one or more models from a Modeltime Table
#' - [update_modeltime_description()]: Updates a description for a model inside a Modeltime Table
#' - [update_modeltime_model()]: Updates a model inside a Modeltime Table
#' - [pull_modeltime_model()]: Extracts a model from a Modeltime Table
Expand Down Expand Up @@ -256,6 +301,7 @@ update_modeltime_description <- update_model_description
#' @seealso
#' - [combine_modeltime_tables()]: Combine 2 or more Modeltime Tables together
#' - [add_modeltime_model()]: Adds a new row with a new model to a Modeltime Table
#' - [drop_modeltime_model()]: Drop one or more models from a Modeltime Table
#' - [update_modeltime_description()]: Updates a description for a model inside a Modeltime Table
#' - [update_modeltime_model()]: Updates a model inside a Modeltime Table
#' - [pull_modeltime_model()]: Extracts a model from a Modeltime Table
Expand Down
1 change: 1 addition & 0 deletions man/add_modeltime_model.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/combine_modeltime_tables.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 36 additions & 0 deletions man/drop_modeltime_model.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/pluck_modeltime_model.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/update_model_description.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/update_modeltime_model.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 13f00ae

Please sign in to comment.