Home

readRDS

readRDS is a base R function that reads a single R object from a file created with saveRDS. It reconstructs the object in memory, preserving its attributes and internal structure. The file argument should be a path to a file or a connection. The function returns the deserialized object, which you typically assign to a variable, for example: obj <- readRDS("path/to/file.rds").

Key points:

- readRDS reads exactly one object. It is the counterpart to saveRDS, which writes a single R object

- The object’s name is not stored in the file; the name is chosen by the assignment at

- The file is often binary and may be compressed depending on how it was written with saveRDS

- readRDS preserves object type, attributes, and most internal structures, so data frames, lists, environments, S3/S4 objects,

Usage notes:

- Signature: readRDS(file, refhook = NULL). The refhook parameter is rarely used in typical workflows.

- Security: avoid reading RDS files from untrusted sources. Deserialization can pose risks if the data contains

In practice, readRDS is commonly used for persisting a single object between sessions or for transferring a

to
a
file.
For
multiple
objects,
use
save
to
create
an
.RData
file
and
load
to
restore
all
objects.
read
time
(unlike
the
original
variable
name
used
when
saving).
(compression
is
controlled
by
the
compress
argument
in
saveRDS;
readRDS
transparently
reads
the
file).
and
closures
can
be
restored.
crafted
objects.
single
object
across
environments,
while
saveRDS
and
loadRData
provide
a
broader
set
of
options
for
multiple
objects.