Attach a layer to a
add_layer attaches a
tplyr_layer to a
tplyr_table object. This allows
for a tidy style of programming (using
magrittr piping, i.e.
%>%) with a
secondary advantage - the construction of the layer object may consist of a series of piped
Tplyr encourages a user to view the construction of a table as a series of "layers".
The construction of each of these layers are isolated and independent of one another - but
each of these layers are children of the table itself.
add_layer isolates the construction
of an individual layer and allows the user to construct that layer and insert it back into the
parent. The syntax for this is intuitive and allows for tidy piping. Simply pipe the current
table object in, and write the code to construct your layer within the
add_layers is another approach to attaching layers to a
tplyr_table. Instead of
constructing the entire table at once,
add_layers allows you to construct layers as
different objects. These layers can then be attached into the
tplyr_table all at
add_layers both additionally allow you to name the layers as you
attach them. This is helpful when using functions like
get_stats_data when you can access information from a layer directly.
add_layer has a name parameter, and layers can be named in
submitting the layer as a named argument.
A layer construction function and associated modifier functions
A name to provide the layer in the table layers container
Layers to be added
tplyr_subgroup_layer with a new layer inserted into the
# Load in pipe library(magrittr) ## Single layer t <- tplyr_table(mtcars, cyl) %>% add_layer( group_desc(target_var=mpg) ) ## Single layer with name t <- tplyr_table(mtcars, cyl) %>% add_layer(name='mpg', group_desc(target_var=mpg) ) # Using add_layers t <- tplyr_table(mtcars, cyl) l1 <- group_desc(t, target_var=mpg) l2 <- group_count(t, target_var=cyl) t <- add_layers(t, l1, 'cyl' = l2)