EVOLUTION-MANAGER
Edit File: get.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: Return the Value of a Named Object</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 get {base}"><tr><td>get {base}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Return the Value of a Named Object</h2> <h3>Description</h3> <p>Search by name for an object (<code>get</code>) or zero or more objects (<code>mget</code>). </p> <h3>Usage</h3> <pre> get(x, pos = -1, envir = as.environment(pos), mode = "any", inherits = TRUE) mget(x, envir = as.environment(-1), mode = "any", ifnotfound, inherits = FALSE) dynGet(x, ifnotfound = , minframe = 1L, inherits = FALSE) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>x</code></td> <td> <p>For <code>get</code>, an object name (given as a character string).<br /> For <code>mget</code>, a character vector of object names. </p> </td></tr> <tr valign="top"><td><code>pos, envir</code></td> <td> <p>where to look for the object (see ‘Details’); if omitted search as if the name of the object appeared unquoted in an expression.</p> </td></tr> <tr valign="top"><td><code>mode</code></td> <td> <p>the mode or type of object sought: see the ‘Details’ section.</p> </td></tr> <tr valign="top"><td><code>inherits</code></td> <td> <p>should the enclosing frames of the environment be searched?</p> </td></tr> <tr valign="top"><td><code>ifnotfound</code></td> <td> <p>For <code>mget</code>, a <code><a href="list.html">list</a></code> of values to be used if the item is not found: it will be coerced to a list if necessary.<br /> For <code>dynGet</code> any <span style="font-family: Courier New, Courier; color: #666666;"><b>R</b></span> object, e.g., a call to <code><a href="stop.html">stop</a>()</code>.</p> </td></tr> <tr valign="top"><td><code>minframe</code></td> <td> <p>integer specifying the minimal frame number to look into.</p> </td></tr> </table> <h3>Details</h3> <p>The <code>pos</code> argument can specify the environment in which to look for the object in any of several ways: as a positive integer (the position in the <code><a href="search.html">search</a></code> list); as the character string name of an element in the search list; or as an <code><a href="environment.html">environment</a></code> (including using <code><a href="sys.parent.html">sys.frame</a></code> to access the currently active function calls). The default of <code>-1</code> indicates the current environment of the call to <code>get</code>. The <code>envir</code> argument is an alternative way to specify an environment. </p> <p>These functions look to see if each of the name(s) <code>x</code> have a value bound to it in the specified environment. If <code>inherits</code> is <code>TRUE</code> and a value is not found for <code>x</code> in the specified environment, the enclosing frames of the environment are searched until the name <code>x</code> is encountered. See <code><a href="environment.html">environment</a></code> and the ‘R Language Definition’ manual for details about the structure of environments and their enclosures. </p> <p>If <code>mode</code> is specified then only objects of that type are sought. <code>mode</code> here is a mixture of the meanings of <code><a href="typeof.html">typeof</a></code> and <code><a href="mode.html">mode</a></code>: <code>"function"</code> covers primitive functions and operators, <code>"numeric"</code>, <code>"integer"</code> and <code>"double"</code> all refer to any numeric type, <code>"symbol"</code> and <code>"name"</code> are equivalent <em>but</em> <code>"language"</code> must be used (and not <code>"call"</code> or <code>"("</code>). </p> <p>For <code>mget</code>, the values of <code>mode</code> and <code>ifnotfound</code> can be either the same length as <code>x</code> or of length 1. The argument <code>ifnotfound</code> must be a list containing either the value to use if the requested item is not found or a function of one argument which will be called if the item is not found, with argument the name of the item being requested. </p> <p><code>dynGet()</code> is somewhat experimental and to be used <em>inside</em> another function. It looks for an object in the callers, i.e., the <code><a href="sys.parent.html">sys.frame</a>()</code>s of the function. Use with caution. </p> <h3>Value</h3> <p>For <code>get</code>, the object found. If no object is found an error results. </p> <p>For <code>mget</code>, a named list of objects (found or specified <em>via</em> <code>ifnotfound</code>). </p> <h3>Note</h3> <p>The reverse (or “inverse”) of <code>a <- get(nam)</code> is <code><a href="assign.html">assign</a>(nam, a)</code>, assigning <code>a</code> to name <code>nam</code>. </p> <p><code>inherits = TRUE</code> is the default for <code>get</code> in <span style="font-family: Courier New, Courier; color: #666666;"><b>R</b></span> but not for S where it had a different meaning. </p> <h3>References</h3> <p>Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988) <em>The New S Language</em>. Wadsworth & Brooks/Cole. </p> <h3>See Also</h3> <p><code><a href="exists.html">exists</a></code> for checking whether an object exists; <code><a href="exists.html">get0</a></code> for an efficient way of both checking existence and getting an object. </p> <p><code><a href="assign.html">assign</a></code>, the inverse of <code>get()</code>, see above. </p> <p>Use <code><a href="../../utils/html/getAnywhere.html">getAnywhere</a></code> for searching for an object anywhere, including in other namespaces, and <code><a href="../../utils/html/getFromNamespace.html">getFromNamespace</a></code> to find an object in a specific namespace. </p> <h3>Examples</h3> <pre> get("%o%") ## test mget e1 <- new.env() mget(letters, e1, ifnotfound = as.list(LETTERS)) </pre> <hr /><div style="text-align: center;">[Package <em>base</em> version 3.6.0 <a href="00Index.html">Index</a>]</div> </body></html>