filter = create_chunk_mapper(dplyr::filter)
#' example: creating a function that keeps only the first and last n row
first_and_last <- function(chunk, n, ...) {
nr = nrow(chunk)
print(nr-n+1:nr)
chunk[c(1:n, (nr-n+1):nr), ]
}
#' create the function for use with disk.frame
first_and_last_df = create_chunk_mapper(first_and_last)
mtcars.df = as.disk.frame(mtcars)
#' the operation is lazy
lazy_mtcars.df = mtcars.df %>%
first_and_last_df(2)
#' bring into R
collect(lazy_mtcars.df)
#' clean up
delete(mtcars.df)
Run the code above in your browser using DataLab