I am trying to create a function, and I want to be able to get the names of my arguments , and I used formalArgs (I found it as answer to a question like mine) for that but I don't get what I want (I even tried formals()).
This is my function
entropy= function(...)
{
rest of the code
print(formalArgs(entropy))
}
when I call the function entropy(h1,h2,h3) the formalArgs prints
$...
but I want to be able to get
h1,h2,h3
is there a way to do that ? thanks :)
Use substitute() to fetch the unaltered input and deparse it.
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"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.