scripted.default: Render Scripted Attributes of Indicated Components by Default

View source: R/scripted.R

scripted.defaultR Documentation

Render Scripted Attributes of Indicated Components by Default

Description

Modifies specific attributes of each indicated element (all elements by default).

Usage

## Default S3 method:
scripted(
  x,
  ...,
  open = getOption("yamlet_append_units_open", " ("),
  close = getOption("yamlet_append_units_close", ")"),
  format = getOption("yamlet_format", ifelse(knitr::is_latex_output(), "latex", "html"))
)

Arguments

x

object

...

indicated columns, or name-value pairs; passed to resolve and selected

open

character to precede units

close

character to follow units

format

one of 'latex' or 'html'

Details

The goal here is to render labels and units (where present) in a way that supports subscripts and superscripts for both plots and tables in either html or latex contexts.

The current implementation writes an expression attribute to support figure labels and a title attribute to support tables. print.decorated_ggplot will attempt to honor the expression attribute if it exists. tablet.data.frame will attempt to honor the title attribute if it exists (see Details there). An attempt is made to guess the output format (html or latex).

To flexibly support plotmath, html, and latex, this function expects column labels and units to be encoded in "spork" syntax. See as_spork for details and examples. Briefly, "_" precedes a subscript, "^" precedes a superscript, and "." is used to force the termination of either a superscript or a subscript where necessary. For best results, units should be written using *, /, and ^; e.g. "kg*m^2/s^2" not "kg m2 s-2" (although both are valid: see is_parseable).

scripted() always calls resolve() for the indicated columns, to make units present where appropriate.

Value

same class as x

See Also

Other scripted: scripted()

Other interface: canonical.decorated(), classified.data.frame(), decorate.character(), decorate.data.frame(), desolve.decorated(), ggplot.decorated(), io_csv.character(), io_csv.data.frame(), io_res.character(), io_res.decorated(), io_table.character(), io_table.data.frame(), io_yamlet.character(), io_yamlet.data.frame(), is_parseable.default(), mimic.default(), modify.default(), promote.list(), read_yamlet(), resolve.decorated(), selected.default(), write_yamlet()

Examples

library(magrittr)
library(ggplot2)
x <- data.frame(time = 1:10, work = (1:10)^1.5)
x %<>% decorate('
  time: [ Time_elapsed, h ]
  work: [ Work_total_observed, kg*m^2/s^2 ]
')

x %>% decorations
x %>% ggplot(aes(time, work)) + geom_point()
x %>% scripted %>% ggplot(aes(time, work)) + geom_point()
x %>% scripted(format = 'html') %$% work %>% attr('title')

bergsmat/yamlet documentation built on Feb. 18, 2024, 5:50 a.m.