【发布时间】:2023-03-05 05:33:01
【问题描述】:
我正在尝试找到一种在函数中使用向量名称而不是其值的方法。
a_vector <- 1:20
testFun <- function(x = a_vector) {
# Function should return "a_vector" and not 1:20
}
这类似于 plot() 默认为 xlab 使用的 xlab,它使用 x 的描述。
非常感谢您的帮助。
【问题讨论】:
标签: r
我正在尝试找到一种在函数中使用向量名称而不是其值的方法。
a_vector <- 1:20
testFun <- function(x = a_vector) {
# Function should return "a_vector" and not 1:20
}
这类似于 plot() 默认为 xlab 使用的 xlab,它使用 x 的描述。
非常感谢您的帮助。
【问题讨论】:
标签: r
我们可以使用deparse/substitute
testFun <- function(x = a_vector) {
deparse(substitute(x))
}
testFun()
#[1] "a_vector"
【讨论】: