sprinkle_fn: Apply a function to a selection of cells

Description Usage Arguments Details Functional Requirements Author(s)

View source: R/sprinkle_fn.R

Description

The pre-defined sprinkles do not always provide the desired impact on the tables. Applying a function allows for highly customized output without having to pre-process that data frame.

Usage

 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
sprinkle_fn(
  x,
  rows = NULL,
  cols = NULL,
  fn = NULL,
  part = c("body", "head", "foot", "interfoot", "table"),
  fixed = FALSE,
  recycle = c("none", "rows", "cols"),
  ...
)

## Default S3 method:
sprinkle_fn(
  x,
  rows = NULL,
  cols = NULL,
  fn = NULL,
  part = c("body", "head", "foot", "interfoot", "table"),
  fixed = FALSE,
  recycle = c("none", "rows", "cols", "columns"),
  ...
)

## S3 method for class 'dust_list'
sprinkle_fn(
  x,
  rows = NULL,
  cols = NULL,
  fn = NULL,
  part = c("body", "head", "foot", "interfoot", "table"),
  fixed = FALSE,
  recycle = c("none", "rows", "cols", "columns"),
  ...
)

Arguments

x

An object of class dust

rows

Either a numeric vector of rows in the tabular object to be modified or an object of class call. When a call, generated by quote(expression), the expression resolves to a logical vector the same length as the number of rows in the table. Sprinkles are applied to where the expression resolves to TRUE.

cols

Either a numeric vector of columns in the tabular object to be modified, or a character vector of column names. A mixture of character and numeric indices is permissible.

fn

An object of class call. The function should act on an object value (which is an internal column in the dust object). It is recommend to wrap the function call in quote. For example, quote(pvalString(value)) or quote(format(value, nsmall = 3)).

part

A character string denoting which part of the table to modify.

fixed

logical(1) indicating if the values in rows and cols should be read as fixed coordinate pairs. By default, sprinkles are applied at the intersection of rows and cols, meaning that the arguments do not have to share the same length. When fixed = TRUE, they must share the same length.

recycle

A character one that determines how sprinkles are managed when the sprinkle input doesn't match the length of the region to be sprinkled. By default, recycling is turned off. Recycling may be performed across rows first (left to right, top to bottom), or down columns first (top to bottom, left to right).

...

Additional arguments to pass to other methods. Currently ignored.

Details

dust objects transform tabular objects so that each cell in the table comprises one row in the data frame of cell attributes. The function to be applied needs to act on the value column of that data frame.

Functional Requirements

  1. Correctly reassigns the appropriate elements fn column in the table part.

  2. Casts an error if x is not a dust object.

  3. Casts an error if fn is not a call object.

  4. Casts an error if part is not one of "body", "head", "foot", or "interfoot"

  5. Casts an error if fixed is not a logical(1)

  6. Casts an error if recycle is not one of "none", "rows", or "cols"

Author(s)

Benjamin Nutter


pixiedust documentation built on Jan. 16, 2021, 5:25 p.m.