Skip to contents

Extracts and returns statistics from a tbl_summary() object for inline reporting in an R markdown document. Detailed examples in the inline_text vignette

Usage

# S3 method for class 'tbl_summary'
inline_text(
  x,
  variable,
  column = NULL,
  level = NULL,
  pattern = NULL,
  pvalue_fun = label_style_pvalue(prepend_p = TRUE),
  ...
)

# S3 method for class 'tbl_svysummary'
inline_text(
  x,
  variable,
  column = NULL,
  level = NULL,
  pattern = NULL,
  pvalue_fun = label_style_pvalue(prepend_p = TRUE),
  ...
)

Arguments

x

(tbl_summary)
Object created from tbl_summary() or tbl_svysummary()

variable

(tidy-select)
A single variable name of statistic to present

column

(tidy-select)
Column name to return from x$table_body. Can also pass the level of a by variable.

level

(string)
Level of the variable to display for categorical variables. Default is NULL

pattern

(string)
String indicating the statistics to return. Uses glue::glue() formatting. Default is NULL

pvalue_fun

(function)
Function to round and format p-values. Default is label_style_pvalue(). The function must have a numeric vector input, and return a string that is the rounded/formatted p-value (e.g. pvalue_fun = label_style_pvalue(digits = 2)).

...

These dots are for future extensions and must be empty.

Value

A string reporting results from a gtsummary table

Author

Daniel D. Sjoberg

Examples

t1 <- trial |>
  tbl_summary(by = trt, include = grade) |>
  add_p()

inline_text(t1, variable = grade, level = "I", column = "Drug A", pattern = "{n}/{N} ({p}%)")
#> 35/98 (36%)
inline_text(t1, variable = grade, column = "p.value")
#> [1] "p=0.9"