This function takes either a list of data frames, or a data frame and a column to split by, and writes them all to CSV files. It then returns the list of data frames, optionally row-binded back together. It fits neatly in the middle of a longer piped workflow.

batch_csv_dump(
  data,
  split_by,
  path = ".",
  base_name = NULL,
  bind = FALSE,
  verbose = TRUE,
  ...
)

Arguments

data

A data frame or a list of data frames

split_by

Bare column name of variable to split by. If data is a list, this is unnecessary and will be ignored.

path

String giving a path at which to save files; defaults to current working directory.

base_name

Optional string to be prepended to all file names.

bind

Logical: whether to row-bind list of data frames into a single data frame. Defaults FALSE, in which case a list of data frames is returned.

verbose

Logical: whether to print files' paths and names as they're written. Defaults TRUE.

...

Additional arguments to pass to utils::write.csv, such as na or col.names.

Value

Either a list of data frames (in case of bind = FALSE) or a single data frame (in case of bind = TRUE).