Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in R Programming by (7.3k points)
edited by

What are the main differences between .RData, .Rda and .Rds files?

More specifically:

  • Are there differences in compression etc?
  • When should each type be used?
  • How to convert one type to another?

1 Answer

0 votes
by
edited by

RData files are used to store multiple R objects within a single file. Rda is a short form of RData.

To save multiple objects into RData file, we use the save() function.

Eg.;

save(a, b, c, file = "myobjects.RData")

To save all the objects in the workspace, we use the save.image() function.

save.image(file = "data/projectimage.RData")

To load all of the objects in the workspace from an Rds file, we use the load function.

load(file = "data/projectimage.RData")

Rds files store a single R object. According to R documentation:

These functions provide the means to save a single R object to a connection (typically a file) and to restore the object, quite possibly under a different name. This differs from saving and load, which save and restore one or more named objects into an environment. They are widely used by R itself, for example, to store metadata for a package and to store the help.search databases: the ".rds" file extension is most often used.

Usage:

saveRDS(object, file = "", ascii = FALSE, version = NULL,

        compress = TRUE, refhook = NULL)

readRDS(file, refhook = NULL)

Arguments:

object

R object to serialize.

file

a connection or the name of the file where the R object is saved to or read from.

ascii

a logical. If TRUE or NA, an ASCII representation is written; otherwise (default), a binary one is used. .

version

the workspace format version to use. NULL specifies the current default version (3). The only other supported value is 2, the default from R 1.4.0 to R 3.5.0.

compress

a logical specifying whether saving to a named file is to use "gzip" compression, or one of "gzip", "bzip2" or "xz" to indicate the type of compression to be used. Ignored if the file is a connection.

refhook

a hook function for handling reference objects.

To know more about Rds files click here.

Browse Categories

...