0

I am writing a R package using devtools. Now I have a generic function plot that can take different classes (e.g. plot.fact, plot.numer, etc.). In the .R file of plot.fact, I use #' comment for documentations in a roxygen way. Besides other items, I specify the following comments:

#' @rdname plot
#' @method plot fact
#' @S3method plot fact
#' @export

However, when I run check('pkg') the following error message appear: Error: bad 'S3method' directive: S3method(plot). Is there anything wrong with how I write the comments? Or do I have to write a plot <- function(x,...) UseMethod("plot") before the function plot.fact? Thanks!

UPDATE

To be more precise, my plot.fact function does not have a single argument x; instead, it has many extra parameters to customize the plot. The arguments are

plot.fact <- function(x, conf.env=0.95, data.note="", leg.cex=1, ...)

According to Hadley's suggestion, I use

#' @rdname plot
#' @method plot fact
#' @export

But the error is still bad 'S3method' directive... Do I need to write down

plot <- function(x, conf.env=0.95, data.note="", leg.cex=1, ...) {
  UseMethod("plot")
}

before the definition of plot.fact? Thanks!

alittleboy
  • 10,616
  • 23
  • 67
  • 107
  • 1
    Not sure if this is the cause of your troubles, but the signature of the plot generic is `function (x, y, ...)`. So your methods should all start with `x,y` rather than the `x` that you've got in your proposed generic. – Ari B. Friedman Jan 09 '13 at 09:36
  • @AriB.Friedman: yep! I updated my post above to make the question more clearly. Thanks! – alittleboy Jan 09 '13 at 16:26
  • The formal signature of a method must include all the terms (preferably in the same order) as the generic it extends. So you need a `y` argument also, even if you then discard `y`. – Ari B. Friedman Jan 09 '13 at 16:56
  • @AriB.Friedman thank you so much for the help! My code finally works ;) – alittleboy Jan 11 '13 at 05:33

1 Answers1

1
  • If you want to document the method use @method plot fact + @export.
  • If you don't want to document it, use @s3method plot fact.

You shouldn't ever have @method and @s3method in the same block.

hadley
  • 102,019
  • 32
  • 183
  • 245
  • thanks for the suggestions! I still got the same error as before, so please see the updated post above. Thanks! – alittleboy Jan 09 '13 at 16:25
  • Finally it works...thank you all for your help! I realize that I need to put `@export @method plot fact` in order. In that way, when I use the `check` function in `devtools`, the `NAMESPACE` file will add at the very beginning `S3method(plot, fact)`, which is desired ;) – alittleboy Jan 11 '13 at 05:32