I am trying to understand how to use the package mmap to access large csv files. More precisely, I'd like to

  1. Create a mmap object from a csv file with mmap.csv();
  2. Save the file created by mmap.csv() containing the data in binary format;
  3. Be able to "map the binary data back to R" using the function mmap().

Achieving 1. and 2. is easy: just use mmap.cv() and save the tempfile() that contains the binary data, or modify mmap.cv() to accept an extra parameter as output file (and modify the line tmpstruct <- tempfile() accordingly). What I am having trouble with is 3. In particular, I need to construct a C-struct for the records in the binary data from the mmap object. Here is a simple reproducible example:

# create mmap object with its file
library(mmap)
data(cars)

m <- as.mmap(cars, file="cars.Rmap")
colnames(m) <- colnames(cars)
str(m) 
munmap(m)

The information from str() can be used to construct the C-struct record.struct that allows mapping the binary file cars.Rmap via the function mmap.

> str(m)
<mmap:temp.Rmap>  (struct) struct [1:50, 1:2] 4 ...
  data         :<externalptr> 
  bytes        : num 400
  filedesc     : Named int 27
 - attr(*, "names")= chr "temp.Rmap"
  storage.mode :List of 2
 $ speed:Classes 'Ctype', 'int'  atomic (0) 
  .. ..- attr(*, "bytes")= int 4
  .. ..- attr(*, "signed")= int 1
 $ dist :Classes 'Ctype', 'int'  atomic (0) 
  .. ..- attr(*, "bytes")= int 4
  .. ..- attr(*, "signed")= int 1
 - attr(*, "bytes")= int 8
 - attr(*, "offset")= int [1:2] 0 4
 - attr(*, "signed")= logi NA
 - attr(*, "class")= chr [1:2] "Ctype" "struct"
  pagesize     : num 4096
  dim          :NULL

In this case, we need two 4-byte integers:

Edit
Report