What's the recommended package build workflow with packages that contain S4 classes? [duplicate]

StackOverflow https://stackoverflow.com/questions/13642092

  •  03-12-2021
  •  | 
  •  

Question

Possible Duplicate:
How to properly document S4 class slots using Roxygen2

I would like to build a package that contains S4 classes using R Studio and roxygen2. I had already documented all my functions using roxygen2 syntax when I introduced a couple of S4 classes to my package.

Now I realized that there's no '@slot' functionality out-of-the-box. So I wonder how can I keep all my documentation work for the other functions and document the S4 classes manually like suggested in this thread?

Or in other words which workflow would you recommend to built a package that contains both old school functions and S4 classes?

EDIT: Would you recommend to configure R Studio built tools not to create .Rd files. roxygenize manually and then add the info afterwards? Still this would lead to overwriting the manually generated .Rd files of the classes...

Was it helpful?

Solution

General info on roxygen and S4 classes

The first version of roxygen had an @slot tag, but that version isn't maintained any more in favor of roxygen2. So it's advised against to use that old version.

As for now, roxygen2 doesn't have real support for S4 classes. Hadley is working hard to make that happen in roxygen3 (https://github.com/hadley/roxygen3). In case you want to give it a shot and feel brave: install roxygen3 from github and try the development version. Note that this version eventually will be incoorporated into roxygen2, so in time the problem will solve itself.

Regarding your workflow:

I personally always find it a bad idea to combine using roxygen and manually written .Rd files. But if you must, you can send the output of roxygen to a different directory using the argument roxygen.dir. This way you can copy whatever you want back into the package directory without overwriting the manually written files.

roxygenise("./mypackage", roxygen.dir="./myroxygendir")

What I would do, is simply use roxygen2 to write the Rd files for your classes as explained in the thread you link to. You don't have to add them manually like you believe for some unknown reason. You just use the #' to indicate the Rd block like always, and use whatever is given in the thread you link to. If you want to make the slots a separate section, you can do that using the @section tag like in the example below.

An example of how to add Slots for the moment using roxygen2 :

#' The MY class
#'
#' This class blabla yadayada
#'
#'@section Slots:
#'  \describe{
#'    \item{\code{aslot}:}{Object of class \code{"numeric"}, containing 
#'whatever and a bit more}
#'    \item{\code{anotherslot}:}{Object of class \code{"character"}, containing
#' strings.}
#'  }
#'
#' @note Yes, you can add notes
#' @name MY 
#' @rdname MY
#' @aliases MY-class
#' @exportClass MY
#' @author Joris Meys
setClass("MY",
         representation=representation(aslot="numeric",
                                       anotherslot="character"
                                       )
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top