R/files.R

Defines functions file_copy_with_time file_set_time file_get_time mkdirp

mkdirp <- function(dir, msg = NULL) {
  s <- vlapply(dir, dir.create, recursive = TRUE, showWarnings = FALSE)
  invisible(s)
}

file_get_time <- function(path) {
  file.info(path)$mtime
}

file_set_time <- function(path, time = Sys.time()) {
  assert_that(
    is_character(path),
    inherits(time, "POSIXct"))
  vlapply(path, Sys.setFileTime, time = time)
}

## file.copy is buggy when to is a vector

file_copy_with_time <- function(from, to) {
  mkdirp(dirname(to))
  if (length(to) > 1) {
    mapply(file.copy, from, to,
           MoreArgs = list(overwrite =  TRUE, copy.date = TRUE),
           USE.NAMES = FALSE)
  } else {
    file.copy(from, to, overwrite = TRUE, copy.date = TRUE)
  }
}

Try the pkgcache package in your browser

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

pkgcache documentation built on July 26, 2023, 5:44 p.m.