generic function argument list problem
On Wed, 2005-08-31 at 08:09 +0100, Robin Hankin wrote:
Hi
it says in R-exts that
A method must have all the arguments of the generic,
including ... if the generic does.
A method must have arguments in exactly the same order as the
generic.
A method should use the same defaults as the generic.
So, how come the arguments for rep() are (x, times, ...) and the
arguments
for rep.default() are (x, times, length.out, each, ...) ?
Shouldn't
these be the same? I am writing a rep() method for objects with class "octonion", and my function rep.octonion() has argument list (x, times, length.out, each, ...) just like rep.default(), but R CMD check complains about it,
pointing
out that rep() and rep.octonion() have different arguments. What do I have to do to my rep.octonion() function to make my package pass R CMD check without warning?
I cannot repeat your problem. Probably you did something differently than you said (like omitted "..." , misspelled times as time or something else in your rep.octonion). This is what I tried. In R:
str(rep)
function (x, times, ...)
rep.octonion <- function(x, times, length.out, each, ...) {}
package.skeleton("octonion", "rep.octonion")
Creating directories ...
Creating DESCRIPTION ...
Creating READMEs ...
Saving functions and data ...
Making help files ...
Created file named './octonion/man/rep.octonion.Rd'.
Edit the file and move it to the appropriate directory.
Done.
Further steps are described in ./octonion/README
Then I edited octonion/man/rep.octonion.Rd so that it uses the generic
and passes R CMD check (virgin Rd files produced by package.skeleton
fail the test, which I found a bit weird). Here are the minimum changes
you need to pass the tests.
--- rep.octonion.Rd.orig 2005-08-31 10:56:36.000000000 +0300
+++ rep.octonion.Rd 2005-08-31 10:55:25.000000000 +0300
@@ -7,5 +7,5 @@
}
\usage{
-rep.octonion(x, times, length.out, each, ...)
+\method{rep}{octonion}(x, times, length.out, each, ...)
}
%- maybe also 'usage' for other objects documented here.
@@ -18,5 +18,5 @@
}
\details{
- ~~ If necessary, more details than the __description__ above ~~
+ ~~ If necessary, more details than the description above ~~
}
\value{
@@ -31,7 +31,7 @@
\note{ ~~further notes~~ }
- ~Make other sections like Warning with \section{Warning }{....} ~
-\seealso{ ~~objects to See Also as \code{\link{~~fun~~}}, ~~~ }
+
+\seealso{ ~~objects to See Also as \code{\link{rep}}, ~~~ }
\examples{
##---- Should be DIRECTLY executable !! ----
@@ -42,4 +42,4 @@
function(x, time, length.out, each, ...) {}
}
-\keyword{ ~kwd1 }% at least one, from doc/KEYWORDS
-\keyword{ ~kwd2 }% __ONLY ONE__ keyword per line
+\keyword{ models }% at least one, from doc/KEYWORDS
+
So this replaces rep.octonion with \method{rep}{octonion}, removes __
from description (these cause latex errors), remove a hanging top level
text "Make other sections...", and removes a link to non-existent
~~fun~~ (I'm not sure if adding a real keyword is necessary).
This passes tests. Including
* checking S3 generic/method consistency ... OK
Conclusion: check your files. (It is pain: been there, done that.)
cheers, jari oksanen