ft_generate_tbls: Iteratively generate tables for 'Feeling Thermometer'...

View source: R/ft_generate_tbls.R

ft_generate_tblsR Documentation

Iteratively generate tables for 'Feeling Thermometer' variables

Description

This function provides a wrapper around ft_generate_xtab(), ft_generate_xtab_3way(), and ft_generate_topline() (all internal), 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

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

Arguments

l

A list of arguments to be passed on to either ft_generate_xtab(), ft_generate_xtab_3way() or ft_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

ft_generate_xtab(), ft_generate_xtab_3way(), and ft_generate_topline() for single 'Feeling Thermometer' crosstab or topline generations.

Examples


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

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

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


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