[R] checking generic/method consistency

Arne Henningsen ahenningsen at email.uni-kiel.de
Tue Sep 30 14:18:11 CEST 2003


Hi *,

thanks for all your answers and discussions. And additionally special thanks 
to Henrik Bengtsson for writing the first draft of the "R Coding 
Conventions". I think that this document contains a lot of good ideas to make 
the code more readable. Since my package is *new* code, I adjusted it 
according to most recommendations of the RCC.

However, one thing is still unclear to me: According to the RCC I gave the 
class of result of my function "linProg" also the name "linProg", but the RCC 
says that classes must start with uppercase, while functions must start with 
lowercase, which is contradictory in this case. In one of the examples of the 
RCC, a function that returns an object with a class attribute starts with 
uppercase:
> Line <- function(x0, y0, x1, y1) {
>   line <- list(x=c(x0,y0), y=(x1,y1));
>   class(line) <- "Line";
>   line;
> }
Does this mean that the names of these functions should start with uppercase?

Best wishes,
Arne


On Friday 26 September 2003 17:43, you wrote:
> 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

-- 
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/




More information about the R-help mailing list