R/create_status_cols.R

Defines functions create_status_cols

Documented in create_status_cols

#' @title
#'    Initializes the `sawmill_status` and `sawmill_pass` columns at the start
#'    of the \code{check_grain()} function
#'
#' @description
#'    \code{create_status_cols()} adds columns to the passed tibble, containing
#'    the sawmill status provided.
#'
#' @param timber
#'    A tibble of timber, with a table built by \code{\link{build_table}}.
#'
#' @param status
#'    A sawmill status description.
#'
#' @details
#'    The \code{create_status_cols()} function works by initializing the default
#'    sawmill status as specified in the \code{check_grain()} function.
#'    The `sawmill_pass` column indicates whether sawmill should operate on the
#'    resistance outcome. Set `sawmill_pass = FALSE` after other co-occurring
#'    events during check failure.
#'
#' @return
#'    The passed tibble of timber with additional columns containing the current
#'    sawmill status.
#'
#'
#' @export

create_status_cols <- function(timber, status = "Initialized.") {
  # Column 'sawmill_pass' indicates whether sawmill should operate on the
  # resistance outcome. Set 'sawmill_pass = FALSE' after other co-occurring
  # events during check failure.
  if (!("sawmill_pass" %in% names(timber))) {
    timber[, "sawmill_pass"] <- TRUE
    message("Column 'sawmill_pass' did not exist and was created.")
  }

  # Column 'sawmill_status' indicates the current sawmill status.
  # Set 'sawmill_status' after every sawmill operation.
  if (!("sawmill_status" %in% names(timber))) {
    # Default status
    timber[, "sawmill_status"] <- status
    message("Column 'sawmill_status' did not exist and was created.")
  }

  return(timber)
}
iAM-AMR/sawmill documentation built on June 30, 2024, 2:25 a.m.