setDefaults: Create Global Defaults List By Function

Description Usage Arguments Details Value Note Author(s) See Also Examples

Description

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.

Usage

1
2

Arguments

.name

name of function, quoted or unquoted

name

name of function, quoted or unquoted

...

name=value default pairs

confirm

prompt before unsetting defaults

Details

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.

Value

None. Called for it's side effect of setting a list of Default arguments by function.

Note

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

Author(s)

Jeffrey A. Ryan

See Also

options, getDefaults, useDefaults,

Examples

 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)

joshuaulrich/Defaults documentation built on May 19, 2019, 8:54 p.m.