如何在 R 中创建包含空元素的配对列表?
在 R 中,当我这样做时
substitute(function(a) { a })[[2]]
,我会看到以下对列表:
$a
请注意,元素的值为空。我怎样才能创建这样的配对列表?以下对我不起作用:
> pairlist(a="")
$a
[1] ""
我在以编程方式创建函数的上下文中询问这个问题。我想做类似的事情,
> call("function", pairlist(a=""), call("{", as.symbol("a")))
function(a = "") {
a
}
这与我所做的非常接近。
> substitute(function(a){a})
function(a) {
a
}
除了函数参数部分之外,
In R, when I do
substitute(function(a) { a })[[2]]
I see the following pairlist:
$a
Note that the value of the element is empty. How can I create such a pairlist? The following doesn't work for me :
> pairlist(a="")
$a
[1] ""
I am asking this in the context of programmatically creating a function. I want to do something like
> call("function", pairlist(a=""), call("{", as.symbol("a")))
function(a = "") {
a
}
This is quite close to what I get by doing
> substitute(function(a){a})
function(a) {
a
}
except for the function argument part.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
试试这个:
也许你想做的是:
try this:
maybe what you want to do is:
使用
alist(a=)
。您可能还会发现函数
formals
和body
对于以编程方式创建函数很有帮助,而不是substitute
和call
。这是文档?formals
中的一个示例,可以像这样扩展
With
alist(a=)
.You may also find the functions
formals
andbody
helpful in programatically creating a function, rather thansubstitute
andcall
. Here's an example from the documentation?formals
which could be extended like this