Learn R Programming

berryFunctions (version 1.12.3)

getName: get the name of an input in nested function calls

Description

get the name of an input in nested function calls

Usage

getName(x)

Arguments

x
input object name or character string

Value

Character string with the name

See Also

http://stackoverflow.com/a/26558733, substitute

Examples

Run this code
# This does not work well:

lower <- function(x) deparse(substitute(x))
upper <- function(y) lower(y)
lower(pi) # returns "pi", as expected
upper(pi) # returns "y".

# That's why there is getName:

getName(pi) # returns "pi", as expected
upper <- function(y) getName(y)
upper(pi) # yay!

upper("dummy")
upper(dummy) # works also for nonexistent objects
dummy <- 7
upper("dummy") # still stable
upper(dummy) # still stable

Run the code above in your browser using DataLab