Re: [Rd] group generics

2009-12-03 Thread Ross Boylan
Thanks for your help.  I had two concerns about using as: that it would
impose some overhead, and that it would require me to code an explicit
conversion function.  I see now that the latter is not true; I don't
know if the overhead makes much difference.

On Thu, 2009-12-03 at 13:00 -0800, Martin Morgan wrote:
 setMethod(Arith, signature(e1=numeric, e2=B), function(e1, e2) {
 new(B, xb=e1...@xb, callGeneric(e1, as(e2, A)))
 })

Things were getting too weird, so I punted and used explicitly named
function calls for the multiplication operation that was causing
trouble.

Ross

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] group generics

2009-12-03 Thread John Chambers
I missed the earlier round of this discussion and only am commenting now 
to say that this doesn't seem weird at all, if I understand what you're 
trying to do.

Martin's basic suggestion,

v - callGeneric(e1, as(e2, A))

seems the simplest solution.

You just want to make another call to the actual generic function, with 
new arguments, and let method selection take place.  In fact, it's 
pretty much the standard way to use group generics. 

John


Ross Boylan wrote:
 Thanks for your help.  I had two concerns about using as: that it would
 impose some overhead, and that it would require me to code an explicit
 conversion function.  I see now that the latter is not true; I don't
 know if the overhead makes much difference.

 On Thu, 2009-12-03 at 13:00 -0800, Martin Morgan wrote:
   
 setMethod(Arith, signature(e1=numeric, e2=B), function(e1, e2) {
 new(B, xb=e1...@xb, callGeneric(e1, as(e2, A)))
 })
 

 Things were getting too weird, so I punted and used explicitly named
 function calls for the multiplication operation that was causing
 trouble.

 Ross

 __
 R-devel@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-devel

   

[[alternative HTML version deleted]]

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] group generics

2009-12-03 Thread Ross Boylan
On Thu, 2009-12-03 at 14:25 -0800, John Chambers wrote:
 I missed the earlier round of this discussion and only am commenting
 now to say that this doesn't seem weird at all, if I understand what
 you're trying to do.
 
 Martin's basic suggestion,
 v - callGeneric(e1, as(e2, A))
 seems the simplest solution.
 
 You just want to make another call to the actual generic function,
 with new arguments, and let method selection take place.  In fact,
 it's pretty much the standard way to use group generics.  
 
 John
There were 2 weird parts.  Mainly I was referring to the fact that
identical code (posted earlier) worked sometimes and not others.  I
could not figure out what the differences were between the 2 scenarios,
nor could I create a non-working scenario reliably.

The second part that seemed weird was that the code looked as if it
should work all the time (the last full version I posted, which used
callNextMethod() rather than callGeneric()).

Finally, I felt somewhat at sea with the group generics, since I wasn't
sure exactly how they worked, how they interacted with primitives, or
how they interacted with callNextMethod, selectMethod, etc.  I did study
what I thought were the relevant help entries.

Ross
 
 
 Ross Boylan wrote: 
  Thanks for your help.  I had two concerns about using as: that it would
  impose some overhead, and that it would require me to code an explicit
  conversion function.  I see now that the latter is not true; I don't
  know if the overhead makes much difference.
  
  On Thu, 2009-12-03 at 13:00 -0800, Martin Morgan wrote:

   setMethod(Arith, signature(e1=numeric, e2=B), function(e1, e2) {
   new(B, xb=e1...@xb, callGeneric(e1, as(e2, A)))
   })
   
  
  Things were getting too weird, so I punted and used explicitly named
  function calls for the multiplication operation that was causing
  trouble.
  
  Ross
  
  __
  R-devel@r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/r-devel
  
 

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] group generics

2009-11-30 Thread Ross Boylan
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1



