First a function for generating some data
gendata <- function() {
n <- 1E3
data.frame(a = 1:n, b = rnorm(n), c = sample(letters, n, replace=TRUE))
}
ff
+ ffbase
For ff
the following pattern can be used:
library(ffbase)
dat <- NULL
for (i in seq_len(10)) {
d <- gendata()
dat <- ffdfappend(dat, d)
}
save.ffdf(dat, dir="./test")
The data can be loaded again by using load.ffdf("./test")
.
CSV
For test/csv files the following pattern can be used:
con <- file("test.csv", "wt")
first_block <- TRUE
for (i in seq_len(10)) {
d <- gendata()
write.table(d, file=con, sep=",", row.names=FALSE, col.names=first_block)
first_block <- FALSE
}
close(con)
To use it, you will first have to import it into ff
or bigmemory
, or you can use it (read only) using LaF
.