Skip to main content
v2026.11,986 entries · CC-BY 4.0

RDS File: What It Is and How to Open or Save It in R

An RDS file stores one serialized R object. Learn saveRDS(), readRDS(), infoRDS(), RDS vs RData, format versions and troubleshooting.

Written and maintained by CASRAI Editorial Board

Published

On this page

An RDS file is a file, usually named with the .rds extension, that holds a single R object written in R’s own serialization format. You create it with saveRDS() and open it with readRDS(), both in base R. The R manual describes the extension as the one most often used for such files; it is a convention, not a requirement, so R reads the file by its contents rather than its name.

This guide explains what is inside an RDS file, how to write and read one, how it differs from .RData files, how format versions affect who can open it, and what to do when reading fails. Everything below is taken from the R documentation (base R manual pages and the R Internals manual), read on 2026-11-12.

What is an RDS file?

An RDS file stores exactly one R object, such as a data frame, a fitted model, a list or a vector, together with its structure, so that R can rebuild the object later. The R manual page for readRDS says that saveRDS and readRDS save and restore a single object, and that the object can be restored under a different name from the one it had when it was saved. That is the main practical difference from save() and load(), which handle one or more named objects and put them back into an environment under their original names.

What does the .rds extension mean?

Nothing technical. The documentation says only that .rds is the extension most often used for these files. You can write the same content to a file with a different name, and readRDS() will still read it. Using .rds is useful because colleagues and file browsers can tell at a glance that the file is a single serialized R object rather than a spreadsheet or a workspace image.

What is serialization?

Serialization is the process of turning an in-memory object into a stream of bytes. The R Internals manual (section 1.8, Serialization Formats) describes the format R uses. In the default form the stream begins with a header, normally the characters X and a newline, which marks a binary stream in XDR (big-endian) byte order. Alternatives exist: A marks an ASCII stream and B marks native binary. By default the whole stream is then compressed with gzip, which is why you cannot read an RDS file in a text editor.

What it is used for in research

Researchers use RDS files to keep the result of an expensive or slow step so it does not have to be repeated: a cleaned analysis data set, a fitted model, a list of intermediate results, a processed copy of a large import. Because the object comes back with its types, factor levels, attributes and column classes intact, an RDS file avoids the type-guessing that happens when a table is written out as plain text and read back in.

The R documentation also shows where the format is a poor choice. The readRDS page warns that these files are not suitable as an interchange format between machines, and the serialize page says serialization should not be used for long-term storage of R objects. For sharing or archiving research data, the format is a working copy, not a deposit format. The FAIR data principles and your data management plan are the right frame for deciding what you publish alongside it; the research data management hub collects the related guidance.

Access: RDS support is built into base R

No package is needed. saveRDS(), readRDS() and infoRDS() belong to base R, so they are available in any R session, in RStudio, and in scripts run from the command line. If you need a current R installation, the CASRAI guide on updating R covers it. The functions documented in the R-devel manual are:

  • saveRDS(object, file = "", ascii = FALSE, version = NULL, compress = TRUE, refhook = NULL)
  • readRDS(file, refhook = NULL)
  • infoRDS(file)

How to save and read an RDS file in R

Save an object with saveRDS

  1. Create or load the object you want to keep, for example results <- lm(mpg ~ wt, data = mtcars).
  2. Write it to disk with saveRDS(results, file = "results.rds"). The file is created in the current working directory unless you give a path. Check the working directory with getwd().
  3. Note that saveRDS() returns NULL invisibly. Nothing is printed on success, and an error message is the only sign of a problem.

Open an RDS file with readRDS

  1. Call readRDS("results.rds"). The function returns the stored object.
  2. Assign the return value to a name: restored <- readRDS("results.rds"). Without the assignment, R prints the object but does not keep it. Because the object can be restored under a different name, restored may be any name you like.
  3. Use the object as usual, for instance summary(restored).

Inspect a file before reading it with infoRDS

