tostring: Convert an 'rtable' object to a string

tostringR Documentation

Convert an rtable object to a string

Description

Transform a complex object into a string representation ready to be printed or written to a plain-text file

Usage

## S4 method for signature 'VTableTree'
toString(
  x,
  widths = NULL,
  col_gap = 3,
  hsep = horizontal_sep(x),
  indent_size = 2,
  tf_wrap = FALSE,
  max_width = NULL
)

Arguments

x

table object

widths

widths of row.name and columns

col_gap

gap between columns

hsep

character to create line separator

indent_size

numeric(1). Number of spaces to use per indent level. Defaults to 2

tf_wrap

logical(1). Should the texts for title, subtitle, and footnotes be wrapped?

max_width

integer(1), character(1) or NULL. Width that title and footer (including footnotes) materials should be word-wrapped to. If NULL, it is set to the current print width of the session (getOption("width")). If set to "auto", the width of the table (plus any table inset) is used. Ignored completely if tf_wrap is FALSE.

Details

Manual insertion of newlines is not supported when tf_wrap is on and will result in a warning and undefined wrapping behavior. Passing vectors of already split strings remains supported, however in this case each string is word-wrapped separately with the behavior described above.

Value

a string representation of x as it appears when printed.

Examples

library(dplyr)

iris2 <- iris %>%
  group_by(Species) %>%
  mutate(group = as.factor(rep_len(c("a", "b"), length.out = n()))) %>%
  ungroup()

lyt <- basic_table() %>%
  split_cols_by("Species") %>%
  split_cols_by("group") %>%
  analyze(c("Sepal.Length", "Petal.Width"), afun = list_wrap_x(summary) , format = "xx.xx")

tbl <- build_table(lyt, iris2)

cat(toString(tbl, col_gap = 3))

rtables documentation built on Aug. 30, 2023, 5:07 p.m.