Skip to content

Commit

Permalink
Preserve order of aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
hadley committed Oct 19, 2016
1 parent a7a5b63 commit c2cb3ef
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 19 deletions.
3 changes: 3 additions & 0 deletions NEWS.md
@@ -1,5 +1,8 @@
# roxygen2 5.0.1.9000

* `@aliases` are no longer sorted in alphabetical order, but will instead
match the order of the usage. This gives you more control in pkgdown.

* `@author` is now rendered after `@seealso`.

* `"_PACKAGE"` documentation now generates a default `@seealso` combining
Expand Down
10 changes: 7 additions & 3 deletions R/field.R
Expand Up @@ -58,16 +58,20 @@ format.roxy_field_backref <- function(x, ...) {

# Fields that repeat multiple times --------------------------------------------

format_rd <- function(x, ...) {
vapply(sort_c(unique(x$values)), rd_macro, field = x$field,
format_rd <- function(x, ..., sort = TRUE) {
if (sort) {
x$values <- sort_c(unique(x$values))
}

vapply(x$values, rd_macro, field = x$field,
FUN.VALUE = character(1), USE.NAMES = FALSE)
}
#' @export
format.roxy_field_keyword <- format_rd
#' @export
format.roxy_field_alias <- function(x, ...) {
x$values <- str_replace_all(x$values, fixed("%"), "\\%")
format_rd(x, ...)
format_rd(x, ..., sort = FALSE)
}

# Fields that keep the first occurence -----------------------------------------
Expand Down
6 changes: 3 additions & 3 deletions man/namespace_roclet.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions man/roclet.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions man/roxy_tag.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/roxygenize.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions tests/testthat/test-rd-alias.R
Expand Up @@ -13,19 +13,19 @@ test_that("aliases split into pieces", {

test_that("aliases escaped, not quoted", {
out1 <- roc_proc_text(rd_roclet(), "
#' @name %a%
#' @aliases a
#' @title a
#' @name %a%
NULL")[[1]]
out2 <- roc_proc_text(rd_roclet(), "
#' @name a
#' @aliases %a%
#' @title a
#' @name a
NULL")[[1]]
alias1 <- format(get_tag(out1, "alias"))
alias2 <- format(get_tag(out2, "alias"))
expect_equal(alias1, c("\\alias{\\%a\\%}\n", "\\alias{a}\n"))
expect_equal(alias2, c("\\alias{\\%a\\%}\n", "\\alias{a}\n"))
expect_equal(alias2, c("\\alias{a}\n", "\\alias{\\%a\\%}\n"))
})

test_that("can use NULL to suppress default aliases", {
Expand Down

0 comments on commit c2cb3ef

Please sign in to comment.