How to document S4 methods for an existing generic?

roxygen2
#1

How do I document S4 methods with roxygen2, say for the [ operator (i.e., for an existing generic from another package)?

For a concrete example, take this answer from SO: https://stackoverflow.com/questions/10961842/how-to-define-the-subset-operators-for-a-s4-class

How to document that S4 method with roxygen2?

Many thanks in advance!

0 Likes

#2

Take a look at R packages book for this type of question: http://r-pkgs.had.co.nz/namespace.html

0 Likes

#3

Thank you for the pointer, I did already. Also looked in new coming book: r-pkgs.org. But I still do not know how to do it.

0 Likes

#4

Did you try the suggestion in this thread?

0 Likes

#5

Thank you Mara, I had seen that thread and also this one: https://stackoverflow.com/questions/7356120/how-to-properly-document-s4-methods-using-roxygen2

but I had (hastily) overlooked them because those answers have some years already, and also because I of Hadley's comment in that thread above:

Would you mind updating this for roxygen2 3.0? None of these workarounds should be necessary any more. – hadley Jan 21 '14 at 12:54

But I will give it a try! Thanks again!

0 Likes

#6

I tried several combinations of the solutions given in those threads but to no avail.

Maybe you may help if I share an example. I want to document the methods for [ operation generic. So my question is: what should be the roxygen2 tags for these 3 methods?

#' @export
setMethod("[",
          signature(x = "studies", i = "missing", j = "missing", drop = "missing"),
          definition = function(x) x)

#' @export
setMethod("[",
          signature(x = "studies", i = "numeric", j = "missing", drop = "missing"),
          definition = function(x, i) {
            study_ids <- unique(x@studies$study_id)[i]
            filter_by_id(x, id = study_ids)
          })


#' @export
setMethod("[",
          signature(x = "studies", i = "character", j = "missing", drop = "missing"),
          definition = function(x, i) {
            filter_by_id(x, id = i)
          })

I tried several combinations of

#' @name
#' @aliases
#' @rdname

but I am always doing something wrong.

0 Likes

#7

I think I got the gist of it!

Is there any way of prettifying these entries for the methods [ under section " Subset GWAS Catalog Entities": https://rmagno.eu/gwasrapidd/reference/index.html?

0 Likes