-
Notifications
You must be signed in to change notification settings - Fork 285
/
Copy pathcallback.Rd
56 lines (50 loc) · 1.98 KB
/
callback.Rd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/callback.R
\name{callback}
\alias{callback}
\alias{ChunkCallback}
\alias{SideEffectChunkCallback}
\alias{DataFrameCallback}
\alias{ListCallback}
\alias{AccumulateCallback}
\title{Callback classes}
\description{
These classes are used to define callback behaviors.
}
\details{
\describe{
\item{ChunkCallback}{Callback interface definition, all callback functions should inherit from this class.}
\item{SideEffectChunkCallback}{Callback function that is used only for side effects, no results are returned.}
\item{DataFrameCallback}{Callback function that combines each result together at the end.}
\item{AccumulateCallBack}{
Callback function that accumulates a single result. Requires the parameter \code{acc} to specify
the initial value of the accumulator. The parameter \code{acc} is \code{NULL} by default.
}
}
}
\examples{
## 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)
}
\seealso{
Other chunked:
\code{\link{melt_delim_chunked}()},
\code{\link{read_delim_chunked}()},
\code{\link{read_lines_chunked}()}
}
\concept{chunked}
\keyword{internal}