Reputation: 69
I would like to extract a set of values for a specific argument of a function.
To demonstrate the problem, I have a function
myFUN <- function (x, y, method = c("top", "down", "left", "right")) {}
and I would like to extract the values "top", "down", "left", "right" from the argument 'method'.
I have been able to extract the argument with args
or match.call
as.list(args(myFUN))$method
which returns, literally the string c("top", "down", "left", "right")
.
How do I get now all the values between the double quotes "
? Can I parse somehow the string c("top", "down", "left", "right")
into a variable as a vector, to get "top", "down", "left", "right"
?
or is there a better way of extracting the argument from a function?
Upvotes: 0
Views: 77
Reputation: 39667
You can use eval
to get the vector.
eval(formals(myFUN)$method)
#eval(as.list(args(myFUN))$method) #Alternative
#[1] "top" "down" "left" "right"
Upvotes: 1