R: Call a Function, Passing Only Recognised Arguments

do.call.matched {spatstat.utils} | R Documentation

## Call a Function, Passing Only Recognised Arguments

### Description

Call a specified function, using only those arguments which are known to be acceptable to the function.

### Usage

      do.call.matched(fun, arglist, funargs, extrargs = NULL,
                      matchfirst = FALSE, sieve = FALSE, skipargs = NULL)

### Arguments

`fun` | A function, or a character string giving the name of a function, to be called.
`arglist` | A named list of arguments.
`funargs` | Character vector giving the names of arguments that are recognised by `fun`. Defaults to the names of the formal arguments of `fun`.
`extrargs` | Optional. Character vector giving the names of additional arguments that can be handled by `fun`.
`skipargs` | Optional. Character vector giving the names of arguments which should not be passed to `fun`.
`matchfirst` | Logical value indicating whether the first entry of `arglist` is permitted to have an empty name and should be matched to the first argument of `fun`.
`sieve` | Logical value indicating whether to return the un-used arguments as well as the result of the function call. See Details.

### Details

This function is a wrapper for `do.call` which avoids passing arguments that are unrecognised by `fun`.

In the simplest case `do.call.matched(fun, arglist)` is like `do.call(fun, arglist)`, except that entries of `arglist` which do not match any formal argument of `fun` are removed. Extra argument names can be permitted using `extrargs`, and argument names can be forbidden using `skipargs`.

### Value

If `sieve=FALSE` (the default), the result is the return value from `fun`.

If `sieve=TRUE`, the result is a list with entries `result` (the return value from `fun`) and `otherargs` (a list of the arguments that were not passed to `fun`).

### Author(s)

Adrian Baddeley Adrian.Baddeley@curtin.edu.au

### See Also

`resolve.defaults`, `do.call.without`.

`do.call`

### Examples

      f <- function(x=0,y=0, ...) { paste(x, y, ..., sep=", ") }
      f()
      do.call.matched(f, list(y=2))
      do.call.matched(f, list(y=2, z=5), extrargs="z")
      do.call.matched(f, list(y=2, z=5), extrargs="z", skipargs="y")

[Package spatstat.utils version 1.13-0 Index]