R/check_files_exist.R

Defines functions check_files_exist

Documented in check_files_exist

#' check input/ouput file/directories are valid
#'
#'
#' @author Al J Abadi, \email{aljalabadi@@gmail.com}
#' @title input/ouput checker
#' @param io_list list of input/output files/directories
#' @return if any files/directories are missing, will produce an error mentioning the missing ones
#' @export
#' @keywords file check
#' @examples
#' \dontrun{check_files-exist(list('~/.Rprofile'))}
###### You can have a family of function to see in see also
#' @family file
check_files_exist <- function(io_list){
  ## flatten the list
  io_flat <- as.list(unlist(io_list, recursive=TRUE))
  non_exist <- io_flat  %>% .[!unlist(lapply(., file.exists))]
  if (length(non_exist))
    stop(paste0('could not find the following file(s): \n',
                paste0(non_exist, collapse = " \n")))
}
aljabadi/Altools documentation built on Jan. 17, 2022, 8:55 a.m.