Reputation: 59597
How to test in R if particular function has argument of given name?
An illustration of what I need:
f <- function (a, b, c)
{
1
}
fun_iam_lookin_for(f, "b") # should return TRUE
fun_iam_lookin_for(f, "d") # should return FALSE
Upvotes: 0
Views: 83
Reputation: 174606
You could try:
f <- function (a, b, c)
{
1
}
fun_iam_lookin_for <- function(f, x) x %in% names(formals(f))
fun_iam_lookin_for(f, "b") # should return TRUE
#> [1] TRUE
fun_iam_lookin_for(f, "d") # should return FALSE
#> [1] FALSE
Created on 2020-05-06 by the reprex package (v0.3.0)
Upvotes: 1