Mobile Monitoring Solutions

Close this search box.

ff and Too-Big-for-Memory Data in R — Part III

MMS Founder

Article originally posted on Data Science Central. Visit Data Science Central

After my last blog on the use of relational databases PostgreSQL and MonetDB to help compensate for R’s RAM limitations, I received an email from a reader who asked if I’d ever used the R ff/ffbase packages to the same end. I had a little experience, but a long time ago.

ff addresses R’s memory limit by providing “data structures that are stored on disk but behave (almost) as if they were in RAM by transparently mapping only a section (pagesize) in main memory – the effective virtual memory consumption per ff object………Beyond basic access functions, the ff package also provides compatibility functions that facilitate writing code for ff and ram objects and support for batch processing on ff objects (e.g. as.ram, as.ff, ffapply).”

The R developer can do an awful lot with ff/ffbase functions. Many perform identically to their memory counterparts. In addition, there are a host of ff-only functions that expand ff’s capabilities for out-of-memory data. Alas, there are no analogs for some important in-memory data munging and modeling tools — ultimately forcing the developer to fend for herself with many tasks.

That email prompted the question of whether ff/ffbase might be able to assume a similar function for me as does MonetDB: to store the larger-than-RAM data in files that can efficiently “serve” on-demand subsets to R data.tables/data.frames. So I decided to give ff a shot using the flights data of 113670794 rows and 111 columns that’s such a favorite with R developers.

I ended up using the fst files I built for that analysis as the data loading points of departure, ultimately binding 6 temporary data.frames into an ff data structure. I then developed a few functions to build meta data and to generate subsetted data.tables without first having to return all the data.

The approach is to “decompose” the larger ff structure query into “where” attributes and “select” attributes. I then identify the row numbers of those records that satisfy the where clause and finally build a data.table of the select columns pre-subsetted by the where row numbers.

What follows is example code. The technology used is Microsoft Open R 3.4.4 with Jupyterlab Beta.

Read the remainder of the blog here.

Subscribe for MMS Newsletter

By signing up, you will receive updates about our latest information.

  • This field is for validation purposes and should be left unchanged.