Skip to content

Instantly share code, notes, and snippets.

Last active Oct 26, 2021
What would you like to do?
Iteratively zip up folders of files (no subfolders) with R, where each file is some group (e.g. an organisation's results)
# Zip up folders programmatically
# Must getwd()/setwd() to prevent full filepaths being saved
# Example: a folder of files (no subfolders) for groups A, B, C
zip_micro <- function(group_code) {
work_dir <- getwd() # project root
out_dir <- file.path(work_dir, "output") # has folders to zip
setwd(out_dir) # switch to location with folders to zip
zipfile = paste0(Sys.Date(), "_", group_code, ".zip"),
files = group_code # folder to be zipped
setwd(work_dir) # back to original working directory
walk(c("A", "B", "C"), zip_micro) # iterate to zip each group's folder
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment