formatCode | R Documentation |
Turn unevaluated shinymeta expressions into (formatted or styled) text.
formatCode(code, width = 500L, formatter = styleText, ...)
styleText(code, ...)
deparseCode(code, width = 500L)
code |
Either an unevaluated expression or a deparsed code string. |
width |
The |
formatter |
a function that accepts deparsed code (a character string) as the first argument. |
... |
arguments passed along to the |
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:
Pipe operators (%>%
) are always followed by a line break.
If the token appearing after a line-break is a comma/operator, the line-break is removed.
Single-element character vector with formatted code
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.