asVarName {CodeDepends} | R Documentation |
This function grabs a symbol out of an expression and returns it as a character (see details for which symbol will be used).
This is a convenience function for use when constructing custom function handlers, it's unlikely to have much utility outside of that context.
asVarName(x)
x |
The (sub)expression to extract a symbol from |
This function always returns a character vector representing a single
symbol from x
, but which code varies depending on the exact form
of x
. When
x
is a single symbolthe character representation of the symbol is returned
x
is a function callasVarName is recursively called on
the sub-expression for the first argument
x
is an assignmentasVarName is called recursively on the
right-hand side (after ->
expressions are transformed to
<-
ones). This is a special case of the rule above.
A character vector of length one representing the symbol (or literal) as described in the Details section.
Duncan Temple Lang
asVarName(quote(rnorm(x, y, z))) # "x" asVarName(quote(rnorm(x, y, z))[[1]] ) # "rnorm" b/c [[1]] is called fun asVarName(quote(rownames(a) <- b )) # "a" asVarName(quote(rnorm(10, y, z))) # "10"