EVOLUTION-MANAGER
Edit File: Defaults.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>R: Manage Default Argument Values for quantmod Functions</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="R.css" /> </head><body> <table width="100%" summary="page for Defaults {quantmod}"><tr><td>Defaults {quantmod}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2> Manage Default Argument Values for quantmod Functions </h2> <h3>Description</h3> <p>Use globally specified defaults, if set, in place of formally specified default argument values. Allows user to specify function defaults different than formally supplied values, e.g. to change poorly performing defaults, or satisfy a different preference. </p> <h3>Usage</h3> <pre> setDefaults(name, ...) unsetDefaults(name, confirm = TRUE) getDefaults(name = NULL, arg = NULL) importDefaults(calling.fun) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>name</code></td> <td> <p> name of function, quoted or unquoted (see Details) </p> </td></tr> <tr valign="top"><td><code>...</code></td> <td> <p> name=value default pairs </p> </td></tr> <tr valign="top"><td><code>confirm</code></td> <td> <p> prompt before unsetting defaults </p> </td></tr> <tr valign="top"><td><code>arg</code></td> <td> <p> values to retrieve </p> </td></tr> <tr valign="top"><td><code>calling.fun</code></td> <td> <p> name of function to act upon </p> </td></tr> </table> <h3>Details</h3> <dl> <dt>setDefaults</dt><dd> <p>Provides a wrapper to <span style="font-family: Courier New, Courier; color: #666666;"><b>R</b></span> <code>options</code> that allows the user to specify any name=value pair for a function's formal arguments. Only formal name=value pairs specified will be updated. </p> <p>Values do not have to be respecified in subsequent calls to <code>setDefaults</code>, so it is possible to add new defaults for each function one at a time, without having to retype all previous values. Assigning <code>NULL</code> to any argument will remove the argument from the defaults list. </p> <p><code>name</code> can be an unquoted, bare symbol only at the top-level. It must be a quoted character string if you call <code>setDefaults</code> inside a function. </p> </dd> <dt>unsetDefaults</dt><dd> <p>Removes name=value pairs from the defaults list. </p> </dd> <dt>getDefaults</dt><dd> <p>Provides access to the stored user defaults. Single arguments need not be quoted, multiple arguments must be in a character vector. </p> </dd> <dt>importDefaults</dt><dd> <p>A call to <code>importDefaults</code> should be placed on the first line in the body of the function. It checks the user's environment for globally specified default values for the called function. These defaults can be specified by the user with a call to <code>setDefaults</code>, and will override any default formal parameters, in effect replacing the original defaults with user supplied values instead. Any user-specified values in the parent function (that is, the function containing <code>importDefaults</code>) will override the values set in the global default environment. </p> </dd> </dl> <h3>Value</h3> <table summary="R valueblock"> <tr valign="top"><td><code>setDefaults</code></td> <td> <p>None. Used for it's side effect of setting a list of default arguments by function. </p> </td></tr> <tr valign="top"><td><code>unsetDefaults</code></td> <td> <p>None. Used for it's side effect of unsetting default arguments by function. </p> </td></tr> <tr valign="top"><td><code>getDefaults</code></td> <td> <p>A named list of defaults and associated values, similar to <code>formals</code>, but only returning values set by <code>setDefaults</code> for the <code>name</code> function. Calling <code>getDefaults()</code> (without arguments) returns in a character vector of all functions currently having defaults set (by <code>setDefaults</code>). </p> <p>This <em>does not</em> imply that the returned function names are able to accept defaults (via <code>importDefaults</code>), rather that they have been set to store user defaults. All values can also be viewed with a call to <code>getOption(name_of_function.Default)</code>. </p> </td></tr> <tr valign="top"><td><code>importDefaults</code></td> <td> <p>None. Used for its side-effect of loading all non-<code>NULL</code> user- specified default values into the current function's environment, effectively changing the default values passed in the parent function call. Like formally defined defaults in the function definition, default values set by <code>importDefaults</code> take lower precedence than arguments specified by the user in the function call. </p> </td></tr> </table> <h3>Note</h3> <dl> <dt>setDefaults</dt><dd> <p>At present it is not possible to specify <code>NULL</code> as a replacement for a non-<code>NULL</code> default, as the process interprets <code>NULL</code> values as being not set, and will simply use the value specified formally in the function. If <code>NULL</code> is what is desired, it is necessary to include this in the function call itself. </p> <p>Any arguments included in the actual function call will take precedence over <code>setDefaults</code> values, as well as the standard formal function values. This conforms to the current user experience in <span style="font-family: Courier New, Courier; color: #666666;"><b>R</b></span>. </p> <p>Like <code>options</code>, default settings are <em>not</em> kept across sessions. Currently, it is <em>not</em> possible to pass values for ... arguments, only formally specified arguments in the original function definition. </p> </dd> <dt>unsetDefaults</dt><dd> <p><code>unsetDefaults</code> removes the <em>all</em> entries from the <code>options</code> lists for the specified function. To remove single function default values simply set the name of the argument to <code>NULL</code> in <code>setDefaults</code>. </p> </dd> <dt>importDefaults</dt><dd> <p>When a function implements <code>importDefaults</code>, non-named arguments <em>may</em> be ignored if a global default has been set (i.e. not <code>NULL</code>). If this is the case, simply name the arguments in the calling function. </p> <p>This <em>should</em> also work for functions retrieving formal parameter values from <code>options</code>, as it assigns a value to the parameter in a way that looks like it was passed in the function call. So any check on <code>options</code> would presumably disregard <code>importDefaults</code> values if an argument was passed to the function. </p> </dd> </dl> <h3>Author(s)</h3> <p> Jeffrey A. Ryan </p> <h3>See Also</h3> <p><code><a href="../../base/html/options.html">options</a></code> </p> <h3>Examples</h3> <pre> my.fun <- function(x=3) { importDefaults('my.fun') x^2 } my.fun() # returns 9 setDefaults(my.fun, x=10) my.fun() # returns 100 my.fun(x=4) # returns 16 getDefaults(my.fun) formals(my.fun) unsetDefaults(my.fun, confirm=FALSE) getDefaults(my.fun) my.fun() # returns 9 </pre> <hr /><div style="text-align: center;">[Package <em>quantmod</em> version 0.4.20 <a href="00Index.html">Index</a>]</div> </body></html>