captureExpression: Capture expression

Description Usage Arguments Value Author(s) References See Also Examples

Description

Captures an arbitrary R expression before it is actually evaluated. This might be useful in situations, where you want to delay the evaluation of the expression.

Usage

1
captureExpression(expr, caller_offset = 1, brackets = TRUE)

Arguments

expr

Signature argument. Expression to capture.

caller_offset

numeric. If specified, the offset in the callstack of the expression to be treated as the caller.

brackets

logical. TRUE: ensure that resulting expression is wrapped inside curly brackets ({}); FALSE: expression returned exactly as captured.

...

Further arguments to be passed to subsequent functions/methods.

Value

curly brackets call (can't write out the actual code in roxygen) if brackets = TRUE, else class of evaluated expression.

Author(s)

Janko Thyson janko.thyson@rappster.de

References

http://github.com/Rappster/yamlr

See Also

substitute, parent.frame

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
## Not run: 

## Expression wrapped in curly brackets //  
res <- captureExpression({
  "object-ref: {id: x_1}"
  x_2 * 2
})
res
class(res)
inherits(res, "call")

## Expression w/o curly brackets //
res <- captureExpression(x_2 * 2)
res
class(res)

res <- captureExpression(x_2 * 2, brackets = FALSE)
res
class(res)

## Character //
res <- captureExpression("object-ref: {id: x_1}")
res
class(res)

res <- captureExpression("object-ref: {id: x_1}", brackets = FALSE)
res
class(res)


## End(Not run)

rappster/yamlr documentation built on May 27, 2019, 2:02 a.m.