R/check_file_exists.R

Defines functions check_file_exists

Documented in check_file_exists

#' Function to check if a file exists.
#' Calls \code{stop} if the file is absent
#' @param filename name of the file
#' @param filename_description description of the filename
#' @return nothing. Will \code{stop} if the file is absent,
#'   with a proper error message
#' @examples
#' check_empty_beautier_folder()
#'
#' check_file_exists(get_beautier_path("anthus_aco_sub.fas"))
#'
#' check_empty_beautier_folder()
#' @author Richèl J.C. Bilderbeek
#' @export
check_file_exists <- function(
  filename,
  filename_description = NA
) {
  if (!file.exists(filename)) {
    if (is_one_na(filename_description)) {
      stop(
        "File not found. ",
        "Could not find file with path '",
        filename,
        "'"
      )
    } else {
      check_string(filename_description)
      stop(
        "File '", filename_description, "' not found. ",
        "Could not find file with path '",
        filename,
        "'"
      )
    }
  }
}

Try the beautier package in your browser

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

beautier documentation built on Nov. 2, 2023, 5:08 p.m.