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
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
Thank you. It works! On Thu, Dec 24, 2015 at 9:08 AM, Michael Lawrence <lawrence.michael at gene.com> 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 <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