[R] checking generic/method consistency

Henrik Bengtsson hb at maths.lth.se
Fri Sep 26 17:43:00 CEST 2003


Hi, it looks from the names of your argument that your function is a
"plain function", i.e. it is not a function specific to a class. If this
is true, I would avoid the period and rename your function to

  solveLP <- function(cvec, bvec, Amat, maximum, maxiter, verbose) ...

Under the S3 style of programming with classes methods coupled to
classes are written in the format

  method.class <- function(object, arg1, arg2, ...

That is, the part before the period is the name of a generic function
and the part after is the name of the class. This is why R CMD check
believe your that you have written a method 'solve' for class 'LP'. All
methods named 'solve' should have a argument signature that match the
generic function 'solve' and your solve.LP doesn't. I do not think this
was your intention, correct? See help.start() -> "R Language Definition"
-> "Object-oriented programming:" for more details about the S3 style. 

To avoid problems like these I am working on a R Coding Conventions
(RCC), http://www.maths.lth.se/help/R/RCC/ (see Naming Conventions). It
is an early version and not everyone agrees with it, but the intention
is to find a style that avoid problems like yours, where it says that
you should avoid periods in function names except if you use it for S3
class methods. Feedback is appreciated.

Cheers

Henrik Bengtsson
Lund University



> -----Original Message-----
> From: r-help-bounces at stat.math.ethz.ch 
> [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Arne Henningsen
> Sent: den 26 september 2003 17:03
> To: r-help at stat.math.ethz.ch
> Subject: [R] checking generic/method consistency
> 
> 
> Hi,
> 
> I wrote a package for linear programming and want to submit 
> it to CRAN. 
> Since the package 'quadprog' has a function with the name 
> 'solve.QP' to 
> perform Quadratic Programming, I named my (main) function 'solve.LP'. 
> However 'R CMD check' gives one warning:
> 
> * checking generic/method consistency ... WARNING
> solve:
>   function(a, b, ...)
> solve.LP:
>   function(cvec, bvec, Amat, maximum, maxiter, verbose)
> 
> while 'R CMD check' gives no warnings when the function has the name 
> 'solve.QP'.
> 
> What do you recommend me to do?
> 1) Ignore the warning and upload the package to CRAN as it is?
> 2) Rename the function? (any suggestions?)
> 3) Change something that avoids this problem without renaming 
> the functions?
> 
> I would prefer the third point, but I don't know how.
> 
> Thank you for your answers,
> 
> Arne
> 
> -- 
> Arne Henningsen
> Department of Agricultural Economics 
> Christian-Albrechts-University Kiel 24098 Kiel, Germany
> Tel: +49-431-880-4445
> Fax: +49-431-880-1397 
> ahenningsen at email.uni-kiel.de 
> http://www.uni-> kiel.de/agrarpol/ahenningsen.html
> 
> 
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list 
> https://www.stat.math.ethz.ch/mailman/listinfo> /r-help
> 
>




More information about the R-help mailing list