From maechler at stat.math.ethz.ch  Thu Sep  7 15:01:51 2006
From: maechler at stat.math.ethz.ch (Martin Maechler)
Date: Thu, 7 Sep 2006 15:01:51 +0200
Subject: [Rd] setMethod("c") [was: setMethod("Summary")]
In-Reply-To: <5C9927A0-281D-4FD6-BE3B-EC3FB9B22713@soc.soton.ac.uk>
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>
	<528BF1A2-3961-454D-B32C-FEE1F756BBBD@soc.soton.ac.uk>
	<44FD978C.9020208@r-project.org> <44FD9C12.70705@r-project.org>
	<95EB4180-77B6-41FC-9897-FDA61185BFE4@soc.soton.ac.uk>
	<44FF0622.50705@r-project.org>
	<5C9927A0-281D-4FD6-BE3B-EC3FB9B22713@soc.soton.ac.uk>
Message-ID: <17664.6207.726759.686976@stat.math.ethz.ch>

>>>>> "Robin" == Robin Hankin <r.hankin at noc.soton.ac.uk>
>>>>>     on Thu, 7 Sep 2006 12:18:51 +0100 writes:

    Robin> Thank you for this.   Minimal self-contained code included below.
    Robin> It is slightly modified from the original because brob objects have two
    Robin> slots, both of which are needed by c().

    Robin> [
    Robin> A "brob" obect is represents a real number with two slots: "x"  holds  
    Robin> its natural
    Robin> logarithm; slot "positive" is Boolean, indicating whether the number  
    Robin> is positive.
    Robin> I want this because I need to manipulate numbers up to ~1e20000.
    Robin> The hard bit is addition:  log(exp(x) + exp(y)) == x + log1p(exp(y-x))
    Robin> ]

I know and I really like your idea.
However....

    Robin> It seemed to make sense to coerce non-brob arguments to brobs,
    Robin> then make cPair() use cPairOfBrobs() [with coerced arguments] in
    Robin> three of the cases, and c() for the fourth with signature c("ANY",  
    Robin> "ANY").

    Robin> Now below, JC states that  "cWithMethods() _replaces_ the ordinary c 
    Robin> (), it's not
    Robin> just a method for it".  Does this imply that one cannot  set up an R  
    Robin> package
    Robin> so that the following code:

    Robin> x <- as.brob(1:10)
    Robin> x1 <- c(1,x)
    Robin> x2 <- c(x,1)

    Robin> works as expected?  

No. There's no way {which does not break much other R code} currently.
More than two days ago, 
I had told you (and the R-devel readers) that you should look at
   help(cbind2)  {and said why}.
If you *really* look at it, and then 
think about or better study the code underlying
the      methods:::bind_activation(TRUE)
kludge,
you will shudder (and run :-) and probably understand that a
similar kludge for c() is not appropriate.

    Robin> Or is there some workaround that would enable me to do this?

well, yes: As John Chambers has tried to say, you have to teach
your users to use  cWithPairs() or c2() or myC() or c.() or any
reasonable name,  but not c().

Martin




[Rd] setMethod("c") [was: setMethod("Summary")]
Martin Maechler