[ RDocumentation ](/)

Moon  [ ](https://github.com/datacamp/rdocumentation-2.0) [ Learn R
](https://www.datacamp.com/learn/r)

Search all packages and functions

[ base  (version  3.6.2  ) ](/packages/base/versions/3.6.2)

#  load: Reload Saved Datasets

##  Description

Reload datasets written with the function ` save ` .

##  Usage

    
    
    load(file, envir = parent.frame(), verbose = FALSE)

##  Arguments

file

a (readable binary-mode) [ connection
](/link/connection?package=base&version=3.6.2) or a character string giving
the name of the file to load (when [ tilde expansion
](/link/tilde%20expansion?package=base&version=3.6.2) is done).

envir

the environment where the data should be loaded.

verbose

should item names be printed during loading?

##  Value

A character vector of the names of objects created, invisibly.

##  Warning

Saved  R  objects are binary files, even those saved with ` ascii = TRUE ` ,
so ensure that they are transferred without conversion of end of line markers.
` load ` tries to detect such a conversion and gives an informative error
message.

` load(<file>) ` replaces all existing objects with the same names in the
current environment (typically your workspace, ` [ .GlobalEnv
](/link/.GlobalEnv?package=base&version=3.6.2) ` ) and hence potentially
overwrites important data. It is considerably safer to use ` envir = ` to load
into a different environment, or to ` [ attach
](/link/attach?package=base&version=3.6.2) (file) ` which ` load() ` s into a
new entry in the ` [ search ](/link/search?package=base&version=3.6.2) ` path.

##  Details

` load ` can load  R  objects saved in the current or any earlier format. It
can read a compressed file (see ` [ save
](/link/save?package=base&version=3.6.2) ` ) directly from a file or from a
suitable connection (including a call to ` [ url
](/link/url?package=base&version=3.6.2) ` ).

A not-open connection will be opened in mode ` "rb" ` and closed after use.
Any connection other than a ` [ gzfile
](/link/gzfile?package=base&version=3.6.2) ` or ` [ gzcon
](/link/gzcon?package=base&version=3.6.2) ` connection will be wrapped in ` [
gzcon ](/link/gzcon?package=base&version=3.6.2) ` 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).

Only  R  objects saved in the current format (used since  R  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.

Loading from an earlier version will give a warning about the ‘magic number’:
magic numbers ` 1971:1977 ` are from  R  < 0.99.0, and ` RD[ABX]1 ` from  R
0.99.0 to  R  1.3.1. These are all obsolete, and you are strongly recommended
to re-save such files in a current format.

The ` verbose ` argument is mainly intended for debugging. If it is ` TRUE ` ,
then as objects from the file are loaded, their names will be printed to the
console. If ` verbose ` 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.

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

##  See Also

` [ save ](/link/save?package=base&version=3.6.2) ` , ` [ download.file
](/link/download.file?package=base&version=3.6.2) ` ; further ` [ attach
](/link/attach?package=base&version=3.6.2) ` as wrapper for ` load() ` .

For other interfaces to the underlying serialization format, see ` [
unserialize ](/link/unserialize?package=base&version=3.6.2)