R/check_rename_fun.R

Defines functions check_rename_fun

Documented in check_rename_fun

#' Check if the rename function is a valid filename rename function
#'
#' Will \link{stop} if not
#' @inheritParams default_params_doc
#' @return No return value, called for side effects
#' @author Richèl J.C. Bilderbeek
#' @export
check_rename_fun <- function(rename_fun) {
  if (length(rename_fun) != 1 || !is.function(rename_fun)
  ) {
    stop("'rename_fun' must be one function")
  }
  if (!is.na(rename_fun(NA))) {
    stop("'rename_fun' must return NA when given an NA")
  }
  if (length(rename_fun("some.path")) != 1 ||
      !is.character(rename_fun("some.path"))
  ) {
    stop("'rename_fun' must return a character vector with one element")
  }

  invisible(rename_fun)
}
ropensci/beautier documentation built on July 9, 2024, 6:14 a.m.