R/normalized_filename.r

Defines functions normalized_filename

Documented in normalized_filename

#' Normalize a file name.
#'
#' Given a string, will check if a file by that name exists.
#' If not, it will try to append '.r' and try again.
#' If not, it will try to append '.R' and try again.
#' Otherwise, it returns FALSE.
#'
#' @param filename a character. The name of a file.
#' @name normalized_filename
#' @examples
#' \dontrun{
#' normalize_filename('test') # will find test.r or test.R
#' normalize_filename('test.r') # just returns test.r
#' }
normalized_filename <- function(filename) {
  # TODO: Extend to use regular expressions
  if (file.exists(filename)) filename
  else if (file.exists(tmp <- pp("#{filename}.r"))) tmp
  else if (file.exists(tmp <- pp("#{filename}.R"))) tmp
  else FALSE
}
robertzk/syberiaStructure documentation built on May 27, 2019, 11:38 a.m.