Skip to content

Instantly share code, notes, and snippets.

@johnmackintosh
Last active October 25, 2022 12:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnmackintosh/7a224a58c96072910204c2fffead7df1 to your computer and use it in GitHub Desktop.
Save johnmackintosh/7a224a58c96072910204c2fffead7df1 to your computer and use it in GitHub Desktop.
quickly create subdiretories for RMarkdown outputs
# I want 18 separate folders for graphic outputs, and 17 separate folders for different outputs
# they will be saved in the "output" folder under my main project directory
library(fs)
library(here)
here <- here::here()
tablenos <- paste0("table",seq(1:17))
fignos <- paste0("fig",seq(1:18))
fs::dir_create(here("output", fignos)) # creates 18 subfolders, one for each image
fs::dir_create(here("output", tablenos)) # creates 17 subfolders, one for each image
# create all at once
folder_vec <- c(fignos, tablenos)
fs::dir_create(here("output", folder_vec))
# alternately
purrr::walk(folder_vec, ~ fs::dir_create(path = here::here("output",.x))) # there is no good reason to do this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment