hasArg {methods} | R Documentation

## Look for an Argument in the Call

### Description

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.

### Usage

    hasArg(name)

### Arguments

`name` | The name of a potential argument, as an unquoted name or character string.

### Details

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.

### Value

Always `TRUE` or `FALSE` as described above.

### See Also

`missing`

### Examples

    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

[Package methods version 3.5.1 Index]