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,
envir=parent.frame())
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 |
extrargs |
Optional. Character vector giving the names of additional arguments
that can be handled by |
skipargs |
Optional. Character vector giving the names of arguments which should
not be passed to |
matchfirst |
Logical value indicating whether the first entry
of |
sieve |
Logical value indicating whether to return the un-used arguments as well as the result of the function call. See Details. |
envir |
An environment within which to evaluate the call,
if any entries of |
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
.
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")