[R] Setting a new method for generic function to satisfy "R CMD check"

Duncan Murdoch murdoch.duncan at gmail.com
Sun Sep 22 13:25:28 CEST 2013


On 13-09-21 3:30 PM, Mikhail Beketov wrote:
> Dear All,
>
> Can somebody explain me how to correctly set a new class-specific method
> for generic functions (e.g. for "plot", "summary" and "print"). I simply
> programmed these functions with the class names and it works perfectly.
> E.g.:
>
> x<-2
> y<-3
> class(x)<-"newclass"
> class(y)<-"newclass"
> print.newclass<-function(x){ cat(x*10) }
> print(x)
> print(y)
>
> However, I need the new methods for a new package, and the "R CMD check"
> gives me warnings that my approach is not correct. I have to define
> "methods" and do not use full names as "print.newclass".
> I read the "Writing R Extensions" and it is not explained there (at least
> to such level that I could get it) and I didn't get anything understandable
> by googling.
>
> Maybe someone can help me?

You need to declare methods in the NAMESPACE file, and there is special 
markup for them in Rd files.

Duncan Murdoch



More information about the R-help mailing list