repr_ls: Show list as formatted string

View source: R/utils_print.R

repr_lsR Documentation

Show list as formatted string

Description

Works exactly like printls, but instead of printing to console with cat, it outputs a single string, formatted using mformat, so that cat(repr_ls(x)) looks identical to printls(x) for any list x

Usage

repr_ls(
  x,
  prefix = "",
  pad = 2L,
  item_format = bold,
  maxlength = 4L,
  center_title = TRUE,
  title = NULL,
  title_newline = TRUE,
  newline_pre = FALSE,
  format_fn_rhs = ddSci,
  print_class = TRUE,
  abbrev_class_n = 3L,
  print_df = FALSE,
  print_S4 = FALSE,
  limit = 12L,
  output_type = c("ansi", "html", "plain")
)

Arguments

x

list or object that will be converted to a list.

prefix

Character: Optional prefix for names.

pad

Integer: Pad output with this many spaces.

item_format

Formatting function for items.

maxlength

Integer: Maximum length of items to show using headdot() before truncating with ellipsis.

center_title

Logical: If TRUE, autopad title for centering, if present.

title

Character: Title to print before list.

title_newline

Logical: If TRUE, print title on new line.

newline_pre

Logical: If TRUE, print newline before list.

format_fn_rhs

Formatting function for right-hand side of items.

print_class

Logical: If TRUE, print abbreviated class of object.

abbrev_class_n

Integer: Number of characters to abbreviate class names to.

print_df

Logical: If TRUE, print data frame contents, otherwise print n rows and columns.

print_S4

Logical: If TRUE, print S4 object contents, otherwise print class name.

limit

Integer: Maximum number of items to show.

output_type

Character: Output type for mformat ("ansi", "html", "plain").

Details

Exported as internal function for use by other rtemis packages.

Value

Character: Formatted string that can be printed with cat()

Author(s)

EDG

Examples

x <- list(
  a = 1:10,
  b = "Hello",
  c = list(
    d = 1,
    e = 2
  )
)
cat(repr_ls(x, title = "A List"))

rtemis.core documentation built on April 22, 2026, 1:11 a.m.