EVOLUTION-MANAGER
Edit File: mode.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: The (Storage) Mode of an 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 mode {base}"><tr><td>mode {base}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>The (Storage) Mode of an Object</h2> <h3>Description</h3> <p>Get or set the type or storage mode of an object. </p> <h3>Usage</h3> <pre> mode(x) mode(x) <- value storage.mode(x) storage.mode(x) <- value </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>x</code></td> <td> <p>any <span style="font-family: Courier New, Courier; color: #666666;"><b>R</b></span> object.</p> </td></tr> <tr valign="top"><td><code>value</code></td> <td> <p>a character string giving the desired mode or ‘storage mode’ (type) of the object.</p> </td></tr> </table> <h3>Details</h3> <p>Both <code>mode</code> and <code>storage.mode</code> return a character string giving the (storage) mode of the object — often the same — both relying on the output of <code><a href="typeof.html">typeof</a>(x)</code>, see the example below. </p> <p><code>mode(x) <- "newmode"</code> changes the <code>mode</code> of object <code>x</code> to <code>newmode</code>. This is only supported if there is an appropriate <code>as.newmode</code> function, for example <code>"logical"</code>, <code>"integer"</code>, <code>"double"</code>, <code>"complex"</code>, <code>"raw"</code>, <code>"character"</code>, <code>"list"</code>, <code>"expression"</code>, <code>"name"</code>, <code>"symbol"</code> and <code>"function"</code>. Attributes are preserved (but see below). </p> <p><code>storage.mode(x) <- "newmode"</code> is a more efficient <a href="Primitive.html">primitive</a> version of <code>mode<-</code>, which works for <code>"newmode"</code> which is one of the internal types (see <code><a href="typeof.html">typeof</a></code>), but not for <code>"single"</code>. Attributes are preserved. </p> <p>As storage mode <code>"single"</code> is only a pseudo-mode in <span style="font-family: Courier New, Courier; color: #666666;"><b>R</b></span>, it will not be reported by <code>mode</code> or <code>storage.mode</code>: use <code>attr(object, "Csingle")</code> to examine this. However, <code>mode<-</code> can be used to set the mode to <code>"single"</code>, which sets the real mode to <code>"double"</code> and the <code>"Csingle"</code> attribute to <code>TRUE</code>. Setting any other mode will remove this attribute. </p> <p>Note (in the examples below) that some <code><a href="call.html">call</a></code>s have mode <code>"("</code> which is S compatible. </p> <h3>Mode names</h3> <p>Modes have the same set of names as types (see <code><a href="typeof.html">typeof</a></code>) except that </p> <ul> <li><p> types <code>"integer"</code> and <code>"double"</code> are returned as <code>"numeric"</code>. </p> </li> <li><p> types <code>"special"</code> and <code>"builtin"</code> are returned as <code>"function"</code>. </p> </li> <li><p> type <code>"symbol"</code> is called mode <code>"name"</code>. </p> </li> <li><p> type <code>"language"</code> is returned as <code>"("</code> or <code>"call"</code>. </p> </li></ul> <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="typeof.html">typeof</a></code> for the R-internal ‘mode’, <code><a href="../../utils/html/type.convert.html">type.convert</a></code>, <code><a href="attributes.html">attributes</a></code>. </p> <h3>Examples</h3> <pre> require(stats) sapply(options(), mode) cex3 <- c("NULL", "1", "1:1", "1i", "list(1)", "data.frame(x = 1)", "pairlist(pi)", "c", "lm", "formals(lm)[[1]]", "formals(lm)[[2]]", "y ~ x","expression((1))[[1]]", "(y ~ x)[[1]]", "expression(x <- pi)[[1]][[1]]") lex3 <- sapply(cex3, function(x) eval(parse(text = x))) mex3 <- t(sapply(lex3, function(x) c(typeof(x), storage.mode(x), mode(x)))) dimnames(mex3) <- list(cex3, c("typeof(.)","storage.mode(.)","mode(.)")) mex3 ## This also makes a local copy of 'pi': storage.mode(pi) <- "complex" storage.mode(pi) rm(pi) </pre> <hr /><div style="text-align: center;">[Package <em>base</em> version 3.6.0 <a href="00Index.html">Index</a>]</div> </body></html>