Hi section 6.1 of R-exts suggests that a package can take over a function in the base package and make it generic. I want to do this with Re() and have the following lines in my R code: "Re" <- function(x){UseMethod("Re" )} "Re.default" <- get("Re" ,pos=NULL,mode="function") "Re.octonion" <- function(x){give.comp(x,1)} This, however, generates the following warning from R CMD check: * checking S3 generic/method consistency ... WARNING Re: function(x) Re.default: function() See section 'Generic functions and methods' of the 'Writing R Extensions' manual. I can suppress the warning by commenting out the first line. Is this a sensible thing to do? -- Robin Hankin Uncertainty Analyst National Oceanography Centre, Southampton European Way, Southampton SO14 3ZH, UK tel 023-8059-7743
Henrik Bengtsson
2005-Sep-01 14:31 UTC
[Rd] generic function S3 consistency warning advice
This happens because you get a primitive function. However, I believe Re() is already an generic function ("too") internally, so you do not have to create your own and redefine the default one. (I'm not sure if there is another way to tell if a primitive function is also a generic function than to look at the C source code or by trial-and-error). Try: % R --vanilla > Re.MyClass <- function(x) NA > x <- structure(3, class="MyClass") > Re(5+3i) 5 > Re(x) NA /Henrik Robin Hankin wrote:> Hi > > section 6.1 of R-exts suggests that a package can take over a > function in the base > package and make it generic. > > I want to do this with Re() and have the following lines in my R code: > > > > "Re" <- function(x){UseMethod("Re" )} > "Re.default" <- get("Re" ,pos=NULL,mode="function") > "Re.octonion" <- function(x){give.comp(x,1)} > > This, however, generates the following warning from R CMD check: > > * checking S3 generic/method consistency ... WARNING > Re: > function(x) > Re.default: > function() > > See section 'Generic functions and methods' of the 'Writing R > Extensions' > manual. > > > > I can suppress the warning by commenting out the first line. Is this a > sensible thing to do? > > > > > -- > Robin Hankin > Uncertainty Analyst > National Oceanography Centre, Southampton > European Way, Southampton SO14 3ZH, UK > tel 023-8059-7743 > > ______________________________________________ > R-devel at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel > >