如何通过R中的包装函数传递函数及其参数?类似于 python 中的 *args 和 *kwargs [英] How to pass a function and its arguments through a wrapper function in R? Similar to *args and *kwargs in python
本文介绍了如何通过R中的包装函数传递函数及其参数?类似于 python 中的 *args 和 *kwargs的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想用 R 编写一个包装函数.我应该接受一个函数及其参数.做一些事情,然后使用提供的参数调用函数.
I want to write a wrapper function in R. I should take a function and its arguments. Do something, and then call the function with the supplied arguments.
我知道如何在 python 中实现,但我在 R 中搜索实现.在python中我会写:
I know how to do it in python, but I search for an implementation in R. In python I would write:
def wrapper(func, *args, **kwargs):
#do something here
return func(*args, **kwargs)
推荐答案
wrapper <- function(func, ...) {
func(...)
}
这篇关于如何通过R中的包装函数传递函数及其参数?类似于 python 中的 *args 和 *kwargs的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文