scripted.default {yamlet}R 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).

In addition to the 'title' and 'expression' attributes, scripted() writes a 'plotmath' attribute to store plotmath versions of factor levels, where present. print.decorated_ggplot should prefer these over their latex and html counterparts. Furthermore, factor levels (and codelists, where present) are converted to their latex or html equivalents. None of this happens if a 'plotmath' attribute already exists, thus preventing the same variable from being accidentally transformed twice.

To flexibly support latex, html, and plotmath, 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). A literal backslash followed by "n" represents a newline. Greek letters are represented by their names, except where names are enclosed in backticks.

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

Value

'scripted', a superclass of 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')
testthat::expect_equal(scripted(x), scripted(scripted(x)))

[Package yamlet version 1.0.3 Index]