get the name of an input in nested function calls

Share:

Description

get the name of an input in nested function calls

Usage

1
getName(x)

Arguments

x

input object name or character string

Value

Character string with the name

Author(s)

http://stackoverflow.com/users/2725969/brodieg Implementation Berry Boessenkool, berry-b@gmx.de, Sep 2016

See Also

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

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
# 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

upper(stackloss[1:5,])

Want to suggest features or report bugs for rdrr.io? Use the GitHub issue tracker.