我有以下数据框和变量名称"foo"
;
> foo <-c(3,4);
Run Code Online (Sandbox Code Playgroud)
我想要做的是转换"foo"
成一个字符串.所以在函数中我不必重新创建另一个额外的变量:
output <- myfunc(foo)
myfunc <- function(v1) {
# do something with v1
# so that it prints "FOO" when
# this function is called
#
# instead of the values (3,4)
return ()
}
Run Code Online (Sandbox Code Playgroud)
Sve*_*ein 205
您可以使用deparse
和substitute
获取函数参数的名称:
myfunc <- function(v1) {
deparse(substitute(v1))
}
myfunc(foo)
[1] "foo"
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
82952 次 |
最近记录: |