From lawrence.michael at gene.com  Thu Dec 24 15:08:54 2015
From: lawrence.michael at gene.com (Michael Lawrence)
Date: Thu, 24 Dec 2015 06:08:54 -0800
Subject: [Rd] override pmin/pmax for my own matrix
In-Reply-To: <CAFLer83+2DvP9dvcB7nfTreKodLknoDdKOKTSaTyp6YmQSdtmA@mail.gmail.com>
References: <CAFLer83+2DvP9dvcB7nfTreKodLknoDdKOKTSaTyp6YmQSdtmA@mail.gmail.com>
Message-ID: <CAOQ5NyfkOaXGbXjNLXgBPm80k_NbzOrCFeF4sibPhwz3+j5sEA@mail.gmail.com>

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 <zhengda1936 at gmail.com> 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 at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel



[Rd] override pmin/pmax for my own matrix
Michael Lawrence