| wrap_string {formatters} | R Documentation |
Wrap a string to a precise width
Description
Core wrapping functionality that preserves whitespace. Newline character "\n" is not supported
by core functionality stringi::stri_wrap(). This is usually solved beforehand by matrix_form().
If the width is smaller than any large word, these will be truncated after width characters. If
the split leaves trailing groups of empty spaces, they will be dropped.
Usage
wrap_string(str, width, collapse = NULL, fontspec = font_spec())
wrap_txt(str, width, collapse = NULL, fontspec = font_spec())
Arguments
str |
( |
width |
( |
collapse |
( |
fontspec |
( |
Details
Word wrapping happens similarly to stringi::stri_wrap() with the following difference: individual
words which are longer than max_width are broken up in a way that fits with other word wrapping.
Value
A string if str is one element and if collapse = NULL. Otherwise, a list of elements
(if length(str) > 1) that can contain strings or vectors of characters (if collapse = NULL).
Functions
-
wrap_txt(): Deprecated function. Please usewrap_string()instead.
Examples
str <- list(
" , something really \\tnot very good", # \t needs to be escaped
" but I keep it12 "
)
wrap_string(str, 5, collapse = "\n")
wrap_txt(str, 5, collapse = NULL)