demo_code: Creates an object of the class 'demo_code'

Description Usage Arguments Value See Also Examples

View source: R/demo_code.R

Description

demo_code objects are evaluated R code, returned from evaluate::evaluate, with an attached attribute called print_string which sets up fancy formatting for knitting.

Usage

1
demo_code(.code_string, eval = TRUE, shatter = TRUE)

Arguments

.code_string

A string containing executable R code OR a valid expression that will be converted to a string via deparse()

eval

A boolean specifying whether the code should be immediately evaluated, in addition to creating the demo_code object. (Defaults to TRUE)

Value

A demo_code object.

See Also

highlight, demo_chunk

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
# When run in console, this will print only the results of mean(1:10)
my_dc <- demo_code('mean(1:10)') %>% hlt_funs()

# The demo_code object itself has no output

my_dc

# However, when knitted, the source code is formatted.

attr(my_dc, "print_string")


# Objects defined in demo_code are created in the environment

demo_code('foo <- mean(1:10)')

foo + 5

kbodwin/demoR documentation built on Nov. 10, 2019, 11:30 p.m.