Take the 2-minute tour ×

I am writing a package that defines a new class, surveyor, and a print method for this, i.e. print.surveyor. My code works fine and I use roxygen for inline documentation. But R CMD check issues a warning:

Functions/methods with usage in documentation object 'print.surveyor' but not in code: print

I have used the following two pages, written by Hadley, as inspiration: Namespaces and Documenting functions, both of which states that the correct syntax is @method function-name class

So my question is: What is the correct way of documenting the print method for my new class using Roxygen? And more specifically, how do I get rid of the warning?

Here is my code: (The commented documentation indicated attempts at fixing this, none of which worked.)

#' Prints surveyor object.
#' Prints surveyor object
## #' @usage print(x, ...)
## #' @aliases print print.surveyor
#' @param x surveyor object
#' @param ... ignored
#' @S3method print surveyor
print.surveyor <- function(x, ...){

And the roxygenized output, i.e. print.surveyor.Rd:

\title{Prints surveyor object.}
\usage{print(x, ...)
\description{Prints surveyor object.}
\details{Prints surveyor object

\arguments{\item{x}{surveyor object}
share|improve this question
add comment

1 Answer

up vote 23 down vote accepted

The function should be documented with the @method tag:

#' @method print surveyor

On initial reading, @hadley's document was a little confusing for me as I am not familiar with roxygen, but after several readings of the section, I think I understand the reason why you need @method.

You are writing full documentation for the print method. @S3method is related to the NAMESPACE and arranges for the method to be exported. @S3method is not meant for documenting a method.

Your Rd file should have the following in the usage section:

\method{print}{surveyor}(x, ...)

if this works correctly, as that is the correct way to document S3 methods in Rd files.

share|improve this answer
Brilliant, thank you. This has been bugging me for months... –  Andrie Jun 29 '11 at 8:25
Yes. Bang on. I need to make that clearer in my docs. –  hadley Jun 29 '11 at 12:34
Thanks, been struggling with this too, but how do you use it with a class specific [-function, e.g. [.myClass? This solution passes R CMD check without warnings but the resulting Rd tag is a mess. @method [ myClass becomes \method{[}{myClass} (x, i, j, ...). –  Backlin Aug 11 '11 at 13:17
@Backlin What's wrong with that? That looks like the proper way to mark-up and S3 method in Rd. It will render properly in the Usage section but with ## S3 method blah blah above the usage code. –  Gavin Simpson Aug 11 '11 at 13:34
@cboettig Yes, @method is the tag for the documentation (the .Rd file) and @S3method is for the namespace mechanism. You need both these days if you have your own NAMESPACE file. You only need @export if you really want to make the method visible outside the namespace of the package. –  Gavin Simpson Nov 3 '12 at 17:48
show 5 more comments

Your Answer


