Accessing Frame Data Frame columns in R mmap objects

I am trying to pass some code to use the mmap package. I am having a problem accessing data frame columns.

I would like to be able to access data columns with the $ and [[ . Here are the results I get.

 > foo <- as.mmap(mtcars) > foo[,'mpg'] # works mpg 1 21.0 2 21.0 3 22.8 4 21.4 5 18.7 ... > foo$mpg #does not work NULL > foo[['mpg']] #also does not work NULL > foo[]$mpg #works ... > foo[][['mpg']] #also works ... 

Is there a way to get the $ and [[ operators to work with an object with memory mapping, as it would on a regular data frame?

Edit: At the suggestion of Joshua, I added a function for [[

 `[[.mmap` <- function(x,...) `[[`(x[],...) 

And for $ , which doesn't look particularly elegant, but seems to work.

 > `$.mmap` <- function(x,...) { if (...%in%c("storage.mode","bytes","extractFUN","filedesc")){ get(...,envir=x) }else { eval(call('$',x[],substitute(...))) }} 
+6
source share
1 answer

These functions do not work because they do not have a mmap method.

 > grep("mmap",methods("["),value=TRUE) [1] "[.mmap" > grep("mmap",methods("[["),value=TRUE) character(0) > grep("mmap",methods("$"),value=TRUE) character(0) 

Therefore, they send default methods that have no idea how to handle the mmap object. You need to write mmap methods for [[ and $ .

+2
source

Source: https://habr.com/ru/post/905230/


All Articles