Title: | Change the Default Arguments in R Functions |
---|---|
Description: | A simple syntax to change the default values for function arguments, whether they are in packages or defined locally. |
Authors: | Nick Golding |
Maintainer: | Nick Golding <[email protected]> |
License: | MIT + file LICENSE |
Version: | 1.0.0 |
Built: | 2024-11-18 05:39:15 UTC |
Source: | https://github.com/goldingn/default |
default()
lets you check, and change, a function's
default arguments. reset_default()
returns the arguments to their
original defaults.
default(fun) default(fun) <- value reset_default(fun)
default(fun) default(fun) <- value reset_default(fun)
fun |
a function |
value |
a named list of new default arguments for that function |
If fun
is a function from a package, a function of the same
name will be defined in the calling environment (e.g. your workspace).
If fun
is defined locally, it will be overwritten by the version
with the new defaults.
reset_default
returns the reset function, rather than
modifying it in place, so you'll need to reassign it, as in the example.
default()
(without assignment) invisibly returns a pairlist of
the current values of the default arguments. It also prints the default
arguments, highlighting those that the user has changed from their original
defaults.
reset_default()
returns the fun
, but with the defaults reset
to their original values. If fun
was a function from a package, the
same thing can be achieved by replacing the locally-defined version of the
function.
# list the default arguments for a function default(data.frame) # change one or more of them default(data.frame) <- list(fix.empty.names = FALSE) data.frame(1:3) # reset the defaults data.frame <- reset_default(data.frame) data.frame(1:3)
# list the default arguments for a function default(data.frame) # change one or more of them default(data.frame) <- list(fix.empty.names = FALSE) data.frame(1:3) # reset the defaults data.frame <- reset_default(data.frame) data.frame(1:3)