Transform a complex object into a string representation ready to be printed or written to a plain-text file.
All objects that are printed to console pass via toString. This function allows
fundamental formatting specifications to be applied to final output, like column widths
and relative wrapping (width), title and footer wrapping (tf_wrap = TRUE and
max_width), and horizontal separator character (e.g. hsep = "+").
toString(x, ...)# S4 method for MatrixPrintForm
toString(
x,
widths = NULL,
tf_wrap = FALSE,
max_width = NULL,
col_gap = mf_colgap(x),
hsep = NULL,
fontspec = font_spec(),
ttype_ok = FALSE,
round_type = obj_round_type(x)
)
A character string containing the ASCII rendering of the table-like object represented by x.
(ANY)
object to be prepared for rendering.
additional parameters passed to individual methods.
(numeric or NULL)
Proposed widths for the columns of x. The expected
length of this numeric vector can be retrieved with ncol(x) + 1 as the column of row names
must also be considered.
(flag)
whether the text for title, subtitles, and footnotes should be wrapped.
(integer(1), string 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. Parameter is ignored if tf_wrap = FALSE.
(numeric(1))
space (in characters) between columns.
(string)
character to repeat to create header/body separator line. If
NULL, the object value will be used. If " ", an empty separator will be printed. See
default_hsep() for more information.
(font_spec)
a font_spec object specifying the font information to use for
calculating string widths and heights, as returned by font_spec().
(logical(1))
should truetype (non-monospace) fonts be
allowed via fontspec. Defaults to FALSE. This parameter is primarily
for internal testing and generally should not be set by end users.
(string)
The type of rounding to perform. Allowed values: ("iec", "iec_mod" or "sas")
See round_fmt() for details.
Manual insertion of newlines is not supported when tf_wrap = TRUE 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.
wrap_string()
mform <- basic_matrix_form(mtcars)
cat(toString(mform))
Run the code above in your browser using DataLab