[Rd] override pmin/pmax for my own matrix

2015-12-24 Thread Da Zheng
Hello,

I'm trying to override pmin and pmax for my own matrix. These two
functions have ... as an argument. I tried to override them as
follows:
setMethod("pmax", class_name, function(x, ..., na.rm) { ... })

I use this way to override primitive functions such as min/max and it
works fine.
But it doesn't work for pmin and pmax. I guess because they are
regular functions?
How do I override a regular function with ... as an argument?

Thanks,
Da

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


Re: [Rd] override pmin/pmax for my own matrix

2015-12-24 Thread Michael Lawrence
Yes, functions like c, min and max are special cases, as they are
primitives. For ordinary functions, you just need to promote them with
"..." as the signature:

setGeneric("pmax", signature="...")
setMethod("pmax", "Class", function(..., na.rm=FALSE) { })

One caveat is that all arguments passed via "..." must derive from the
class specified for "..." in the method signature. At some point we
should solve that by introducing a binary pmin2, pmax2 as we have for
cbind and rbind.


On Thu, Dec 24, 2015 at 5:54 AM, Da Zheng  wrote:
> Hello,
>
> I'm trying to override pmin and pmax for my own matrix. These two
> functions have ... as an argument. I tried to override them as
> follows:
> setMethod("pmax", class_name, function(x, ..., na.rm) { ... })
>
> I use this way to override primitive functions such as min/max and it
> works fine.
> But it doesn't work for pmin and pmax. I guess because they are
> regular functions?
> How do I override a regular function with ... as an argument?
>
> Thanks,
> Da
>
> __
> 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] override pmin/pmax for my own matrix

2015-12-24 Thread Da Zheng
Thank you. It works!

On Thu, Dec 24, 2015 at 9:08 AM, Michael Lawrence
 wrote:
> Yes, functions like c, min and max are special cases, as they are
> primitives. For ordinary functions, you just need to promote them with
> "..." as the signature:
>
> setGeneric("pmax", signature="...")
> setMethod("pmax", "Class", function(..., na.rm=FALSE) { })
>
> One caveat is that all arguments passed via "..." must derive from the
> class specified for "..." in the method signature. At some point we
> should solve that by introducing a binary pmin2, pmax2 as we have for
> cbind and rbind.
>
>
> On Thu, Dec 24, 2015 at 5:54 AM, Da Zheng  wrote:
>> Hello,
>>
>> I'm trying to override pmin and pmax for my own matrix. These two
>> functions have ... as an argument. I tried to override them as
>> follows:
>> setMethod("pmax", class_name, function(x, ..., na.rm) { ... })
>>
>> I use this way to override primitive functions such as min/max and it
>> works fine.
>> But it doesn't work for pmin and pmax. I guess because they are
>> regular functions?
>> How do I override a regular function with ... as an argument?
>>
>> Thanks,
>> Da
>>
>> __
>> 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