Skip to content

Guidance on documenting R6 #189

@sckott

Description

@sckott

to add maybe to 1.7 Documentation in chapter 1 Packaging Guide.

Because roxygen2 doesn't currently completely/sufficiently document R6 methods, I think we should give some guidance on this, just a few tips to better document your R6 stuff so users have as much info as possible.

A brief start:


Documenting R6

This is assuming the maintainer is using roxygen2.

Usage

That "Usage" section at the top of most manual pages for R functions is not created for R6 classes. To create that section for your R6 class' new method, we suggest doing the following:

#' @section Usage:
#' ```
#' FooBar$new(x, y, z, ...)
#' ```

The downside of this approach is that normal usage sections are checked during R CMD CHECK - but not with the above approach. But otherwise its not created at all or you get something that's not useful to users (see below). Remember to make sure your Usage section is up to date with what the R6 class' initialize method contains.

Methods

You should document all public methods on your R6 class so users know how to use each method.

#' @section Methods:
#'   \describe{
#'     \item{`multiply()`}{
#'       Multiply something
#'     }
#'   }

method with parmeters, can describe each within \itemize{\item ...}

#' @section Methods:
#'   \describe{
#'     \item{`multiply(x, y)`}{
#'       Multiply two numbers
#'       \itemize{
#'         \item some number
#'         \item some number
#'       }
#'     }
#'   }

Other pieces

Folks documenting R6 classes usually also do:

#' @format NULL
#' @usage NULL

Setting @format to not be used because it creates something not very useful:

An object of class R6ClassGenerator of length 24

See above for why @usage is removed.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions