R/load_recent.R

Defines functions load_recent

Documented in load_recent

#'
#' load the most recent .rdata file in a given directory
#'
#' I typically have multiple .rdata files for a given project due to updates in the data over time. Each of these .rdata files is dated and this function will load the most recent (via sorting)
#'
#' @param dir_path path to the directory containing .rdata files, of which you want the most recent
#' @export load_recent

load_recent <- function(dir_path) {

  load(
    print(
      sort(
        list.files(
          dir_path,
          recursive = FALSE,
          full.names = TRUE
        ),
        decreasing = TRUE
      )[1]
    ),
    envir = .GlobalEnv
  )

}
hild0146/hildenp documentation built on May 17, 2019, 3:58 p.m.