Skip to content

examplesIf doesn't work when documenting the methods of an R6 class #1521

Closed
@ashbythorpe

Description

@ashbythorpe

When @examplesIf is used instead of @examples whilst documenting an R6 method, the example is treated as separate from the method (i.e. only documenting the class).

I've created a reproducible example here: https://github.com/ashbythorpe/roxygen2examples

A simple class is created, with two documented methods: one which uses @examples and one which used @examplesIf:

#' Create an instance of MyClass
#'
#' @returns An instance of MyClass
#'
#' @export
MyClass <- R6::R6Class("MyClass",
  public = list(
    #' @description
    #' Create a new `MyClass` instance.
    initialize = function() {},

    #' @description
    #' Do something.
    #'
    #' @examples
    #' MyClass$new()$foo()
    foo = function() {},

    #' @description
    #' Do something else.
    #'
    #' @examplesIf TRUE
    #' MyClass$new()$bar()
    bar = function() {}
  )
)

I would expect the two examples sections to be rendered in the same way. Instead, the following is produced:
https://ashbythorpe.github.io/roxygen2examples/reference/MyClass.html
https://github.com/ashbythorpe/roxygen2examples/blob/a94f2bbdb9ebf9e1a71b06e20d4aab52e767a823/man/MyClass.Rd

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions