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

Generic should come before method #863

Closed
krlmlr opened this issue May 19, 2019 · 2 comments
Closed

Generic should come before method #863

krlmlr opened this issue May 19, 2019 · 2 comments
Labels
feature a feature request or enhancement rd ✍️

Comments

@krlmlr
Copy link
Member

krlmlr commented May 19, 2019

in the "Usage" section.

Often, the following pattern is used to document an S3 generic along with its methods:

#' Some
#'
#' Method.
#' @export
some_method <- function(x, ...) UseMethod("some_method")

#' @rdname some_method
#' @export
some_method.data.frame <- function(x, ...) {
  # Method implementation for data frames
}

Currently, they are shown in order of appearance, and collation or renaming files is necessary to make sure the generic appears first. (Also, \name{} and \alias{} seem wrong.)

library(roxygen2)
roc_proc_text(rd_roclet(), "
#' @rdname some_method
#' @export
some_method.data.frame <- function(x, ...) {
  # Method implementation for data frames
}

#' Some
#'
#' Method.
#' @export
some_method <- function(x, ...) UseMethod('some_method')
")
#> $some_method.Rd
#> % Generated by roxygen2: do not edit by hand
#> % Please edit documentation in Rtmp5qvmr0/file34342bfb9414
#> \name{some_method.data.frame}
#> \alias{some_method.data.frame}
#> \alias{some_method}
#> \title{Some}
#> \usage{
#> \method{some_method}{data.frame}(x, ...)
#> 
#> some_method(x, ...)
#> }
#> \description{
#> Method.
#> }

Created on 2019-05-19 by the reprex package (v0.2.1)

@hadley hadley added feature a feature request or enhancement rd ✍️ labels Jul 21, 2019
@hadley
Copy link
Member

hadley commented Sep 12, 2019

The only way I can see to implement this would be to add a special @order tag, then add a new block ordering step that's executed after parsing in roc_proc_text() and roxygenise(). (It would a special tag because it wouldn't be processed by a roclet). I think the default order value would be Inf so that any order value would cause the block to bubble to the front.

@hadley hadley closed this as completed in 718af11 Sep 17, 2019
@krlmlr
Copy link
Member Author

krlmlr commented Oct 1, 2019

Great! This will make @include obsolete in many cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature a feature request or enhancement rd ✍️
Projects
None yet
Development

No branches or pull requests

2 participants