[R] need some help with this example
Glenn Schultz
glennmschultz at me.com
Tue Oct 29 01:05:08 CET 2013
I have a class Details that contains information needed by FirstSet to do some calculations then a super class that returns Details and FirstSet. The problem seems to be in FirstSet where I use the function getAnumber(id).
setClass("Details",
representation(
ID = "character",
Anumber = "numeric"))
setGeneric("Details",
def = function(object){standardGeneric("Details")})
setMethod("initialize",
signature(.Object = "Details"),
function(.Object, ID = "character", Anumber = numeric()){
.Object at ID = ID
.Object at Anumber = 2
return(.Object)
})
# getter for A number
setGeneric("getAnumber", function(object){standardGeneric("getAnumber")})
setMethod("getAnumber","Details",
function(object){return(Object at Anumber)})
setClass("FirstSet",
representation(
Anothernumber = "numeric"))
setGeneric(
name = "FirstSet",
def = function(object){standardGeneric("FirstSet")}
)
setMethod("initialize",
signature(.Object = "FirstSet"),
function (.Object, id = "character", multiplier = numeric())
{ x = getAnumber(id)
y = x * multiplier
.Object at Anothernumber = y
return(.Object)
}
)
setClass("Super", contains = c("Details", "FirstSet"))
setGeneric("Super",
def = function(object){standardGeneric("Super")})
setMethod("initialize",
signature(.Object = "Super"),
function(.Object, id = "character", Anumber = Anumber()){
Details<- new("Details", ID = id, Anumber = number)
FirstSet <- new("FirstSet", Anothernumber = Anothernumber)
Super <- new("Super", Details, FirstSet)
return(.Object)
})
More information about the R-help
mailing list