adorn_tidytableone: Format tidytableone for display and reporting

View source: R/adorn-tidytableone.R

adorn_tidytableoneR Documentation

Format tidytableone for display and reporting

Description

Take the raw summary statistics from create_tidy_table_one and format them for inclusion in a presentable table.

Usage

adorn_tidytableone(
  tidy_t1,
  default_continuous = "{mean} ({sd})",
  default_categorical = "{n} ({p})",
  fmt_vars = NULL,
  con_accuracy = 0.1,
  cat_accuracy = 0.1,
  p_accuracy = 0.001,
  prefix = "",
  suffix = "",
  big_mark = "",
  decimal_mark = ".",
  style_positive = c("none", "plus"),
  style_negative = c("hyphen", "minus", "parens"),
  scale_cut = NULL,
  con_trim = TRUE,
  cat_trim = FALSE,
  show_pct = TRUE,
  exact = NULL,
  nonnormal = NULL,
  equal_variance = NULL,
  no_cont_correction = NULL,
  monte_carlo_p = NULL,
  show_test = FALSE,
  show_smd = FALSE,
  use_labels = TRUE,
  combine_level_col = TRUE,
  missing = "no",
  missing_text = "(Missing)",
  default_miss = "{n}",
  ...
)

Arguments

tidy_t1

Results in a tibble from create_tidy_table_one

default_continuous

A glue statement that provides the formatting for continuous variables, Default is "{mean} ({sd})"

default_categorical

A glue statement that provides the formatting for categorical variables, Default is "{n} ({p})"

fmt_vars

A list of variable names and glue statements to override the defaults for specific variables.

con_accuracy

A number to round to for continuous variables. Use (e.g.) 0.01 to show 2 decimal places of precision. Default is 0.1.

cat_accuracy

A number to round to for categorical variables. Use (e.g.) 0.01 to show 2 decimal places of precision. Default is 0.1.

p_accuracy

A number to round to for p-values and smd (when shown). Use (e.g.) 0.01 to show 2 decimal places of precision. Default is 0.001.

prefix

Additional text to display before the number. The suffix is applied to absolute value before style_positive and style_negative are processed so that prefix = "$" will yield (e.g.) ⁠-$1⁠ and ⁠($1)⁠.

suffix

Additional text to display after the number.

big_mark

Character used between every 3 digits to separate thousands.

decimal_mark

The character to be used to indicate the numeric decimal point.

style_positive

A string that determines the style of positive numbers. See ?scales:number for more information.

style_negative

A string that determines the style of negative numbers. See ?scales:number for more information.

scale_cut

Named numeric vector that allows you to rescale large (or small) numbers and add a prefix. See ?scales:number for more information.

con_trim

Logical, if FALSE, values are right-justified to a common width (see base::format()).

cat_trim

Logical, if FALSE, values are right-justified to a common width (see base::format()).

show_pct

Logical, if FALSE, "%" is omitted from percentages.

exact

String vector of variable names to use exact tests for p-values.

nonnormal

String vector of variable names to use non-parametric tests for p-values.

equal_variance

String vector of variable names to assume equal variance.

no_cont_correction

String vector of variable names to assume continuity correction.

monte_carlo_p

String vector of variable names to simulate p-values.

show_test

Logical, if FALSE, the names of the test are omitted from the table.

show_smd

Logical, if FALSE, Standardized Mean Differences (SMD) are not included.

use_labels

Logical, if TRUE, labels are used instead of variable names.

combine_level_col

Combines the var and level columns into one instead of two. HTML won't recognize the extra spaces when printing, but you can used flextable::padding to indent the right rows in that column later.

missing

Indicates whether to include counts of NA values in the table. Allowed values are "no" (shows a column of number not missing), "ifany" (only display if any NA values), and "always" (includes NA count row for all variables). Default is "no".

missing_text

Character string to use in place of NA when missing is "ifany" or "always". Default is "(Missing)".

default_miss

A glue statement that provides the formatting for missing, Default is "{n}"

...

Additional arguments. Not used.

Value

A tibble

Examples

library(dplyr)

dplyr::glimpse(pbc_mayo)

tab1 <- create_tidy_table_one(data = pbc_mayo,
                              strata = "trt",
                              vars = c("time",
                                       "status",
                                       "age",
                                       "sex",
                                       "ascites",
                                       "hepato",
                                       "spiders",
                                       "edema",
                                       "bili",
                                       "chol",
                                       "albumin",
                                       "copper",
                                       "alk_phos",
                                       "ast",
                                       "trig",
                                       "platelet",
                                       "protime",
                                       "stage"))

dplyr::glimpse(tab1)

# Check to see if assumptions may be violated
check_tests <- calc_table_one_tests(tab1)


dplyr::distinct(tab1, var)


adorn_tidytableone(tidy_t1 = tab1)

adorn_tidytableone(tidy_t1 = tab1,
                   show_test = TRUE)


adorn_tidytableone(tidy_t1 = tab1,
                   show_test = TRUE,
                   exact = "status",
                   nonnormal = check_tests$non_normal_shapiro)

emilelatour/tidytableone documentation built on Jan. 6, 2025, 9:20 a.m.