Hello, I have a simple class that looks like:

setClass("statisticInfo",
        representation( max = "numeric",
                        min = "numeric",
                        beg = "numeric",
                        current = "numeric",
                        avg = "numeric",
                        obs = "vector"
                       )
         )

and the following function

updateStatistic <- function(statistic, newData){
    statistic@obs = c(statistic@obs, newData)
    statistic@max = max(newData, statistic@max, na.rm=T)
    statistic@min = min(newData, statistic@min, na.rm=T)
    statistic@avg = mean(statistic@obs)
    statistic@current = newData
    if(length(statistic@obs)==1 || is.na(statistic@beg)){
        statistic@beg = newData
    }
    return(statistic)
}

Firstly,

I know you can use methods which seems to add some value. I looked at
http://developer.r-project.org/methodDefinition.html but I try

setMethod("update", signature(statistic="statisticInfo", newData="numeric"),

function(statistic, newData){
    statistic@obs = c(statistic@obs, newData)
    statistic@max = max(newData, statistic@max, na.rm=T)
    statistic@min = min(newData, statistic@min, na.rm=T)
    statistic@avg = mean(statistic@obs)
    statistic@current = newData
    if(length(statistic@obs)==1 || is.na(statistic@beg)){
        statistic@beg = newData
    }
    return(statistic)
}
)

Creating a new generic function for "update" in ".GlobalEnv"
Error in match.call(fmatch, fcall) :
  unused argument(s) (statistic = "statisticInfo", newData = "numeric")
 1: source("tca.init.R", chdir = T)
 2: eval.with.vis(ei, envir)
 3: eval.with.vis(expr, envir, enclos)
 4: source("../../studies/tca.tradeClassifyFuncs.R")
 5: eval.with.vis(ei, envir)
 6: eval.with.vis(expr, envir, enclos)
 7: setMethod("update", signature(statistic = "statisticInfo", newData =
"numeric"), function(statistic, newData) {
 8: isSealedMethod(f, signature, fdef, where = where)
 9: getMethod(f, signature, optional = TRUE, where = where, fdef = fGen)
10: matchSignature(signature, f

I don't understand this any help would be appreciated.

Secondly, can anyone give any examples of where methods are used that makes
sense besides just checking the class inputs?

Thirdly, I've looked into passing by reference in R, and some options come
up, but in general they seem to be fairly complicated.

I would like update to work more like my update function to work without
having to return a a new object.

Something like
> statList = list(new("statisticInfo"))
> updateStatistic(statList[[1]],3)
> statList[[1]]

#this would then have the updated one and not the old one.

Anyways,
The main reason I'm asking these questions is because I can't really find a
good online resource for this. Any help would be greatly appreciated.

Thanks,
Rob

	[[alternative HTML version deleted]]

