I'm writing a package with an R6 class that has several methods. I would like to be able to generate documentation for both, class and methods. For the below example, I would like to be able to access the docs with ?Person
for the class and ?set_hair
, for the method. Here my example class:
#' This is my Person class
#' @title Person Class
#' @docType class
#' @description Person class description
#' @field name Name of the person
#' @field hair Hair colour
#'
#' @section Methods:
#' \describe{
#' \item{set_hair Set the hair color}
#' }
#'
#' @examples
#' Person$new(name="Bill", hair="Blond")
#' @export
Person <- R6::R6Class("Person",
public = list(
name = NULL,
hair = NULL,
initialize = function(name = NA, hair = NA) {
self$name <- name
self$hair <- hair
},
# '@name set_hair
# '@param val: hair colour
set_hair = function(val) {
self$hair <- val
},
)
)
Running roxygenise()
, the annotations above the method bodies are not rendered at all, so the only information I specify in @section Methods
is in the docs.
Since I have over 50 class methods, it would be much nicer if I can access the method docs with ?methodname
sepeartly. I found some some posts on this (Documenting R6 classes and methods within R package in RStudio, https://github.com/klutometis/roxygen/issues/306), but it seems to me that this is not supported for R6 classes.
What would be the best way to document my class methods separately?