Learn R Programming

plotscaper (version 0.2.8)

reducer: Create a reducer

Description

Constructs a reducer that can be used to show alternative summaries in a plotscaper plot.

Usage

reducer(initialfn = NULL, reducefn = NULL, name = NULL)

Value

A reducer (which is really just a list with some additional formatting)

Arguments

initialfn

An JavaScript initializing function

reducefn

A JavaScript reducer function specified

name

A name for the reducer (a string)

Details

reducefn and initialfn should be strings interpretable as JavaScript functions. Further:

  • initialfn should take 0 arguments and just return some value (i.e. a thunk).

  • reducefn should take two arguments previous and next and return a result of the same type as previous.

Examples

Run this code
r <- reducer(initialfn = "() => 0",
             reducefn = "(x, y) => Math.max(x, y)",
             name = "max")
create_schema(mtcars) |>
  add_barplot(c("cyl", "mpg"), options = list(reducer = r))

Run the code above in your browser using DataLab