R/utils-asserts.R

Defines functions assert_df_cols

#' Check that all columns in a data frame
#' @param df Data frame
#' @param cols Required columns (character)
#' @param derived_from String of generating function to paste into error msg.
#' @noRd
assert_df_cols <- function(df, cols, derived_from) {
  cols_in_df <- cols %in% names(df)

  if (!all(cols_in_df)) {
    stop(
      "Not all necessary columns present in the data frame. Input `df` should ",
      "be derived from `",
      derived_from,
      "`. Missing columns are: ",
      paste(cols[!cols_in_df], collapse = ", "),
      call. = FALSE
    )
  }
}

Try the idmc package in your browser

Any scripts or data that you put into this service are public.

idmc documentation built on Sept. 30, 2024, 9:33 a.m.