Description Usage Arguments Details Value Note Author(s) See Also Examples
Create Defaults to be used in place of a function's formal argumenent values.
In conjuction with useDefaults
, or
functions already supporting
importDefaults
, to allow for
user override of formal arguments without specifying
in the function call.
See useDefaults
for the details of
this process.
1 2 | setDefaults(.name,...)
unsetDefaults(name, confirm=TRUE)
|
.name |
name of function, quoted or unquoted |
name |
name of function, quoted or unquoted |
... |
name=value default pairs |
confirm |
prompt before unsetting defaults |
setDefaults is a wrapper to
R options
, allowing the user
to specify any name=value pair that
a function has in it's formal arguments.
Calling setDefaults
on an object
that previously could not process Defaults will
automatically enable defaults via an internal
call to useDefaults
.
Only formal name=value pairs specified will be updated.
Values do not have to be respecified in subsequent calls
to setDefaults
, so it is possible to add
new defaults one at a time for each function, without
having to retype all previous values. Assigning
NULL to any argument will remove the argument from the
Defaults list.
When a function is set to use these Defaults
(using useDefaults
, setDefaults
, or hard-coded
to use the Defaults package)
all non-NULL values set by setDefaults
will effectively replace all formally
specified function defaults.
At present it is not possible to specify NULL as a replacement for a non-NULL default, as the process interprets NULL values as being not set, and will simply use the value specified formally in the function. If NULL is what is desired, it is necessary to include this in the function call itself.
Any arguments included in the actual function
call will take precedence over setDefaults
values, as well as the standard formal function
values. This conforms to the current user
experience in R.
unsetDefaults
does exactly what it says.
None. Called for it's side effect of setting a list of Default arguments by function.
Like options
, settings are NOT
kept across sessions.
Currently, it is NOT possible to pass values for ... arguments, only formally specified arguments in the original function definition.
If it is desired to pass additional arguments,
or more specifically have new defaults, to
subsequent methods/calls, a seperate setDefaults
useDefaults
series is required.
unsetDefaults
removes the all entries from
the options
lists for the specified function, and
then calls unDefaults
. To remove single function Default
values simply set the name of the argument to
NULL in setDefaults
Jeffrey A. Ryan
options
,
getDefaults
,
useDefaults
,
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | my.fun <- function(x=2,y=1) { x ^ y }
my.fun() #returns 2
my.fun(x=2,y=10) #returns 1024
setDefaults(my.fun,x=2,y=3)
#useDefaults(my.fun)# DEFUNCT as of 2.0-0
my.fun
my.fun() #returns 8
my.fun(y=10) #returns 1024
my.fun(x=2,y=10) #returns 1024
#unDefaults(my.fun) # DEFUNCT as of 2.0-0
my.fun
my.fun() #returns 2
getDefaults(my.fun)
setDefaults(my.fun,x=NULL) #removes the value for x, leaving just y
unsetDefaults(my.fun,confirm=FALSE)
getDefaults(my.fun)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.