extract_metadata: Extract docstring and meta data from an anonymous function

Description Usage Arguments Value Examples

View source: R/metadata.R

Description

Currently the docstring must come first and the metadata list must come second. Both must precede any other code in the function. These constraints may be relaxed in the future.

Usage

1
extract_metadata(expr, env = parent.frame(), skip_name = TRUE)

Arguments

expr

an expression with an optional docstring as the first statement

env

Environment in which to search for functions

skip_name

Do not attempt to find function matching expressions of type 'name'. If FALSE, then a function will by searched for with name expr if expr is a name. This leads to expr being evaluated, which raises errors outside the purview of Rmonad. For example, extract_metadata(stop("dying")).

Value

a list of three elements, the expression with the docstring and metadata removed, the docstring itself, and the metadata.

Examples

1
2
3
4
5
6
7
8
9
## extract metadata from a block 
expr <- substitute(
  {
    "this is the docstring"
    list(foo="this is meta data")
    5 * 32
  }
)
extract_metadata(expr)

rmonad documentation built on March 26, 2020, 7:31 p.m.