Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
ashbythorpe opened this issue Oct 23, 2023 · 3 comments
Closed

Comments

@ashbythorpe
Copy link

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

@gaborcsardi
Copy link
Member

Yes, this is documented at https://roxygen2.r-lib.org/articles/rd-other.html#r6:

Method documentation can use the @description, @details, @param, @return and @examples tags. These are used to create a subsection for the method, within a separate ‘Methods’ section. All roxygen comment lines of a method documentation must appear after a tag.

@ashbythorpe
Copy link
Author

Ah, so it is. Thanks!

@averissimo
Copy link

Could this be reopened as a feature request?

It is a useful tag to have to protect against suggested packages that are used in examples not being installed.

Alternatively, support the \dontshow tag inside the R6 methods @examples so this can be achieved manually (it currently shows the \dontshow on the method definition)

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants