Mikhail Beketov
2013-Sep-21 19:30 UTC
[R] Setting a new method for generic function to satisfy "R CMD check"
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? Many thanks in advance! Mikhail [[alternative HTML version deleted]]
Duncan Murdoch
2013-Sep-22 11:25 UTC
[R] Setting a new method for generic function to satisfy "R CMD check"
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