save_RDS_or_RDA: Save a single object to am RDS or RDA file

View source: R/rdata_io.R

save_RDS_or_RDAR Documentation

Save a single object to am RDS or RDA file

Description

If the output file name ends in ".rda" or ".rdata" (with any capitalization), the file will be saved using save(). Otherwise, it will be saved using saveRDS().

Usage

save_RDS_or_RDA(
  object,
  file,
  ascii = FALSE,
  version = NULL,
  compress = TRUE,
  savetype
)

Arguments

object

R object to serialize.

file

A file name or connection object to save to.

ascii, version, compress

See saveRDS().

savetype

Either "rda" or "rds". If this argument is supplied, it overrides the automatic detection of whether to use save() or saveRDS() based on the file extension.

Examples


tmpf_rda <- tempfile(fileext = ".rda")
tmpf_rds <- tempfile(fileext = ".rds")
x <- 1:10
save_RDS_or_RDA(x, tmpf_rda)
save_RDS_or_RDA(x, tmpf_rds)
# Load as an RData file
x_rda <- read_single_object_from_rda(tmpf_rda)
# Load as an RDS file
x_rds <- readRDS(tmpf_rds)
# Both loaded objects are identical to the original
identical(x, x_rda)
identical(x, x_rds)


DarwinAwardWinner/rctutils documentation built on July 22, 2022, 5:19 a.m.