append_units.default: Append Units By Default

View source: R/append_units.R

append_units.defaultR Documentation

Append Units By Default

Description

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

Value

same class as x, with sub-class 'latex' or 'plotmath' depending on style

See Also

Other labels: alias.data.frame(), append_units.data.frame(), append_units(), drop_title.decorated(), drop_title.default(), drop_title.dvec(), drop_title(), make_title.decorated(), make_title.default(), make_title.dvec(), make_title(), sub_units()

Examples

library(units)
library(magrittr)
x <- 1:10
attr(x, 'label') <- 'acceleration'
units(x) <- 'm/s^2'
y <- as_units('kg')
x %>% attr('label')
x %>% append_units %>% attr('label')
y %>% attr('label')
y %>% append_units %>% attr('label')
x %>% append_units(style = 'plain')
x %>% append_units(style = 'plotmath')
x %>% append_units(style = 'latex')



yamlet documentation built on Oct. 6, 2023, 9:07 a.m.