formatCode {shinymeta}R Documentation

Deparse and format shinymeta expressions

Description

Turn unevaluated shinymeta expressions into (formatted or styled) text.

Usage

formatCode(code, width = 500L, formatter = styleText, ...)

styleText(code, ...)

deparseCode(code, width = 500L)

Arguments

code

Either an unevaluated expression or a deparsed code string.

width

The width.cutoff to use when deparse()-ing the code expression.

formatter

a function that accepts deparsed code (a character string) as the first argument.

...

arguments passed along to the formatter function.

Details

Before any formatting takes place, the unevaluated expression is deparsed into a string via deparseCode(), which ensures that shinymeta comment strings (i.e., literal strings that appear on their own line, and begin with one or more ⁠#⁠ characters.) are turned into comments and superfluous ⁠\{⁠ are removed. After deparsing, the formatCode() function then calls the formatter function on the deparsed string to format (aka style) the code string. The default formatter, styleText(), uses styler::style_text() with a couple differences:

Value

Single-element character vector with formatted code

Examples


options(shiny.suppressMissingContextError = TRUE)

x <- metaReactive({
  "# Here's a comment"
  sample(5) %>% sum()
})

code <- expandChain(x())

deparseCode(code)
formatCode(code)
formatCode(code, formatter = styler::style_text)

[Package shinymeta version 0.2.0.3 Index]