choreography: choreography

Description Usage Arguments Value Examples

View source: R/choreography.R

Description

The choreography is a central concept of the dance package, most of the time you don't need to use it directly, but it is used by many other functions like tango(), samba(), ...

Usage

1
choreography(.tbl, ..., .env = caller_env())

Arguments

.tbl

A data frame

...

A variable number of formulas. choreography() only uses the rhs of each of the formulas.

.env

parent environment of the created function, see rlang::new_function()

Value

a function that can be called with a single argument that represents indices.

When called with an integer vector idx, the function returns a list of each of the expressions given on the rhs evaluated on the subset of the columns, i.e. in the formula ~mean(Sepal.Length) the column Sepal.Length stands for Sepal.Length[idx].

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
moves <- choreography(iris,
  Sepal.Length = ~mean(Sepal.Length),
  Sepal.Width  = ~mean(Sepal.Width)
)

moves(1:10)
# this returns the same as
list(
  Sepal.Length = mean(iris$Sepal.Length[1:10]),
  Sepal.Width  = mean(iris$Sepal.Width[1:10])
)

romainfrancois/dance documentation built on Nov. 21, 2019, 11:49 a.m.