首页 > 解决方案 > 如何在 RStudio 中查看、打开和保存 .rdb 文件

问题描述

我可以按照此处的方向将变量环境中 .rdb 文件中的每个数据库视为“承诺” 。现在,我想编辑其中一个文件并保存它。我怎样才能做到这一点?我是 R 的新手。

标签: r

解决方案


在关于r-pkg-devel的讨论中,Ivan Krylov 提供了以下函数来读取 RDB 数据库:

# filename: the .rdb file
# offset, size: the pair of values from the .rdx
# type: 'gzip' if $compressed is TRUE, 'bzip2' for 2, 'xz' for 3
readRDB <- function(filename, offset, size, type = 'gzip') {
        f <- file(filename, 'rb')
        on.exit(close(f))
        seek(f, offset + 4)
        unserialize(memDecompress(readBin(f, 'raw', size - 4), type))
}

因此,您应该能够使用 、 和 的组合来实现serialize反向memCompress操作writeBin

请注意,如果对象更改大小,您还必须调整索引文件。


推荐阅读