From chris.jewell at warwick.ac.uk  Tue Jan  8 00:23:31 2013
From: chris.jewell at warwick.ac.uk (Chris Jewell)
Date: Tue, 8 Jan 2013 12:23:31 +1300
Subject: [Rd] "Default" accessor in S4 classes
In-Reply-To: <50E5D72E.5010704@r-project.org>
References: <50E5D72E.5010704@r-project.org>
Message-ID: <35A75ECB-EDAD-4FCA-A6D6-4CBD69A163EF@warwick.ac.uk>

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



[Rd] "Default" accessor in S4 classes
Chris Jewell