D Ogle D Ogle - 1 year ago 87
R Question

roxygen2: Issue with exporting print method

I have updated to roxygen2 v4.0.0 and am now attempting to convert @S3method and @method commands to @export commands following the directions here. This seems to have worked well for all of my methods except for those related to print.

Here is a toy example that illustrates my problem (I understand the silliness of the example). Here is the .R file ...

#' Test.
#' Test.
#'@aliases zzzTest print.zzzTest summary.zzzTest
#'@param v A numeric vector.
#'@param x A \code{zzzTest} object.
#'@param object A \code{zzzTest} object.
#'@param \dots Additional arguments for the S3 methods.
#'@return A \code{zzzTest} object.
#'@keywords manip
#'z <- zzzTest(runif(10,1,2))
#'@rdname zzzTest
#'@export zzzTest
zzzTest <- function(v) {
tmp <- log(v)
class(tmp) <- "zzzTest"

#'@rdname zzzTest
print.zzzTest <- function(x,...) { print(x, ...) }

#'@rdname zzzTest
summary.zzzTest <- function(object,...) { summary(object) }

And this is the .Rd file that results from roxygenising ...

% Generated by roxygen2 (4.0.0): do not edit by hand

print.zzzTest(x, ...)

\method{summary}{zzzTest}(object, ...)
\item{v}{A numeric vector.}

\item{x}{A \code{zzzTest} object.}

\item{object}{A \code{zzzTest} object.}

\item{\dots}{Additional arguments for the S3 methods.}
A \code{zzzTest} object.
z <- zzzTest(runif(10,1,2))

My use of @export seems to work fine for the summary method (note the \method()), but not for the print method (note no \method() and only print.zzzTest). I was also successful using @export for several other methods in other .R files. My problems only seem to occur with the print method.

Can someone point out where I am going wrong? Thank you in advance for any help with this problem.

For what it is worth, I am using R 3.1.0, RStudio 0.98.501, and roxygen2 4.0.0.

UPDATE 1: There is an export(print.zzzTemp) but not an S3method(print,zzzTemp) in the namespace ... i.e., the same problem as ZNK (in the comments).

UPDATE 2: I copied the exact .R file into another package, roxygenized that package, and the .Rd file (and corresponding namespace) were created properly. This implies that I have some "switch" related to roxygen2 different between the two packages, but I can't seem to isolate the difference or find such a "switch" (I believe that I have only controlled roxygen through the project options in RStudio).

Answer Source

I have found a solution for my problem (In comments above) and it may work for yours. In The NEWS.md file for v3.0.0, it is mentioned that @method tag is not needed as roxygen2 will figure it out, but it's sill available in the rare case that roxygen2 cannot do so. My solution:

#' @method print myClass    
#' @export    
print.myClass <- function(x) print("myClass")

This gives me back the S3method(print, myClass) in my NAMESPACE file.