Created
May 21, 2022 23:08
-
-
Save favstats/2faca357aa2bfd10623bd76c16adcbde to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
save_csv <- function(d, path) { | |
if(file.exists(path)){ | |
readr::write_csv(d, append = T, file = path) | |
} else { | |
dirs_to_create <- stringr::str_split(path, "\\/") %>% | |
unlist() %>% | |
purrr::discard(~stringr::str_detect(.x, "\\.")) %>% | |
paste0(collapse = "/") | |
if(stringr::str_count(dirs_to_create) != 0){ | |
dir.create(dirs_to_create, recursive = T) | |
} | |
readr::write_csv(d, file = path) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment