1

I am able to see every database in the .rdb file in the variable environment as a "promise" as per direction here. Now, I want to edit one of the file and save it. How can I do that? I am new in R.

James Z
  • 12,209
  • 10
  • 24
  • 44

1 Answers1

0

In a discussion on r-pkg-devel, Ivan Krylov provided the following function ro read an RDB database:

# 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))
}

Therefore, you should be able to implement the reverse using a combination of serialize, memCompress, and writeBin.

Note that if the object changes size, you will also have to adjust the index file.

Neal Fultz
  • 9,282
  • 1
  • 39
  • 60