Reputation: 7317
Is there a way to "access" all passed arguments in a function? I beleive this can be done i javascript through the arguments array, is there an equivalent in R?
myfunc <- function() {
print(arguments[1])
print(arguments[2])
}
R> myfunc("A","B")
[1] "A"
[1] "B"
Upvotes: 1
Views: 1211
Reputation: 176648
Technically, your function has no arguments, so passing arguments to it is an error.
That said, at minimum you would need ...
. If you do that, you can use list
on ...
and then access the names of your copy of ...
. For example:
myfunc <- function(...) {
names(list(...))
}
Another approach would be to parse the call with match.call
. For example:
myfunc <- function(A, B) {
names(match.call()[-1])
}
Upvotes: 10