【发布时间】:2010-08-09 16:37:36
【问题描述】:
如果我想知道 R 函数中 ... 参数中存储的内容,我可以简单地将其转换为列表,就像这样
foo <- function(...)
{
dots <- list(...)
print(dots)
}
foo(x = 1, 2, "three")
#$x
#[1] 1
#
#[[2]]
#[1] 2
#
#[[3]]
#[1] "three"
我不知道如何在调用函数中评估...。在下一个示例中,我希望 baz 的内容将 ... 参数返回给 bar。
bar <- function(...)
{
baz()
}
baz <- function()
{
# What should dots be assigned as?
# I tried
# dots <- get("...", envir = parent.frame())
# and variations of
# dots <- eval(list(...), envir = parent.frame())
print(dots)
}
bar(x = 1, 2, "three")
get("...", envir = parent.frame()) 返回<...>,看起来很有希望,但我不知道如何从中提取任何有用的东西。
eval(list(...), envir = parent.frame()) 抛出错误,声称... 使用不当。
如何从bar 检索...?
【问题讨论】:
标签: r environment callstack