我正在尝试创建一个函数,我希望能够得到我的参数的名称,并且我使用formalArgs(我发现它像我一样的问题的答案)但是我没有得到我想要的东西(我甚至尝试过formals())。
这是我的功能
entropy= function(...)
{
rest of the code
print(formalArgs(entropy))
}
当我调用函数entropy(h1,h2,h3)时 formalArgs打印
$...
但我希望能够获得
h1,h2,h3
有办法吗? 谢谢:)
答案 0 :(得分:0)
使用substitute()获取未更改的输入并将其解析。
entropy= function(h1,h2,h3)
{
#rest of the code
print(c( deparse(substitute(h1)), deparse(substitute(h2)), deparse(substitute(h3))))
}
entropy(a,b,c)
#[1] "a" "b" "c"