[Rd] S4 class for chunked data that inherits from numeric- numeric methods won't work

From: Elizabeth Sander <elsander_at_microstrain.com>
Date: Mon, 02 Jul 2012 09:45:46 -0400


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_at_start + (chunkpos - 1)*x_at_step
        end <- x_at_start + (chunkpos + chunksize - 2)*x_at_step
        data <- seq(begin, end, x_at_step) #calculate values in data chunk

        #get rid of out-of-bounds values
        data[data > x_at_end] <- NA

        x_at_chunk <- data
        x_at_chunkpos <- chunkpos
        return(x)

    }
    }
)

        [[alternative HTML version deleted]]



R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Mon 02 Jul 2012 - 21:20:35 GMT

This quarter's messages: by month, or sorted: [ by date ] [ by thread ] [ by subject ] [ by author ]

All messages

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 03 Jul 2012 - 07:10:31 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.

list of date sections of archive