How to get name of variable in R (substitute)?

后端 未结 3 1103
攒了一身酷
攒了一身酷 2020-12-03 05:42

I stacked with trying to pass variable through few functions, and on the final function I want to get the name of the original variable. But it seems like substitute functio

3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-03 05:52

    One hack, probably not the best way:

    fun2 <- function (var_pass) { fun1 (deparse(substitute(var_pass))) }
    
    fun1 <- function (some_variable) {(some_variable))}
    
    fun2(my_var)
    # "my_var"
    

    And you could run get on that. But as Paul H, suggests, there are better ways to track variables.

提交回复
热议问题