[R] callNextMethod with dots argument

2013-09-19 Thread Kiên Kiêu

Hi,

I met a problem when invoking callNextMethod within a method associated 
with a generic function taking ... as an argument.


Here is the code

setClass(Aparent,representation(x=numeric,y=numeric))
setClass(Achild,contains=Aparent)

setGeneric(do,def=function(a,...) standardGeneric(do))
setMethod(do,signature(a=Aparent),
  function(a,msg) {
print(do Aparent)
  })
setMethod(do,signature(a=Achild),
  function(a,msg)  {
print(do Achild)
callNextMethod()
  })

myA - new(Achild)
buf - do(a=myA)   # works
buf - do(a=myA,msg=bonjour) # error

The last call yields the following error message:

Error in callNextMethod() :
  in processing 'callNextMethod', found a '...' in the matched call, 
but no corresponding '...' argument


which I do not understand. Replacing ... by msg in setGeneric makes 
it work. But I don't like this limitation so much (unless I understand it).


Regards.

Kien

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] callNextMethod with dots argument

2013-09-19 Thread Simon Zehnder
Kien,

if you want to add variables in a function definition that is predefined by a 
Generic and calls CallNextMethod you have to add the '…' argument as well.

 setMethod(do,signature(a=Achild),
  function(a,msg,...)  {
print(do Achild)
callNextMethod()
  })

Best

Simon

On Sep 19, 2013, at 8:58 AM, Kiên Kiêu kien.k...@jouy.inra.fr wrote:

 Hi,
 
 I met a problem when invoking callNextMethod within a method associated with 
 a generic function taking ... as an argument.
 
 Here is the code
 
 setClass(Aparent,representation(x=numeric,y=numeric))
 setClass(Achild,contains=Aparent)
 
 setGeneric(do,def=function(a,...) standardGeneric(do))
 setMethod(do,signature(a=Aparent),
  function(a,msg) {
print(do Aparent)
  })
 setMethod(do,signature(a=Achild),
  function(a,msg)  {
print(do Achild)
callNextMethod()
  })
 
 myA - new(Achild)
 buf - do(a=myA)   # works
 buf - do(a=myA,msg=bonjour) # error
 
 The last call yields the following error message:
 
 Error in callNextMethod() :
  in processing 'callNextMethod', found a '...' in the matched call, but no 
 corresponding '...' argument
 
 which I do not understand. Replacing ... by msg in setGeneric makes it 
 work. But I don't like this limitation so much (unless I understand it).
 
 Regards.
 
 Kien
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.