[Rd] "Default" accessor in S4 classes
Chris Jewell
chris.jewell at warwick.ac.uk
Tue Jan 8 00:23:31 CET 2013
Hi All,
I'm currently trying to write an S4 class that mimics a data.frame, but stores data on disc in HDF5 format. The idea is that the dataset is likely to be too large to fit into a standard desktop machine, and by using subscripts, the user may load bits of the dataset at a time. eg:
> myLargeData <- LargeData("/path/to/file")
> mySubSet <- myLargeData[1:10, seq(1,15,by=3)]
I've therefore defined by LargeData class thus
> LargeData <- setClass("LargeData", representation(filename="character"))
> setMethod("initialize","LargeData", function(.Object,filename) .Object at filename <- filename)
I've then defined the "[" method to call a C++ function (Rcpp), opening the HDF5 file, and returning the required rows/cols as a data.frame.
However, what if the user wants to load the entire dataset into memory? Which method do I overload to achieve the following?
> fullData <- myLargeData
> class(fullData)
[1] "data.frame"
or apply transformations:
> myEigen <- eigen(myLargeData)
In C++ I would normally overload the "double" or "float" operator to achieve this -- can I do the same thing in R?
Thanks,
Chris
More information about the R-devel
mailing list