infoRDS("results.rds") reads only the header information and returns a list with the serialization version, the writer_version (the R version that wrote it), the min_reader_version (the oldest R that can read it), the format, and, for version 3 and later, the native_encoding. The manual notes that this function cannot confirm that the whole file is valid; it reports what the header says.

Choose compression and version

The compress argument accepts TRUE (gzip, the default), FALSE, or one of "gzip", "bzip2", "xz" or "zstd"; it is ignored if file is a connection. The version argument defaults to NULL, which means the current default, version 3; the only other accepted value is 2. Setting ascii = TRUE writes an ASCII representation instead of binary.

saveRDS(results, "results_v2.rds", version = 2)   # readable by R older than 3.5.0saveRDS(results, "results_xz.rds", compress = "xz")info <- infoRDS("results_v2.rds")info$min_reader_version

Reading the output: what you get back

The object returned by readRDS() is the same kind of object that was saved. A saved data frame comes back as a data frame with its column classes; a saved model comes back as a model object you can pass to predict() or summary(). Packages that the object depends on must be installed for methods on it to work, a standard behaviour of R objects rather than anything specific to this format.

Use identical(original, restored) to confirm a round trip in a script. If you export results for colleagues who do not use R, the RDS file is the wrong deliverable; write an open, documented format alongside it.

RDS versus RData: saveRDS, save and load

The R manual page for save states that for saving single R objects, saveRDS() is mostly preferable to save(), notably because readRDS() is functional: it returns the object, whereas load() creates objects in the environment as a side effect, possibly overwriting something with the same name. The table below sets out the differences documented in the manual pages.

Function pair What it stores How you get it back Typical file name
saveRDS() / readRDS() A single R object Returned by readRDS(); you choose the name .rds (most often used)
save() / load() One or more named objects Restored into an environment under their original names .RData or .rda
save.image() The whole workspace (shortcut for save) Restored with load() .RData in the working directory by default
serialize() / unserialize() An object as a raw vector or connection stream Output is readable by readRDS() and vice versa No file by default

The practical rule: use RDS when you want one object back under a name you control, and save() only when you need several named objects stored together. Both formats use gzip compression by default, and version 3 is supported by save() from R 3.5.0.

Serialization versions and compatibility

RDS files carry a format version. According to the R Internals manual, version 2 was used from R 1.4.0 (December 2001) until R 3.5.3 (March 2019) as the default, and version 3 was introduced in R 3.5.0. Version 3 adds support for ALTREP custom serialization and records the native encoding of the session that wrote the file. The serialize manual page describes the interface as stable since R 2.4.0.

The consequence for collaboration: a file written with the default (version 3) by a current R session is intended for readers on a current R. If a collaborator or a computing cluster runs an R older than 3.5.0, write the file with version = 2, and use infoRDS() to confirm the min_reader_version before sending it. Where possible, agree on one R version for a project and record it, which is also what a reproducibility audit will ask for. The data table below lists the header and format options in the documentation.

Troubleshooting

“Cannot open file” or “No such file or directory”

R looks for a relative path in the working directory. Run getwd() and list.files() to see where R is looking, then either change the directory with setwd() or pass the full path to readRDS(). In project-based workflows, building paths relative to the project folder keeps scripts portable.

The object does not appear after readRDS

readRDS() returns the object; it does not create it by name the way load() does. Assign the result: x <- readRDS("file.rds").

An error about the file format or an unknown input format

The file may not be an RDS file at all (a workspace saved with save() must be opened with load()), or it may be damaged. Try infoRDS() to see whether the header can be read. The manual states that the check cannot prove validity, so a header that reads cleanly does not guarantee a complete file.

The file was written by a newer R than the one you have

Compare min_reader_version from infoRDS() with your R version, and update R (see updating R) or ask the sender to re-save with version = 2.

You need to use the object in a Shiny app

Applications often read a prepared RDS file at start-up instead of recomputing it. Keep the file inside the app directory and use a relative path; the shinyapps.io guide covers deployment.

