I see. I might add the write to csv functionality as I see this request quite often.
The best way to keep track though is to submit an issue on github https://github.com/xiaodaigh/disk.frame/issues I have done that this time see https://github.com/xiaodaigh/disk.frame/issues/311
If you want to write each chunk to a separate CSV just do
df %>%
cimap(function(id, chunk) {
data.table::fwrite(chunk, file.path("some/path/", paste0(id, ".csv"))
NULL # return null since you don't need to return anything
}, lazy=FALSE)
E.g.
library(disk.frame)
a = as.disk.frame(nycflights13::flights)
cimap(a, function(chunk, id) {
data.table::fwrite(chunk, file.path(tempdir(), paste0(id, ".csv")))
NULL
}, lazy=FALSE)
dir(tempdir())
If you wish to write to one file just modify to write to one file via append=TRUE
, but make sure you turn off multiple workers!
setup_disk.frame(workers = 1) # only one worker
cmap(a, function(chunk) {
data.table::fwrite(chunk, file.path(tempdir(), "one_file.csv"), append = TRUE)
NULL
}, lazy=FALSE)
setup_disk.frame() # turn multi worker back on
dir(tempdir())