R - save datasets (save(),saveRDS(), write.table(), WriteXLS())

31 May 2019

https://www.r-bloggers.com/how-to-save-and-load-datasets-in-r-an-overview/

Save R objects

  1. save() -> create an .Rdata file, where several variables can be stored. To save space, use with compress=TRUE (default), to save time use with compress = FALSE.
data2 <- data
save(list = c("data", "data2"), file = "data.Rdata")
load("data.Rdata")
  1. saveRDS() -> create an .Rds file. where only 1 variable can be stored. The compress parameter is also available for saveRDS)
saveRDS(data, file = "data.Rds")
data.copy <- readRDS(file = "data.Rds")

With readRDS(), assign the result of the reading process to a variable.

With load(), you have to remember the name of the stored variable.

Save as a CSV file

Save as an Excel file

library(WriteXLS)
WriteXLS()
[ R  function  objects  save  ]