Free alternatives

All of the options below are part of base R, so none needs an additional package. The table is limited to what the R manual pages state.

Alternative Use it when Documented caveat
save() and load() You need several named objects in one file Less suitable for a single object; load() restores by original name
save.image() You want a snapshot of the whole workspace Default file .RData in the working directory
serialize() to a connection or raw vector You want the byte stream itself, for example to send over a connection Not for long-term storage of R objects
saveRDS(..., ascii = TRUE) You want an ASCII form of the serialized object Still an R-specific format

For data you intend to share outside R, export a plain tabular or other open format and describe it in documentation, as the FAIR principles above recommend, and treat the RDS file as an R-side working copy.

Frequently asked questions

What is an RDS file?

It is a file holding one serialized R object, normally created by saveRDS() and read by readRDS(), with .rds as the usual extension.

How do I open an RDS file?

Open R or RStudio and run x <- readRDS("path/to/file.rds"). A double-click on the file does not open it in a viewer, because the contents are compressed binary data meant for R.

What does saveRDS do?

It writes one R object to a file in R’s serialization format, gzip-compressed by default, and returns NULL invisibly.

What does readRDS do?

It reads a file written by saveRDS() (or by serialize()) and returns the object, which you assign to any name.

What is the difference between .rds and .RData?

RDS stores a single object that you name on reading; .RData (from save() or save.image()) stores one or more named objects that load() restores under those names.

Can an RDS file be opened without R?

The R documentation describes the format only in terms of R functions. This guide therefore does not recommend a non-R reader; if collaborators do not use R, supply an open format instead.

Are RDS files suitable for archiving?

The R manual says the files are not suitable as an interchange format between machines and that serialization should not be used for long-term storage of R objects. Keep an open-format copy for archives.

Sources

Data: R serialization format options relevant to .rds files

Compilation of the stream header codes, compression options and format versions that apply to RDS files, compiled from the R-devel base manual pages and the R Internals manual (section 1.8).

R serialization format options relevant to .rds files
FeatureOption or valueMeaning in the R documentation
Stream headerX (then newline)Binary stream in XDR (big-endian) format; the normal default
Stream headerA (then newline)ASCII stream; written by saveRDS with ascii = TRUE
Stream headerB (then newline)Native binary stream
Compression (compress argument)TRUE or "gzip"gzip; the default for saveRDS
Compression (compress argument)"bzip2"bzip2 compression
Compression (compress argument)"xz"xz compression
Compression (compress argument)"zstd"zstd compression
Serialization version2Used from R 1.4.0 (Dec 2001) and the default until R 3.5.3 (Mar 2019); the only non-default value saveRDS accepts
Serialization version3Introduced in R 3.5.0; current default; adds ALTREP custom serialization and records native encoding

Sources

Compiled by CASRAI from the sources above. Free to reuse under CC BY 4.0 with attribution.

Follow CASRAI

Research-administration guidance, standards updates and independent tool reviews.

Ask CASRAI · free to try

Ask about RDS File: What It Is and How to Open or Save It in R

Ask your first 2 questions free below. Subscribers get 150 a day for $29 a month.

An AI assistant specialized in research administration. It cites the sources behind every answer, labels web answers and says when it can't answer.

Answers draw on CASRAI's guides and dictionary plus the federal and funder documents we index: Federal Register, Grants.gov, Regulations.gov and UKRI.

Works on this site and inside Claude, Cursor and the AI tools you already use.

Everything CASRAI publishes — this page, the dictionary, the guides and the news — stays free to read, with no account and no card.

Referenced across the research world

University of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logoUniversity of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logo
  • University of Cambridge logo
  • Columbia University logo
  • Crossref logo
  • University of Edinburgh logo
  • Harvard University logo
  • University of Oxford logo
  • Princeton University logo
  • Stanford School of Medicine logo
  • University College London logo
  • ORCID logo

View CASRAI adoption →