[英]Print arguments of a function in R
Is it possible to print the arguments of a function? 是否可以打印函数的参数?
Example, this is my function: 例子,这是我的功能:
my_function <- function(argument_1, argument_2){
my_equation <- argument_1 + argument_2
return(my_equation)
}
And i run it with this code: 我用以下代码运行它:
my_save <- my_function(argument_1=1, argument_2=123)
Is it possible to write something like this GET.MY.FUNCTION.PARAMETERS(my_save)
which would return a vector or list with 1, 123
是否可以编写类似
GET.MY.FUNCTION.PARAMETERS(my_save)
东西,该向量将返回带有1, 123
或1, 123
的向量或列表
A quick way to do this is to pass the arguments back in return
as part of a list: 一个快速的方法来做到这一点是通过参数重新
return
为一个列表的一部分:
my_function <- function(argument_1, argument_2){
my_equation <- argument_1 + argument_2
return(list(eqn = my_equation, arg1 = argument_1, arg2 = argument_2))
}
So that you can assign an output: 这样您就可以分配输出:
results <- my_function(foo1, foo2)
and then strip the information you need: 然后剥离您需要的信息:
eqn <- results$eqn
args <- with(results, c(arg1, arg2))
print(args)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.