unwrap | R Documentation |
Given an unforced quotation whose expression is a bare variable
name, unwrap
follows the variable reference, and returns a
quotation. When the argument is forced or has a nontrivial
expression unwrap
has no effect.
unwrap(x, recursive = FALSE)
## S3 method for class 'dots'
unwrap(x, recursive = FALSE)
x |
a quotation to unwrap. |
recursive |
Default |
There are two good use cases for unwrap(x, recursive=TRUE)
. One
is to derive plot labels (the most inoccuous use of
metaprogramming). Another is to check for missingness (this is what
R's missing and does as well).
Using unwrap(x, recursive=TRUE)
in other situations can get you
into confusing situations – effectively you are changing the
behavior of a parent function that may be an unknown number of
levels up the stack, possibly turning a standard-evaluating
function into nonstandard-evaluating function. So recursive
unerapping is not the default behavior.
The quotation method returns a quotation.
The dots method returns a dots object with each quotation unwrapped.
# different levels of unwrapping:
f <- function(x) { g(x) }
g <- function(y) { h(y) }
h <- function(z) {
print(arg(z))
print(unwrap(quo(z)))
print(unwrap(unwrap(quo(z))))
print(unwrap(quo(z), recursive=TRUE))
}
w <- 5
f(w)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.