Description Usage Arguments Details Author(s)
Partially apply arguments to a function, reducing the number of arguments it takes, or setting them as defaults.
1 | partially_apply(f, ..., set_as_defaults = FALSE)
|
f |
A function |
... |
Named arguments to set |
set_as_defaults |
Should values in |
There are two strategies. In the default, with
set_as_defaults=FALSE
, we assign all supplied values into a
new environment that is placed ahead of the function's native
environment: the supplied values will be found first. The
returned function will have an argument list that omits the given
arguments.
In the second, with set_as_defaults=TRUE
, we set the
supplied values as defaults in the function's argument list. The
returned function's argument list still includes the given
arguments, but they are all moved after the unset values,
and kept in the order provided. If the function contains
...
as an argument, then these values will be put
after the ellipsis, which means partial name matching won't
work (don't use it anyway!).
Both strategies seem to offer similar performance. I suspect that
the set_as_defaults=TRUE
strategy is a little more fragile.
They differ mainly in how the function is intended to be used - if
you want to forever specify particular values for a value, use
set_as_defaults=FALSE
. If you want to generate new
function that you might sometimes want to use different values in,
use set_as_defaults=TRUE
.
Rich FitzJohn
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.