R/get_last_mod.R

Defines functions get_last_mod

Documented in get_last_mod

#' Get Name of Last Modified File
#'
#' @param path string, file path
#' @param pattern string, regex
#' @param ignore.case logical
#' @param recursive logical
#'
#' @return a string with the filename of the last modified file
#'
#' @author Lillian Nguyen
#'
#' @export

get_last_mod <- function(path, pattern, ignore.case = FALSE, recursive = FALSE) {

  # Exception handling ####
  if (missing(path) | missing(pattern)) {
    stop("Missing argument(s)")
  }

  # FUNCTION #####################################################################
  files <- list.files(path, pattern, full.names = TRUE,
                      ignore.case = ignore.case, recursive = recursive)

  files %>%
    file.mtime() %>%
    which.max() %>%
    files[.] %>%
    return()
}
baltimorebudget/bbmR documentation built on Aug. 28, 2023, 6:32 p.m.