generate_tbls: Iteratively generate multiple tables

View source: R/generate_tbls.R

generate_tblsR Documentation

Iteratively generate multiple tables

Description

This function provides a wrapper around generate_xtab(), generate_xtab_3way(), and generate_topline(), allowing users to efficiently generate many tables by passing a list of arguments. The shapes of the argument lists may vary depending on the table type.

Usage

generate_tbls(l, df, weight, type = "topline")

Arguments

l

A list of arguments to be passed on to either generate_xtab(), generate_xtab_3way(), or generate_topline():

For toplines
list_topline <- tibble::tribble(
     ~x, ~caption,
     "var_1", "caption1",
     "var_2", "caption2",
     "var_3", "caption3",
     .
     .
     .
  )
For crosstabs
list_xtab <- tibble::tribble(
     ~x, ~y, ~caption,
     "var_1", "var_2", "caption1",
     "var_2", "var_9", "caption2",
     "var_3", "var_23", "caption3",
     .
     .
     .
  )
For three-way crosstabs
list_xtab <- tibble::tribble(
     ~x, ~y, ~z, ~caption,
     "var_1", "var_2", "var_3", "caption1",
     "var_2", "var_9", "var_1", "caption2",
     "var_3", "var_23", "var_17", "caption3",
     .
     .
     .
  )
df

A data frame or tibble.

weight

A length one character vector used as the caption for the topline.

type

Must either be 'topline', 'crosstab_2way', or 'crosstab_3way'. Defaults to 'topline'.

Value

A list containing elements that are list objects, each of which is the source code for a single s3 list object of class flextable.

See Also

generate_xtab(), generate_xtab_3way(), and generate_topline() for single crosstab or topline generations.

Examples


# Generate crosstabs
list_of_xtabs <- generate_tbls(
  l = list_xtab,
  df,
  "weight",
  "crosstab_2way"
)

#' list_of_xtabs <- generate_tbls(
  l = list_xtab,
  df,
  "weight",
  "crosstab_3way"
)

# Generate toplines
list_of_topline <- generate_tbls(
  l = list_topline,
  df,
  "weight",
  "topline"
)


YangWu1227/citizenr documentation built on June 18, 2022, 12:17 p.m.