3

How to inherit roxygen documentation from an R6 method? The following code (slightly changed Roxygen R6 documentation example)

#' R6 Class representing a person
#'
#' A person has a name and a hair color.
Person <- R6::R6Class("Person",
                      public = list(
                        #' @field name First or full name of the person.
                        name = NULL,

                        #' @field hair Hair color of the person.
                        hair = NULL,

                        #' @description
                        #' Create a new person object.
                        #' @param name Name.
                        #' @param hair Hair color.
                        #' @return A new `Person` object.
                        initialize = function(name = NA, hair = NA) {
                          self$name <- name
                          self$hair <- hair
                          self$greet()
                        },

                        #' @description
                        #' Change hair color.
                        #' @inheritParams Person$initialize
                        #' @examples
                        #' P <- Person("Ann", "black")
                        #' P$hair
                        #' P$set_hair("red")
                        #' P$hair
                        set_hair = function(hair) {
                          self$hair <- hair
                        }
                      )
)

returns warnigs

Warning: argument `hair` undocumented for R6 method `set_hair()`
Warning message:
Topic 'Person': no parameters to inherit with @inheritParams 

I have tried some different ways how to refer to R6 methods but any of them is working. Is it even possible?

Martin
  • 31
  • 1
  • Have you tried `@inheritParams Person$new` ? The object `Person$initialize` doesn't actually exist. – Allan Cameron Oct 30 '21 at 11:12
  • I have tried inheriting using `Person$new`, `Person$initialize`, `Person$public_methods$initialize` but without success. – Martin Oct 31 '21 at 10:09
  • [A solution](https://github.com/r-lib/roxygen2/issues/996) to this particular problem is to add the @param hair to the roxygen part of the whole class – Martin Nov 05 '21 at 14:22

0 Answers0