是否可以从...中删除一个元素并将...传递给其他功能?我的前两次尝试失败了:
parent = function(...)
{
a = list(...)
str(a)
a$toRemove = NULL
str(a)
# attempt 1
child(a)
# attempt 2
child( ... = a )
}
child = function(...)
{
a = list( ... )
str(a)
}
parent( a = 1 , toRemove = 2 )
编辑
对不起混乱。我修复了 child()。目的是让孩子列出...的内容
Edit2
这里更多的是一个真实世界的例子(但仍然相当简单,所以我们可以就它进行有用的对话)。通过递归调用父级。父级需要知道递归调用的深度。parent 之外的调用者不应该知道“深度”,也不应该在调用 parent() 时设置它。Parent 调用其他函数,在本例中为 child()。孩子需要价值......显然孩子不需要“深度”,因为父母生成它是为了自己使用。
parent = function( ... )
{
depth = list(...)$depth
if ( is.null( depth ) )
{
depth = 1
}
print( depth )
# parent needs value of depth to perform various calculations (not shown here)
if ( depth == 5 )
{
return()
}
else
{
# child doesn't need "depth" in ...
child( ... )
}
# yikes! now we've added a second, third, etc. depth value to ...
parent( depth = depth + 1 , ... )
}
child = function(...)
{
# does some magic
}