Bart, I think you can do something along these lines:

# create your base class
setClass('ourClass', representation (x = 'numeric'))

# create your stack class
setClass('ourStack', representation (z = 'list'))

if (!isGeneric("stack")) {
setGeneric("stack", function(x, ...)
standardGeneric("stack"))
}

setMethod("stack", signature(x='ourClass'),
function(x, ...) {
x <- c(list(x), list(...))
i <- sapply(x, function(j) inherits(j, 'ourClass'))
if (!all(i)) { warning("removed ", sum(!i), " object(s) not inheriting from
'ourClass'" ) }

s <- new('ourStack')
s@z <- x[i]
return(s)
}
)

a <- new('ourClass', x=10)
b <- new('ourClass', x=15)

s1 <- stack(a,b,a)
s2 <- stack(a,b,10,b,15)


Best, Robert


On Fri, Jun 15, 2012 at 7:44 AM, Bart <bart@njn.nl> wrote:

> Dear list,
>
> Currently I'm developing an r package for movement analysis, it is quite
> heavily based on the raster and sp package. One of the things we want to do
> is combine multiple objects into one combined object, much like stack
> stacks multiple rasters. We thought of using the in raster defined generic
> stack function for ease of use but this poses a problem.
>
> First calling it with a list is not possible since that method is already
> set in the raster package, then i thought about the following way.
>
> setMethod("stack", signature(x='ourClass'), ....
>
> and than call it as following
>
> do.call('stack', list_of_objects_of_our_class)
>
> I think this works in principle fine the problem is that there needs to be
> an argument called x to the call to stack, while our list does not
> necessarily contain this. One way around is removing the names from the
> list but i would like to avoid that also to keep indexing simple.
>
> Is there any other way that we could use the stack function without
> renaming our list?
>
> I hope the problem is a bit clear, thanks in advance
>
> Bart
>
> ______________________________**_________________
> R-sig-Geo mailing list
> R-sig-Geo@r-project.org
> https://stat.ethz.ch/mailman/**listinfo/r-sig-geo<https://stat.ethz.ch/mailman/listinfo/r-sig-geo>
>

	[[alternative HTML version deleted]]

