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)
}
richelbilderbeek/beastscriptr documentation built on April 9, 2024, 2:28 p.m.