From r.hankin at noc.soton.ac.uk  Tue Sep  5 16:48:53 2006
From: r.hankin at noc.soton.ac.uk (Robin Hankin)
Date: Tue, 5 Sep 2006 15:48:53 +0100
Subject: [Rd] setMethod("c") [was: setMethod("Summary")]
In-Reply-To: <17661.14016.528539.481357@stat.math.ethz.ch>
References: <C7B9E5CB-E340-445D-A5B9-FC86AB6CC1DE@soc.soton.ac.uk>
	<C4E5D78B-28AB-4A25-8112-3668F31444E4@mac.com>
	<E28E6E71-5DD8-4B38-81C9-BB6014F6C16E@soc.soton.ac.uk>
	<17661.14016.528539.481357@stat.math.ethz.ch>
Message-ID: <528BF1A2-3961-454D-B32C-FEE1F756BBBD@soc.soton.ac.uk>

Hello everybody.

I didn't see Franklin's first message; sorry.

Bearing in mind Professor Ripley's comments
on the efficiency of S4 vs S3, I'm beginning to think I
  should just stick with S3 methods for my brob objects.  After
all, S3 was perfectly adequate for the onion package.

Notwithstanding that,  here's my next problem.  I want to define a
brob method for "c".  Using the example in package "arules" as a
template (I couldn't see one in Matrix), I have


setClass("brob",
          representation = representation 
(x="numeric",positive="logical"),
          prototype      = list(x=numeric(),positive=logical())
          )

"brob" <- function(x,positive){
   if(missing(positive)){
     positive <- rep(TRUE,length(x))
   }
   if(length(positive)==1){
     positive <- rep(positive,length(x))
   }
   new("brob",x=x,positive=positive)
}

setGeneric("getX",function(x){standardGeneric("getX")})
setGeneric("getP",function(x){standardGeneric("getP")})
setMethod("getX","brob",function(x){x at x})
setMethod("getP","brob",function(x){x at positive})


setMethod("c",signature(x="brob"),
           function(x, ..., recursive=FALSE){
             xx <- x at x
             xpos <- x at positive
             z <- list(...)
             return(
                    brob(
                         c(xx,do.call("c",lapply(z,getX))),
                         c(xpos,do.call("c",lapply(z,getP)))
                         )
                    )
           }
           )




Now,  this works for something like

 > x <- new("brob",x=pi,positive=T)
 > c(x,x)

but c(1,x) isn't dispatched to my function.  How to
deal cleanly with this case?   Perhaps if any argument
to c() is a brob object, I would like to coerce them all to brobs.
Is this possible?













--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743




[Rd] setMethod("c") [was: setMethod("Summary")]
Robin Hankin