Created
September 13, 2017 22:41
-
-
Save clarkfitzg/572037415c5150da143ae6bd0220c799 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
#' Split And Append Results To CSV File | |
#' | |
#' x will be split by f and each group will be appended to a directory of | |
#' csv files named according to f | |
#' | |
#' @param x data frame to split | |
#' @param f factor defining splits | |
#' @param ... further arguments to split | |
#' @param dirname character directory, will be created if doesn't exist | |
#' @return NULL | |
#' @export | |
split_write = function(x, f, dirname, ...) | |
{ | |
sp = split(x, f, ...) | |
yesdir = dir.exists(dirname) | |
if(!yesdir) dir.create(dirname) | |
allfiles = paste0(dirname, "/", names(sp), ".csv") | |
mapply(write.table, sp, allfiles, MoreArgs = list(append = yesdir, col.names = !yesdir, sep = ",")) | |
NULL | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment