create_sub_table: Helper function that creates a styled sub table

View source: R/create_cross_table_body.R

create_sub_tableR Documentation

Helper function that creates a styled sub table

Description

This function creates a styled cross table from a given data.frame that already has cross table format. It uses the columns specified in sub_table_cols to separate the table body into several sub tables, where each sub table has the current value in the column defined by sub_table_cols as sub heading. The columns specified in y_cols_left, x_cols and value_cols define the cross table structure. The data.frame given in data has already s If the table should not be a cross table, but a normal table then the arguments x_cols and value_cols should be omitted. The function is a recursive function that builds that subTables from inside out.

Usage

create_sub_table(
  data,
  sub_level,
  sub_table_cols,
  sub_heading_stylings = NULL,
  body_styling = NULL,
  y_cols_left,
  y_cols_right
)

Arguments

data

A data.frame that should be used for the creation of the cross table.

sub_level

This is the recursive counter that gives the deepness of the recursive function execution. It points to the current sub heading level. So sub_level == 1 means that we look at the sub headings given by the different values in the data.frame column that has the name given in sub_table_cols\[1\].

sub_table_cols

(optional) A vector of column names that should be used in order to separate the data.frame into several sub tables, that will be concatenated vertically. Each sub table will have a sub heading row above the sub table body. The sub heading text is just the corresponding value in the column defined by sub_table_cols. If no sub heading should be introduced at all, the argument sub_table_cols should be omitted. If the sub_table_cols is vector with more than one column name, then a hirachy level is introduced for the sub headings, where the first column has the highest and the column given by the last entry in sub_table_cols has the lowest hirachy level.

sub_heading_stylings

(optional) A list of styling functions. A styling function is a function that takes a StyledTable object as its only argument and returns a styled function. The first styling function is applied to the level-1 sub heading (the sub heading defined by the first entry in sub_table_cols), the second styling function is applied to the level-2 sub heading etc. Alternatively a single styling function can be passed into sub_heading_stylings, in this case this styling function is applied to all sub heading levels.

body_styling

(optional) A styling function that is applied to the generated styled body of each sub table. A styling function is a function that takes a StyledTable object as its only argument and returns a styled function. In order to format the value columns of the resulting cross table use the argument value_col_stylings.

y_cols_left

A vector of column names that are unchanged by the cross table compuation. If the table should not be a cross table, but a normal table this argument can be omitted.

y_cols_right

A vector of column names that are unchanged by the cross table compuation. This columns are of the same kind as the columns defined by the argument y_cols_left, but aligned to the right of the generated cross table.


R-package/styledTables documentation built on Feb. 6, 2024, 2:21 a.m.