R/zip_dir.R

Defines functions zip_dir

Documented in zip_dir

#' Use zip from a directory
#'
#' @param dirpath    (character vector of length 1) The directory path
#' @param zipname    (character vector of length 1) The name to give to the zipped file
#' @param pattern    (character vector of length 1) The pattern to select the files in the directory
#' @param ...        Other parameters to pass to \code{list.files}
#'
#' @return    zipname
#' @export
zip_dir <- function(dirpath, zipname, pattern = NULL, ...) {
  assert(dirpath, "character", "dirpath", 1L)
  assert(zipname, "character", "dirpath", 1L)
  if (!is.null(pattern)) assert(pattern, "character", "dirpath", 1L)
  olddir <- getwd()
  setwd(dirpath)
  utils::zip(zipfile = zipname, files = list.files("./", pattern = pattern), ...)
  setwd(olddir)
  zipname
}
salix-d/salixUtils documentation built on Aug. 14, 2024, 7:11 a.m.