Home

saveRDSreadRDS

saveRDS and readRDS are base R functions designed to serialize a single R object to disk and to restore it later. They provide a compact, language-native mechanism for persisting objects, sharing them between sessions, or caching results. Unlike the save function, which writes one or more named objects to an .RData file, saveRDS and readRDS focus on a single object and do not save the object’s original name.

saveRDS writes a single R object to a file in the RDS format. Its typical usage is

readRDS reads an RDS file and returns the stored object. The returned value is typically assigned to

Compared with save and load, saveRDS/readRDS are ideal for persisting single objects and controlling their loaded

saveRDS(object,
file)
with
optional
arguments
such
as
ascii,
version,
compress,
and
refhook.
The
ascii
option
writes
a
human-readable
representation
when
supported,
version
selects
the
serialization
format
version,
compress
controls
whether
compression
is
used,
and
refhook
allows
handling
of
external
pointers
during
restoration.
Importantly,
saveRDS
does
not
store
the
object
name;
the
name
is
assigned
when
the
object
is
read
back.
a
variable,
e.g.,
obj
<-
readRDS("path/model.rds").
The
original
object
name
is
not
restored,
so
explicit
assignment
determines
how
the
object
is
named
in
the
current
session.
readRDS
accepts
a
refhook
argument
similar
to
saveRDS
for
advanced
restoration
scenarios.
names,
while
save/load
handle
multiple
objects
and
preserve
their
names
within
an
environment.
The
.rds
format
is
R-specific
and
primarily
used
for
R-to-R
data
exchange.