setDefaults             package:Defaults             R Documentation

_C_r_e_a_t_e _G_l_o_b_a_l _D_e_f_a_u_l_t_s _L_i_s_t _B_y _F_u_n_c_t_i_o_n

_D_e_s_c_r_i_p_t_i_o_n:

     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.

_U_s_a_g_e:

     setDefaults(.name,...)
     unsetDefaults(name, confirm=TRUE)

_A_r_g_u_m_e_n_t_s:

   .name: name of function, quoted or unquoted 

    name: name of function, quoted or unquoted 

     ...: name=value default pairs 

 confirm: prompt before unsetting defaults 

_D_e_t_a_i_l_s:

     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.

_V_a_l_u_e:

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

_N_o_t_e:

     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'

_A_u_t_h_o_r(_s):

     Jeffrey A. Ryan

_S_e_e _A_l_s_o:

     'options', 'getDefaults', 'useDefaults',

_E_x_a_m_p_l_e_s:

     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)
     my.fun

     my.fun()            #returns 8
     my.fun(y=10)        #returns 1024
     my.fun(x=2,y=10)    #returns 1024

     unDefaults(my.fun)
     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)

