显示函数执行过程中的实际参数列表
我试图显示调用函数时提供的参数的实际值。 `match.call' 按照我想要的方式做了一些事情,但它不评估变量。例如
foo <- function(x) match.call()
foo(2)
印刷品
foo(x = 2)
,我对此很满意。但是:
xxx <- 2
foo(xxx)
将打印
foo(x = xxx)
而不是 foo(x = 2)
因为我想要它。
我尝试了 substitute
、eval
和 company 的各种组合,但没有成功。
I am trying to display the actual values of the parameters that were supplied when the function was called. `match.call' does something along the lines I want but it does not evaluate variables. For example
foo <- function(x) match.call()
foo(2)
prints
foo(x = 2)
and I am happy with that. However:
xxx <- 2
foo(xxx)
will print
foo(x = xxx)
instead of foo(x = 2)
as I would like to have it.
I have tried various combinations of substitute
, eval
, and company, but was not succesful.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不久前编写了一个函数 Expand.call() 来执行您想要的操作(我认为......)。实际上,它的作用还多一点:
如果您需要保留有关调用的更多信息或将其格式化得更好,那么您通常会使用它来代替 match.call(),例如:
也许您可以使用它来解决你的问题。
I wrote a function expand.call() that does what you want (I think...) a while ago. Actually, it does a little more:
You would normally use this as a substitute for match.call() if you need to preserve some some more info about the call or have it formatted more nicely, like:
Maybe you can use it to solve your problem.
我不知道这是否是最好的方法,但也许你可以通过以下方式做到这一点:
I don't know if this is the best way, but probably you can do it by: