和文件之间.RData
的主要区别是什么?.Rda
.Rds
- 压缩等方面有区别吗?
- 什么时候应该使用每种类型?
- 如何将一种类型转换为另一种类型?
Rda 只是 RData 的简称。您可以像使用 RData 一样保存()、加载()、附加()等。
Rds 存储单个R 对象。然而,除了这个简单的解释之外,与“标准”存储还有几个不同之处。可能这个R-manual Link to readRDS() function充分阐明了这些区别。
所以,回答你的问题:
除了@KenM 的回答,另一个重要的区别是,在加载保存的对象时,您可以分配Rds
文件的内容。不是这样的Rda
> x <- 1:5
> save(x, file="x.Rda")
> saveRDS(x, file="x.Rds")
> rm(x)
## ASSIGN USING readRDS
> new_x1 <- readRDS("x.Rds")
> new_x1
[1] 1 2 3 4 5
## 'ASSIGN' USING load -- note the result
> new_x2 <- load("x.Rda")
loading in to <environment: R_GlobalEnv>
> new_x2
[1] "x"
# NOTE: `load()` simply returns the name of the objects loaded. Not the values.
> x
[1] 1 2 3 4 5