Learn R Programming

tinsel (version 0.0.1)

source_decoratees: Read and Parse Decoratees from a File

Description

Given a file, source_decoratees reads and parses decorated functions (decoratees) into the calling environment.

Usage

source_decoratees(file)

Arguments

file
A character string specifying a file path.

Details

Malformed decoratees are ignored and a message will alert the user a function has been skipped. However, an error is raised if a decorator is undefined.

If you are working within RStudio the "Source Active File Decoratees" addin effectively allows you to bind source_decoratees to a keyboard shorcut. The addin is found under Tools > Addins.

Examples

Run this code
# source example files
source_decoratees(tinsel_example('attributes.R'))
source_decoratees(tinsel_example('tags.R'))

# the important thing is to look at the contents
# of the example files, note the use of the special
# "#." comment
writeLines(readLines(tinsel_example('attributes.R')))
writeLines(readLines(tinsel_example('tags.R')))

# the decorator functions are not sourced,
exists('attribute')  # FALSE
exists('html_wrap')  # FALSE

# only decorated functions are sourced
print(selector1)
selector1(mtcars, 'mpg')

# format with bold tags
html_bold('make this bold')

# format with paragraph tags
html_paragraph("I'll make my report as if I told a story...")

Run the code above in your browser using DataLab