callback | R Documentation |
These classes are used to define callback behaviors.
Callback interface definition, all callback functions should inherit from this class.
Callback function that is used only for side effects, no results are returned.
Callback function that combines each result together at the end.
Callback function that accumulates a single result. Requires the parameter acc
to specify
the initial value of the accumulator. The parameter acc
is NULL
by default.
Other chunked:
melt_delim_chunked()
,
read_delim_chunked()
,
read_lines_chunked()
## If given a regular function it is converted to a SideEffectChunkCallback
# view structure of each chunk
read_lines_chunked(readr_example("mtcars.csv"), str, chunk_size = 5)
# Print starting line of each chunk
f <- function(x, pos) print(pos)
read_lines_chunked(readr_example("mtcars.csv"), SideEffectChunkCallback$new(f), chunk_size = 5)
# If combined results are desired you can use the DataFrameCallback
# Cars with 3 gears
f <- function(x, pos) subset(x, gear == 3)
read_csv_chunked(readr_example("mtcars.csv"), DataFrameCallback$new(f), chunk_size = 5)
# The ListCallback can be used for more flexible output
f <- function(x, pos) x$mpg[x$hp > 100]
read_csv_chunked(readr_example("mtcars.csv"), ListCallback$new(f), chunk_size = 5)
# The AccumulateCallback accumulates results from each chunk
f <- function(x, pos, acc) sum(x$mpg) + acc
read_csv_chunked(readr_example("mtcars.csv"), AccumulateCallback$new(f, acc = 0), chunk_size = 5)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.