Martin Morgan wrote:
 Hi Ross -- 
 
 Ross Boylan r...@biostat.ucsf.edu writes:
 
 I have classes A and B, where B contains A.  In the implementation of
 the group generic for B I would like to use the corresponding group
 generic for A.  Is there a way to do that?

 setMethod(Arith, signature(e1=numeric, e2=B), function(e1, e2) {
  # the next line does not work right
   v - selectMethod(callGeneric, signature=c(numeric, A))(e1, e2)
 
 v - callGeneric(e1, as(e2, A))
 
 or probably
 
v - callNextMethod(e1, e2)
 
 Martin

A different error this time, one that looks a lot like the report from
stephen.p...@ubs.com on 2007-12-24 concerning callNextMethod:, except
this is with
callGeneric.

HOWEVER, the problem is erratic; when I started from scratch and took
this code into a workspace and executed the commands, they worked as
expected.  I had various false starts and revisions, as well as the real
code on which the example is based, when the error occurred.  I tried
taking in the real code (which defines generics with Arith from my
actual classes, and which also fails as below), and the example still
worked.


My revised code:

setClass(A,
 representation=representation(xa=numeric)
 )

setMethod(Arith, signature(e1=numeric, e2=A), function(e1, e2) {
  new(A, xa=callGeneric(e1, e...@xa))
}
 )

setClass(B,
 representation=representation(xb=numeric),
 contains=c(A)
 )

setMethod(Arith, signature(e1=numeric, e2=B), function(e1, e2) {
  new(B, xb=e1...@xb, callNextMethod())
}
)

Results:
 options(error=recover)
 tb - new(B, xb=1:3, new(A, xa=10))
 3*tb
Error in get(fname, envir = envir) : object '.nextMethod' not found

Enter a frame number, or 0 to exit

 1: 3 * tb
 2: 3 * tb
 3: test.R#16: new(B, xb = e1 * e...@xb, callNextMethod())
 4: initialize(value, ...)
 5: initialize(value, ...)
 6: callNextMethod()
 7: .nextMethod(e1 = e1, e2 = e2)
 8: test.R#6: new(A, xa = callGeneric(e1, e...@xa))
 9: initialize(value, ...)
10: initialize(value, ...)
11: callGeneric(e1, e...@xa)
12: get(fname, envir = envir)

Selection: 0

The callGeneric in frame 11 is trying to get the primitive for
multiplying numeric times numeric.  Quoting from Pope's analysis:
[The primitive...]
 does not get the various magic variables such as .Generic, .Method,
 etc. defined in its frame. Thus, callGeneric() fails when, failing to
 find .Generic then takes the function symbol for the call (which
 callNextMethod() has constructed to be .nextMethod) and attempts to
 look it up, which of course also fails, leading to the resulting error
 seen above.

I'm baffled, and hoping someone on the list has an idea.
I'm running R 2.10 under ESS (in particular, I use c-c c-l in the code
file to read in the code) on XP.
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAksUTcQACgkQTEwcvZWfjMgEdwCfYt/bmsXG76rq3BpbByBYNjLY
ubsAoKnBnBMbd+OlBL2YOg3vWslL35Zg
=D58x
-END PGP SIGNATURE-

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] group generics

2009-11-25 Thread Martin Morgan
Hi Ross -- 

Ross Boylan r...@biostat.ucsf.edu writes:

 I have classes A and B, where B contains A.  In the implementation of
 the group generic for B I would like to use the corresponding group
 generic for A.  Is there a way to do that?

 I would also appreciate any comments if what I'm trying to do seems like
 the wrong approach.

 Here's a stripped down example:
 setClass(A,
  representation=representation(xa=numeric)
  )

 setMethod(Arith, signature(e1=numeric, e2=A), function(e1, e2) {
   new(A, ax=e1...@xa)

typo, I guess, xa = e1...

 }
   )

 setClass(B,
  representation=representation(xb=numeric),
  contains=c(A)
  )

 setMethod(Arith, signature(e1=numeric, e2=B), function(e1, e2) {
   # the next line does not work right
   v - selectMethod(callGeneric, signature=c(numeric, A))(e1, e2)

v - callGeneric(e1, as(e2, A))

or probably

   v - callNextMethod(e1, e2)

Martin

   print(v)
   new(B, v, xb=e1...@xb)
 }
 )


 Results:
 t1 - new(B, new(A, xa=4), xb=2)
 t1
 An object of class “B”
 Slot xb:
 [1] 2

 Slot xa:
 [1] 4

 3*t1
 Error in getGeneric(f, !optional) : 
   no generic function found for callGeneric

 Thanks.
 Ross Boylan

 __
 R-devel@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-devel

-- 
Martin Morgan
Computational Biology / Fred Hutchinson Cancer Research Center
1100 Fairview Ave. N.
PO Box 19024 Seattle, WA 98109

Location: Arnold Building M1 B861
Phone: (206) 667-2793

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


[Rd] group generics

2009-11-24 Thread Ross Boylan
I have classes A and B, where B contains A.  In the implementation of
the group generic for B I would like to use the corresponding group
generic for A.  Is there a way to do that?

I would also appreciate any comments if what I'm trying to do seems like
the wrong approach.

Here's a stripped down example:
setClass(A,
 representation=representation(xa=numeric)
 )

setMethod(Arith, signature(e1=numeric, e2=A), function(e1, e2) {
  new(A, ax=e1...@xa)
}
  )

setClass(B,
 representation=representation(xb=numeric),
 contains=c(A)
 )

setMethod(Arith, signature(e1=numeric, e2=B), function(e1, e2) {
# the next line does not work right
  v - selectMethod(callGeneric, signature=c(numeric, A))(e1, e2)
  print(v)
  new(B, v, xb=e1...@xb)
}
)


Results:
 t1 - new(B, new(A, xa=4), xb=2)
 t1
An object of class “B”
Slot xb:
[1] 2

Slot xa:
[1] 4

 3*t1
Error in getGeneric(f, !optional) : 
  no generic function found for callGeneric

Thanks.
Ross Boylan

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel