hasArg {methods} | R Documentation |
Returns TRUE
if name
corresponds to an argument in the
call, either a formal argument to the function, or a component of
...
, and FALSE
otherwise.
hasArg(name)
name |
The name of a potential argument, as an unquoted name or character string. |
The expression hasArg(x)
, for example, is similar to
!missing(x)
, with two exceptions. First, hasArg
will look for
an argument named x
in the call if x
is not a formal
argument to the calling function, but ...
is. Second,
hasArg
never generates an error if given a name as an argument,
whereas missing(x)
generates an error if x
is not a
formal argument.
Always TRUE
or FALSE
as described above.
ftest <- function(x1, ...) c(hasArg(x1), hasArg("y2")) ftest(1) ## c(TRUE, FALSE) ftest(1, 2) ## c(TRUE, FALSE) ftest(y2 = 2) ## c(FALSE, TRUE) ftest(y = 2) ## c(FALSE, FALSE) (no partial matching) ftest(y2 = 2, x = 1) ## c(TRUE, TRUE) partial match x1