I am currently creating a new S4 class which uses a S3 zoo object. I can create a class
setClass("rollingSD", slot = c(rollPeriod = "numeric", tsOutput = "zoo"))
riskSD <- new("rollingSD")
riskSD <- new("rollingSD", rollPeriod = 12)
Error in validObject(.Object) :
invalid class “rollingSD” object: invalid object for slot "tsOutput" in class
"rollingSD": got class "S4", should be or extend class "zoo"
The problem is caused because R's class mechanism doesn't know how to make a new
zoo object. You can fix this by specifying a "prototype":
setClass( "rollingSD", slot = c(rollPeriod = "numeric", tsOutput = "zoo"), prototype=prototype( tsOutput=some_zoo_object ) )
some_zoo_object is of class
zoo. The default prototype for a
numeric slot is
numeric(), but because you defined the (S4) class
zoo yourself, the default is
new("zoo") and this isn't defined.