R/steps_and_checks.R

Defines functions add_check add_step check step

Documented in add_check add_step check step

## Overall wrappers to make new `step_X` or `check_Y` objects
#'
#' `step` sets the class of the `step` and `check` is for checks.
#'
#' @param subclass A character string for the resulting class. For example,
#'   if `subclass = "blah"` the step object that is returned has class
#'   `step_blah` or `check_blah` depending on the context.
#' @param ... All arguments to the operator that should be returned.
#' @param .prefix Prefix to the subclass created.
#'
#' @seealso [developer_functions]
#'
#' @keywords internal
#' @return An updated step or check with the new class.
#' @export
step <- function(subclass, ..., .prefix = "step_") {
  structure(list(...),
    class = c(paste0(.prefix, subclass), "step")
  )
}

#' @rdname step
#' @export
check <- function(subclass, ..., .prefix = "check_") {
  structure(list(...),
    class = c(paste0(.prefix, subclass), "check")
  )
}

#' Add a New Operation to the Current Recipe
#'
#' `add_step` adds a step to the last location in the recipe.
#' `add_check` does the same for checks.
#'
#' @param rec A [recipe()].
#' @param object A step or check object.
#' @return A updated [recipe()] with the new operation in the last slot.
#'
#' @seealso [developer_functions]
#'
#' @export
add_step <- function(rec, object) {
  rec$steps[[length(rec$steps) + 1]] <- object
  rec
}


#' @rdname add_step
#' @export
add_check <- function(rec, object) {
  rec$steps[[length(rec$steps) + 1]] <- object
  rec
}
topepo/recipes documentation built on April 10, 2024, 10:30 p.m.