Skip to contents

format() encodes text as plain text unless its caller names another output type, so that files, snapshots, and paste() receive no markup. print() writes the output type that r8output_type() determines. The text of an R8 value is its type's Display impl's, or its default layout (r8layout()); a Print impl replaces the output of print(), and a Debug impl the output of str(). The default str() adds to the size of a Rust-stored value the fields read into R that are not views of its state, which together make r8size(x): <pkgr::Signal> 7.63 MiB + 112 B read.

Usage

# S3 method for class 'r8_text'
format(
  x,
  output_type = "plain",
  theme = NULL,
  inline = FALSE,
  html_style = NULL,
  ...
)

# S3 method for class 'r8_text'
print(x, output_type = NULL, theme = NULL, ...)

# S3 method for class 'r8_value'
format(
  x,
  output_type = "plain",
  theme = NULL,
  inline = FALSE,
  html_style = NULL,
  ...
)

# S3 method for class 'r8_value'
print(x, output_type = NULL, theme = NULL, ...)

# S3 method for class 'r8_value'
str(object, ...)

Arguments

x, object

An R8 value or an r8_text object.

output_type

Character: "plain", "ansi", "html", or "markdown"; NULL in print() determines it with r8output_type().

theme

An r8_theme object, or NULL for getOption("r8.theme") or R8's theme.

inline

Logical: markdown writes one line.

html_style

Character or NULL: "inline", which styles each span through its own style attribute, or "classes", which marks spans by class only, for the stylesheet of r8css(), where the theme then applies. NULL reads getOption("r8.html_style"), then "inline"; print(), knitr, and Jupyter read the option. Only for the output type "html".

...

Passed to a Display impl by format(), and to a Print impl by print().

Value

format(): Character, one element per line. print(): x, invisibly. str(): NULL, invisibly.

Examples

GBM <- new_struct("GBM", fields = list(n_trees = type_integer()))
x <- GBM(n_trees = 500L)
format(x)
#> [1] "<global::GBM>"  "  n_trees: 500"
format(x, output_type = "html")
#> [1] "<pre class=\"r8\"><span class=\"r8-line\" data-depth=\"0\"><span class=\"r8-bracket\" style=\"color:var(--r8-bracket,#6CA3A0)\">&lt;</span><span class=\"r8-muted\" style=\"color:var(--r8-muted,#808080)\">global::</span><span class=\"r8-type_name\" style=\"font-weight:bold\">GBM</span><span class=\"r8-bracket\" style=\"color:var(--r8-bracket,#6CA3A0)\">&gt;</span></span>"
#> [2] "<span class=\"r8-line\" data-depth=\"1\">  <span class=\"r8-field_name\">n_trees</span>: <span class=\"r8-scalar\">500</span></span></pre>"                                                                                                                                                                                                                                          
print(x, output_type = "plain")
#> <global::GBM>
#>   n_trees: 500
str(x)
#> <global::GBM>
#>   n_trees: 500