EVOLUTION-MANAGER
Edit File: load.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: Reload Saved Datasets</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 load {base}"><tr><td>load {base}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Reload Saved Datasets</h2> <h3>Description</h3> <p>Reload datasets written with the function <code>save</code>. </p> <h3>Usage</h3> <pre> load(file, envir = parent.frame(), verbose = FALSE) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>file</code></td> <td> <p>a (readable binary-mode) <a href="connections.html">connection</a> or a character string giving the name of the file to load (when <a href="path.expand.html">tilde expansion</a> is done).</p> </td></tr> <tr valign="top"><td><code>envir</code></td> <td> <p>the environment where the data should be loaded.</p> </td></tr> <tr valign="top"><td><code>verbose</code></td> <td> <p>should item names be printed during loading?</p> </td></tr> </table> <h3>Details</h3> <p><code>load</code> can load <span style="font-family: Courier New, Courier; color: #666666;"><b>R</b></span> objects saved in the current or any earlier format. It can read a compressed file (see <code><a href="save.html">save</a></code>) directly from a file or from a suitable connection (including a call to <code><a href="connections.html">url</a></code>). </p> <p>A not-open connection will be opened in mode <code>"rb"</code> and closed after use. Any connection other than a <code><a href="connections.html">gzfile</a></code> or <code><a href="gzcon.html">gzcon</a></code> connection will be wrapped in <code><a href="gzcon.html">gzcon</a></code> to allow compressed saves to be handled: note that this leaves the connection in an altered state (in particular, binary-only), and that it needs to be closed explicitly (it will not be garbage-collected). </p> <p>Only <span style="font-family: Courier New, Courier; color: #666666;"><b>R</b></span> objects saved in the current format (used since <span style="font-family: Courier New, Courier; color: #666666;"><b>R</b></span> 1.4.0) can be read from a connection. If no input is available on a connection a warning will be given, but any input not in the current format will result in a error. </p> <p>Loading from an earlier version will give a warning about the ‘magic number’: magic numbers <code>1971:1977</code> are from <span style="font-family: Courier New, Courier; color: #666666;"><b>R</b></span> < 0.99.0, and <code>RD[ABX]1</code> from <span style="font-family: Courier New, Courier; color: #666666;"><b>R</b></span> 0.99.0 to <span style="font-family: Courier New, Courier; color: #666666;"><b>R</b></span> 1.3.1. These are all obsolete, and you are strongly recommended to re-save such files in a current format. </p> <p>The <code>verbose</code> argument is mainly intended for debugging. If it is <code>TRUE</code>, then as objects from the file are loaded, their names will be printed to the console. If <code>verbose</code> is set to an integer value greater than one, additional names corresponding to attributes and other parts of individual objects will also be printed. Larger values will print names to a greater depth. </p> <p>Objects can be saved with references to namespaces, usually as part of the environment of a function or formula. Such objects can be loaded even if the namespace is not available: it is replaced by a reference to the global environment with a warning. The warning identifies the first object with such a reference (but there may be more than one). </p> <h3>Value</h3> <p>A character vector of the names of objects created, invisibly. </p> <h3>Warning</h3> <p>Saved <span style="font-family: Courier New, Courier; color: #666666;"><b>R</b></span> objects are binary files, even those saved with <code>ascii = TRUE</code>, so ensure that they are transferred without conversion of end of line markers. <code>load</code> tries to detect such a conversion and gives an informative error message. </p> <p><code>load(<file>)</code> replaces all existing objects with the same names in the current environment (typically your workspace, <code><a href="environment.html">.GlobalEnv</a></code>) and hence potentially overwrites important data. It is considerably safer to use <code>envir = </code> to load into a different environment, or to <code><a href="attach.html">attach</a>(file)</code> which <code>load()</code>s into a new entry in the <code><a href="search.html">search</a></code> path. </p> <h3>See Also</h3> <p><code><a href="save.html">save</a></code>, <code><a href="../../utils/html/download.file.html">download.file</a></code>; further <code><a href="attach.html">attach</a></code> as wrapper for <code>load()</code>. </p> <p>For other interfaces to the underlying serialization format, see <code><a href="serialize.html">unserialize</a></code> and <code><a href="readRDS.html">readRDS</a></code>. </p> <h3>Examples</h3> <pre> ## save all data xx <- pi # to ensure there is some data save(list = ls(all = TRUE), file= "all.rda") rm(xx) ## restore the saved values to the current environment local({ load("all.rda") ls() }) xx <- exp(1:3) ## restore the saved values to the user's workspace load("all.rda") ## which is here *equivalent* to ## load("all.rda", .GlobalEnv) ## This however annihilates all objects in .GlobalEnv with the same names ! xx # no longer exp(1:3) rm(xx) attach("all.rda") # safer and will warn about masked objects w/ same name in .GlobalEnv ls(pos = 2) ## also typically need to cleanup the search path: detach("file:all.rda") ## clean up (the example): unlink("all.rda") ## Not run: con <- url("http://some.where.net/R/data/example.rda") ## print the value to see what objects were created. print(load(con)) close(con) # url() always opens the connection ## End(Not run)</pre> <hr /><div style="text-align: center;">[Package <em>base</em> version 3.6.0 <a href="00Index.html">Index</a>]</div> </body></html>