modify.args <- function(formals, arglist, ..., dots=FALSE)
{
# avoid evaluating '...' to make things faster
dots.names <- eval(substitute(alist(...)))
if(missing(arglist))
arglist <- NULL
arglist <- c(arglist, dots.names)
# see 'S Programming' p. 67 for this matching
# nothing to do if arglist is empty; return formals
if(!length(arglist))
return(formals)
argnames <- names(arglist)
if(!is.list(arglist) && !is.null(argnames) && !any(argnames == ""))
stop("'arglist' must be a *named* list, with no names == \"\"")
.formals <- formals
onames <- names(.formals)
pm <- pmatch(argnames, onames, nomatch = 0L)
#if(any(pm == 0L))
# message(paste("some arguments stored for", fun, "do not match"))
names(arglist[pm > 0L]) <- onames[pm]
.formals[pm] <- arglist[pm > 0L]
# include all elements from arglist if function formals contain '...'
if(dots && !is.null(.formals$...)) {
dotnames <- names(arglist[pm == 0L])
.formals[dotnames] <- arglist[dotnames]
#.formals$... <- NULL # should we assume we matched them all?
}
.formals
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.