Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6766601
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:51:03+00:00 2026-05-26T14:51:03+00:00

I am trying to understand how to use the package mmap to access large

  • 0

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:

# load from disk
record.struct <- struct(speed = integer(),  # int32(), 4 byte int
                        dist  = integer()   # int32(), 4 byte int
                        )
m <- mmap("temp.Rmap", mode=record.struct)

Inferring the right C-struct can be very impractical for “wide” csv files (i.e. files with tens or hundreds of columns). Here is my question:
How can one construct record.struct directly
from the mmap object m?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T14:51:04+00:00Added an answer on May 26, 2026 at 2:51 pm

    A more or less complete example of what you are asking – using mmap and mmap.csv

    data(mtcars)
    tmp <- tempfile()
    write.csv(mtcars, tmp)
    m <- mmap.csv(tmp)   # mmap in the csv
    head(m)
                        X  mpg cyl disp  hp drat    wt  qsec vs am gear carb
    1 Mazda RX4           21.0   6  160 110 3.90 2.620 16.46  0  1    4    4
    2 Mazda RX4 Wag       21.0   6  160 110 3.90 2.875 17.02  0  1    4    4
    3 Datsun 710          22.8   4  108  93 3.85 2.320 18.61  1  1    4    1
    4 Hornet 4 Drive      21.4   6  258 110 3.08 3.215 19.44  1  0    3    1
    5 Hornet Sportabout   18.7   8  360 175 3.15 3.440 17.02  0  0    3    2
    6 Valiant             18.1   6  225 105 2.76 3.460 20.22  1  0    3    1
    
    
    st <- m$storage.mode
    
    ## since m is already mmap'd as a binary, we'll use that here - but you'd store this
    m1 <- mmap(attr(m$filedesc, "names"), mode=st, extractFUN=as.data.frame)
    
    head(m1)
                        X  mpg cyl disp  hp drat    wt  qsec vs am gear carb
    1 Mazda RX4           21.0   6  160 110 3.90 2.620 16.46  0  1    4    4
    2 Mazda RX4 Wag       21.0   6  160 110 3.90 2.875 17.02  0  1    4    4
    3 Datsun 710          22.8   4  108  93 3.85 2.320 18.61  1  1    4    1
    4 Hornet 4 Drive      21.4   6  258 110 3.08 3.215 19.44  1  0    3    1
    5 Hornet Sportabout   18.7   8  360 175 3.15 3.440 17.02  0  0    3    2
    6 Valiant             18.1   6  225 105 2.76 3.460 20.22  1  0    3    1
    

    As a previous answer mentions, m$storage.mode is the mode you are needing.

    You could go one step further and store the mode in a file using some naming convention of your devising. You could also create a custom binary object utilizing the len and off args to mmap.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to use recode in R (from the car package) and it is
I'm trying to learn how to use Python's multiprocessing package, but I don't understand
I am learning Django and I am trying to understand the use of models.py
I'm trying to understand how to use firebug to debug my Javascript. So I
I am trying to understand how to use instance variable in Perl OO -
I am trying to understand how to use reference parameters. There are several examples
I'm trying to understand why one would use Spring Batch over a scripting language
I'm trying to understand whether and under what circs one should use Python classes
I am trying to understand my embedded Linux application's memory use. The /proc/pid/maps utility/file
I'm trying to understand amazon php sdk for AWS but I really can't use

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.