View source: R/call-flexibly.R
call_flexibly | R Documentation |
Programming aid: See details for more information on how to use it.
call_flexibly(
fn,
fn.ns,
fn.ns.sep = "::",
default = list(),
verbose = TRUE,
v.fail = NULL,
v.skip = NULL
)
fn |
Character value. Denotes the function to be called. |
fn.ns |
Character value. Denotes the namespace/package from which to call fn. |
default |
A named list of arguments that can not be specified by the user. |
verbose |
Logical. If set to TRUE informative messages regarding the computational progress will be printed. (Warning messages will always be printed.) |
v.fail |
The return value in case the function call results in an error. |
v.skip |
The return value in case of |
This function takes two strings as input denoting
the function to be called and the namespace from which it is to be called. It expects
an object of the same name as fn to be in it's calling environment specified with an identically named
argument from the user of the function from which call_flexibly()
is called.
If that object is a list all named elements of that list are considered to be arguments with
which function fn is to be called (= specified list). The names of that list are compared to the names
of default_list
. Arguments specified in the default list can not be altered and are discarded from
the specified list with an informative warning. Subsequently the names of all remaining arguments are compared
to the valid arguments of the function to be called and discarded if unused arguments appear in order to
prevent the function call from failing. (This does not happen if the function to be called uses the dot-product '...').
If that object is a single TRUE the fn
is called with default_list
as input.
If that object is anything else the function call is skipped.
The return value of fn.
# Not run:
example_fun <- function(plot, runif){
call_flexibly(fn = "plot",
fn.ns = "base",
default_list = list(x = 1:10),
v.fail = "This failed.",
v.skip = "Okey, I skip that."
)
call_flexibly(fn = "runif",
fn.ns = "stats",
default_list = list(n = 100),
v.fail = "This failed.",
v.skip = 1:100)
}
# call the function
example_fun(plot = list(y = 1:10, cex = 5, col = "red"), runif = list(max = 100, min = 1))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.