Units attribute is wrapped in open and
close, and appended to label.
Result is assigned to target attribute
(default: 'label').
If style is 'latex' or 'plotmath',
all elements are treated as spork
(as_spork) and coerced
to canonical form before concatenation.
Usage
# Default S3 method
append_units(
x,
...,
open = getOption("yamlet_append_units_open", " ("),
close = getOption("yamlet_append_units_close", ")"),
style = getOption("yamlet_append_units_style", "plain"),
target = getOption("yamlet_append_units_target", "label")
)Arguments
- x
object
- ...
passed to
as_latex,as_plotmath- open
character to precede units
- close
character to follow units
- style
one of 'plain', 'latex', or 'plotmath'
- target
attribute name for appended result
Examples
library(units)
#> udunits database from /usr/share/xml/udunits/udunits2.xml
library(magrittr)
x <- 1:10
attr(x, 'label') <- 'acceleration'
units(x) <- 'm/s^2'
y <- as_units('kg')
x %>% attr('label')
#> [1] "acceleration"
x %>% append_units %>% attr('label')
#> [1] "acceleration (m/s^2)"
y %>% attr('label')
#> NULL
y %>% append_units %>% attr('label')
#> [1] " (kg)"
x %>% append_units(style = 'plain')
#> Units: [m/s^2]
#> [1] 1 2 3 4 5 6 7 8 9 10
#> attr(,"label")
#> [1] "acceleration (m/s^2)"
x %>% append_units(style = 'plotmath')
#> Units: [m/s^2]
#> [1] 1 2 3 4 5 6 7 8 9 10
#> attr(,"label")
#> expression("acceleration" * " " * "(m/s"^{
#> "2"
#> } * ")")
x %>% append_units(style = 'latex')
#> Units: [m/s^2]
#> [1] 1 2 3 4 5 6 7 8 9 10
#> attr(,"label")
#> [1] "\\(\\mathrm{\\textrm{acceleration} \\textrm{ } \\textrm{(m/s}{}^{\\textrm{\\scriptsize 2}} \\textrm{)}}\\)"
#> attr(,"class")
#> [1] "latex" "character"