简体   繁体   English

.rds 文件内部格式

[英].rds file internal format

I have lost a .rds file due to the device (let's call it volume 1) getting filled up.由于设备(我们称之为第 1 卷)被填满,我丢失了一个 .rds 文件。 Usually when that happened R would throw an error and stop.通常,当发生这种情况时,R 会抛出错误并停止。 In that case I had a safe copy on a different volume (volume 2).在那种情况下,我在不同的卷(卷 2)上有一个安全的副本。 This time however, R would write the file on volume 1 without error and copy it over to volume 2. Now the file cannot be opened with readRDS anymore with the error "error reading from connection".然而,这一次,R 将在第 1 卷上写入文件而不会出错,并将其复制到第 2 卷。现在无法使用 readRDS 打开该文件,并出现错误“从连接读取错误”。

The file contains a data.table, is stored uncompressed and infoRDS can read the metadata:该文件包含一个 data.table,未压缩存储并且 infoRDS 可以读取元数据:

> infoRDS('corrupt.rds')
$version
[1] 3

$writer_version
[1] "3.6.3"

$min_reader_version
[1] "3.5.0"

$format
[1] "xdr"

$native_encoding
[1] "UTF-8"

Also, hexView::readRaw can read the file and shows the names of the columns of the data table.此外, hexView::readRaw 可以读取文件并显示数据表的列的名称。

Using使用

readRaw('corrupt.rds', endian = 'big', human = 'real', width = 8, offset = 5)

I can see many of the numbers I need to recover.我可以看到许多我需要恢复的数字。 However, this seems very tedious of an approach, since I don't understand the internal format of the .rds file.但是,这似乎是一种非常乏味的方法,因为我不了解 .rds 文件的内部格式。

I also looked into xmlDeserializeHook which I don't understand how to use.我还研究了 xmlDeserializeHook,我不明白如何使用。 Of course the C code used by readRDS unserializeFromConn contains all the information of the used structure, but a higher level documentation would be helpful.当然,readRDS unserializeFromConn使用的 C 代码包含所用结构的所有信息,但更高级别的文档会有所帮助。

Is there an easier way than to dive into that C code or pick up the numbers manually one by one?有没有比深入研究 C 代码或手动逐个获取数字更简单的方法?

R internals contains a documentation of the serialisation format. R 内部包含序列化格式的文档。 Unless somebody published a more detailed description on the mailing list, that's probably the best we can do.除非有人在邮件列表上发布了更详细的描述,否则这可能是我们能做的最好的事情。 But (at a glance) this looks to be a fairly comprehensive description (definitely when taken together with the implementation).但是(一目了然)这看起来是一个相当全面的描述(当与实现结合在一起时)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM