Dear R-devel,

I've created an S4 class called "range.vec", which is meant to hold a
sequence of numbers, like one you would create using seq(). I'm trying to
only store a chunk of the sequence at any given time, to save memory. this
means that my class has slots for start, end, and step, as well as a cached
chunk slot and a slot for where the chunk is indexed within the complete
sequence vector.

I have functional get() and set() methods for chunking, along with '[',
'length', '[[', and 'el', and the class inherits from "numeric". However,
when I try to use a numeric method like 'mean', the function returns NaN
(other numeric methods output different errors).

>From debugging, I've learned that methods like "mean" are successfully
accessing my range.vec methods, but since there is no data stored in .Data,
the functions can't run correctly. I want the numeric methods to use my
chunking functions to access the data, but even after extensive searching
(Green/Blue books, WRE, R internals, and other S4 resources), I haven't
figured out how to use .Data to point to a function, or more generally, how
to get numeric methods to work with my class. Any pointers or suggestions
would be greatly appreciated. Thanks!

Note: I’m running R 2.15.1 on Windows XP from a binary.

Thanks,

Liz Sander
Microstrain
Williston, VT

setClass("range.vec",
    representation(start = "numeric",
    end = "numeric",
    step = "numeric",
    chunk = "numeric",
    chunkpos = "numeric"),
    contains="numeric"  #so that it inherits from ‘vector’ without assuming
logical data
)

setGeneric("set.chunk", function(x,...) standardGeneric("set.chunk"))
setMethod("set.chunk",
    signature(x = "range.vec"),
    function (x, chunksize=100, chunkpos=1)
    {
    #This function extracts a chunk of data from the range.vec object.
        begin <- x@start + (chunkpos - 1)*x@step
        end <- x@start + (chunkpos + chunksize - 2)*x@step
        data <- seq(begin, end, x@step) #calculate values in data chunk

        #get rid of out-of-bounds values
        data[data > x@end] <- NA

        x@chunk <- data
        x@chunkpos <- chunkpos
        return(x)
    }
    }
)

        [[alternative HTML version deleted]]

______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel

Reply via email to