Description Usage Arguments Details Author(s) Examples
Extract from the function definition its formal arguments. Then from
...
, only use the arguments that are in the formal definition and
drop the rest. This helps avoid conflicts when you are passing arguments
with ...
but is not used by all of the functions you need.
1 | formal_call(fun, ...)
|
fun |
A function to use (the actual function, not the character) |
... |
A set of arguments. Only those matching the formal definition of
|
Some functions are not defined with the ...
argument, and they will
choke if you use them in your functions and pass arguments they are not
using.
L. Collado-Torres
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | ## Lets define a very simple identity function
ident <- function(x) return(x)
## Now lets use it inside another function
maxIdent <- function(x, ...) {
m <- max(x, ...)
y <- ident(m, ...)
return(y)
}
## Seems to work
maxIdent(1:10)
## But not when we actually use '...'
## Not run:
maxIdent(1:10, 11)
## End(Not run)
## Lets now use formal_call() to run ident() only using the arguments it
## has as part of its function definition.
maxIdent2 <- function(x, ...) {
m <- max(x, ...)
y <- formal_call('ident', x = m, ...)
return(y)
}
## Works now =)
maxIdent2(1:10, 11)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.