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