Row-wise caching of operations on data frame.

flow_dfr(..., fn = NULL, fn_id = NULL,
  flow_options = get_flow_options())

Arguments

...

Named arguments to pass to fn. The first argument must be a data.frame or tibble. Row names are not supported.

fn

The function to apply to the data frame. It must accept a data frame as the first argument.

fn_id

Optional id to uniquely identify the function. By default, rflow functions reuse the cache if the same function is given. The id allows the user to suppress console messages and to explicitly indicate whether to reuse the old cache or create a new one.

flow_options

List of options created using get_flow_options.

Value

The flow object.

Details

Function fn operates on a data frame received as argument. fn will receive only the rows changed; it may drop some of the rows, but will not add any new rows. The function fn may return fewer or more columns or modify existing columns as long it always returns a consistent schema (i.e., the same column data types and names) for all calls. The data frame df passed to fn will include one additional column ..row_hash.. that must be returned as is in order to identify changes.

Arguments fn, fn_id and flow_options, when provided, must be named. Argument fn must be always provided.

Examples

df_fn <- function(df, i = NULL) { if (is.null(i)) { dfi <- df dfi$rm <- rowMeans(dfi[1:10]) } else { dfi <- df[i, , drop = FALSE] } dfi } # the flow element can also become input for another flow_df function # in order to allow multiple, chained computations dfr_flow <- flow_dfr(mtcars, 1, fn = df_fn)
#> New cache: fn=df_fn / fn_id=1 / fn_key=ca704c02dbfc38cc
collected_dfr <- dfr_flow %>% collect()