spatstat.utils (version 1.13-0)

do.call.matched: 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.

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).

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.

See Also

resolve.defaults, do.call.without.

do.call

Examples

Run this code
# NOT RUN {
  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")
# }

Run the code above in your browser using DataCamp Workspace