From adee2a7bef206663895ba8b5ea9f3f4842fa88fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Sat, 23 Dec 2023 07:26:33 +0100 Subject: [PATCH 1/4] Add test --- tests/testthat/_snaps/rd-family.md | 86 ++++++++++++++++++++++++++++++ tests/testthat/test-rd-family.R | 26 +++++++++ 2 files changed, 112 insertions(+) create mode 100644 tests/testthat/_snaps/rd-family.md diff --git a/tests/testthat/_snaps/rd-family.md b/tests/testthat/_snaps/rd-family.md new file mode 100644 index 00000000..f437d3d0 --- /dev/null +++ b/tests/testthat/_snaps/rd-family.md @@ -0,0 +1,86 @@ +# careful ordering + + Code + out + Output + $foofun1.Rd + % Generated by roxygen2: do not edit by hand + % Please edit documentation in ./ + \name{foofun1} + \alias{foofun1} + \title{foofun1} + \usage{ + foofun1() + } + \description{ + foofun1 + } + \seealso{ + Other a: + \code{\link{Foofun3}()}, + \code{\link{foofun2}()}, + \code{\link{foofun}()} + } + \concept{a} + + $foofun2.Rd + % Generated by roxygen2: do not edit by hand + % Please edit documentation in ./ + \name{foofun2} + \alias{foofun2} + \title{foofun2} + \usage{ + foofun2() + } + \description{ + foofun2 + } + \seealso{ + Other a: + \code{\link{Foofun3}()}, + \code{\link{foofun1}()}, + \code{\link{foofun}()} + } + \concept{a} + + $Foofun3.Rd + % Generated by roxygen2: do not edit by hand + % Please edit documentation in ./ + \name{Foofun3} + \alias{Foofun3} + \title{Foofun3} + \usage{ + Foofun3() + } + \description{ + Foofun3 + } + \seealso{ + Other a: + \code{\link{foofun1}()}, + \code{\link{foofun2}()}, + \code{\link{foofun}()} + } + \concept{a} + + $foofun.Rd + % Generated by roxygen2: do not edit by hand + % Please edit documentation in ./ + \name{foofun} + \alias{foofun} + \title{foofun} + \usage{ + foofun() + } + \description{ + foofun + } + \seealso{ + Other a: + \code{\link{Foofun3}()}, + \code{\link{foofun1}()}, + \code{\link{foofun2}()} + } + \concept{a} + + diff --git a/tests/testthat/test-rd-family.R b/tests/testthat/test-rd-family.R index d6e8eacf..2aa036b0 100644 --- a/tests/testthat/test-rd-family.R +++ b/tests/testthat/test-rd-family.R @@ -123,3 +123,29 @@ test_that("custom family prefixes can be set", { expect_match(out$get_value("seealso"), "^Custom prefix:") }) + +test_that("careful ordering", { + # Can't use foo1 because it's used as class in another test + + out <- roc_proc_text(rd_roclet(), " + #' foofun1 + #' @family a + foofun1 <- function() {} + + #' foofun2 + #' @family a + foofun2 <- function() {} + + #' Foofun3 + #' @family a + Foofun3 <- function() {} + + #' foofun + #' @family a + foofun <- function() {} + ") + + expect_snapshot({ + out + }) +}) From e9a728640c08d6b8eabf0baa7247fa1773066b98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Sat, 23 Dec 2023 07:27:15 +0100 Subject: [PATCH 2/4] Improve ordering --- R/rd-family.R | 7 +++++-- R/util-locale.R | 8 +++++++- man/tags-index-crossref.Rd | 2 +- man/tags-reuse.Rd | 4 ++-- tests/testthat/_snaps/rd-family.md | 12 ++++++------ 5 files changed, 21 insertions(+), 12 deletions(-) diff --git a/R/rd-family.R b/R/rd-family.R index 3b93013a..df036544 100644 --- a/R/rd-family.R +++ b/R/rd-family.R @@ -51,12 +51,15 @@ topics_process_family <- function(topics, env) { if (length(others) < 1) next - by_file <- map_chr(aliases[others], function(x) { + other_aliases <- aliases[others] + other_aliases_order <- map_chr(other_aliases, function(x) escape(x[1])) + + by_file <- map_chr(other_aliases[order_c(other_aliases_order)], function(x) { obj <- find_object(x[1], env) suffix <- if (is.function(obj$value)) "()" else "" paste0("\\code{\\link{", escape(x[1]), "}", suffix, "}") }) - links <- paste(sort_c(by_file), collapse = ",\n") + links <- paste(by_file, collapse = ",\n") seealso <- topics_process_family_prefix(family) topic$add(rd_section("seealso", paste0(seealso, "\n", links))) diff --git a/R/util-locale.R b/R/util-locale.R index fa324ce8..7360aabf 100644 --- a/R/util-locale.R +++ b/R/util-locale.R @@ -11,4 +11,10 @@ with_collate <- function(locale, code) { force(code) } -sort_c <- function(x, ...) with_collate("C", sort(x, ...)) +sort_c <- function(x, ...) { + with_collate("C", sort(x, ...)) +} + +order_c <- function(x, ...) { + with_collate("C", order(x, ...)) +} diff --git a/man/tags-index-crossref.Rd b/man/tags-index-crossref.Rd index 265e93bc..b8e4aec4 100644 --- a/man/tags-index-crossref.Rd +++ b/man/tags-index-crossref.Rd @@ -40,8 +40,8 @@ Other less frequently used tags: } \seealso{ Other documentation tags: -\code{\link{tags-rd-other}}, \code{\link{tags-rd}}, +\code{\link{tags-rd-other}}, \code{\link{tags-reuse}} } \concept{documentation tags} diff --git a/man/tags-reuse.Rd b/man/tags-reuse.Rd index d3aa3c3b..de062a56 100644 --- a/man/tags-reuse.Rd +++ b/man/tags-reuse.Rd @@ -56,7 +56,7 @@ Other less frequently used tags: \seealso{ Other documentation tags: \code{\link{tags-index-crossref}}, -\code{\link{tags-rd-other}}, -\code{\link{tags-rd}} +\code{\link{tags-rd}}, +\code{\link{tags-rd-other}} } \concept{documentation tags} diff --git a/tests/testthat/_snaps/rd-family.md b/tests/testthat/_snaps/rd-family.md index f437d3d0..64746072 100644 --- a/tests/testthat/_snaps/rd-family.md +++ b/tests/testthat/_snaps/rd-family.md @@ -18,8 +18,8 @@ \seealso{ Other a: \code{\link{Foofun3}()}, - \code{\link{foofun2}()}, - \code{\link{foofun}()} + \code{\link{foofun}()}, + \code{\link{foofun2}()} } \concept{a} @@ -38,8 +38,8 @@ \seealso{ Other a: \code{\link{Foofun3}()}, - \code{\link{foofun1}()}, - \code{\link{foofun}()} + \code{\link{foofun}()}, + \code{\link{foofun1}()} } \concept{a} @@ -57,9 +57,9 @@ } \seealso{ Other a: + \code{\link{foofun}()}, \code{\link{foofun1}()}, - \code{\link{foofun2}()}, - \code{\link{foofun}()} + \code{\link{foofun2}()} } \concept{a} From b173e1b86e546f0813b1563761c9f5e6dbd76473 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Tue, 2 Jan 2024 21:26:54 +0100 Subject: [PATCH 3/4] NEWS --- NEWS.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/NEWS.md b/NEWS.md index 5d63d603..144b7930 100644 --- a/NEWS.md +++ b/NEWS.md @@ -62,6 +62,8 @@ * `@inherit` can now also inherit from `@format` (#1293). +* `@family` lists are now ordered more carefully, "foo1" comes after "foo" (#1563, @krlmlr). + # roxygen2 7.2.3 * roxygen2 now supports HTML blocks in markdown. They are only included From 7cb9709d6d7750a1f1b75a6154264a2bd3ba841b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Wed, 3 Jan 2024 06:29:49 +0100 Subject: [PATCH 4/4] foofun -> foo --- tests/testthat/_snaps/rd-family.md | 72 +++++++++++++++--------------- tests/testthat/test-rd-family.R | 18 ++++---- 2 files changed, 44 insertions(+), 46 deletions(-) diff --git a/tests/testthat/_snaps/rd-family.md b/tests/testthat/_snaps/rd-family.md index 64746072..915bba09 100644 --- a/tests/testthat/_snaps/rd-family.md +++ b/tests/testthat/_snaps/rd-family.md @@ -3,83 +3,83 @@ Code out Output - $foofun1.Rd + $foo1.Rd % Generated by roxygen2: do not edit by hand % Please edit documentation in ./ - \name{foofun1} - \alias{foofun1} - \title{foofun1} + \name{foo1} + \alias{foo1} + \title{foo1} \usage{ - foofun1() + foo1() } \description{ - foofun1 + foo1 } \seealso{ Other a: - \code{\link{Foofun3}()}, - \code{\link{foofun}()}, - \code{\link{foofun2}()} + \code{\link{Foo3}()}, + \code{\link{foo}()}, + \code{\link{foo2}()} } \concept{a} - $foofun2.Rd + $foo2.Rd % Generated by roxygen2: do not edit by hand % Please edit documentation in ./ - \name{foofun2} - \alias{foofun2} - \title{foofun2} + \name{foo2} + \alias{foo2} + \title{foo2} \usage{ - foofun2() + foo2() } \description{ - foofun2 + foo2 } \seealso{ Other a: - \code{\link{Foofun3}()}, - \code{\link{foofun}()}, - \code{\link{foofun1}()} + \code{\link{Foo3}()}, + \code{\link{foo}()}, + \code{\link{foo1}()} } \concept{a} - $Foofun3.Rd + $Foo3.Rd % Generated by roxygen2: do not edit by hand % Please edit documentation in ./ - \name{Foofun3} - \alias{Foofun3} - \title{Foofun3} + \name{Foo3} + \alias{Foo3} + \title{Foo3} \usage{ - Foofun3() + Foo3() } \description{ - Foofun3 + Foo3 } \seealso{ Other a: - \code{\link{foofun}()}, - \code{\link{foofun1}()}, - \code{\link{foofun2}()} + \code{\link{foo}()}, + \code{\link{foo1}()}, + \code{\link{foo2}()} } \concept{a} - $foofun.Rd + $foo.Rd % Generated by roxygen2: do not edit by hand % Please edit documentation in ./ - \name{foofun} - \alias{foofun} - \title{foofun} + \name{foo} + \alias{foo} + \title{foo} \usage{ - foofun() + foo() } \description{ - foofun + foo } \seealso{ Other a: - \code{\link{Foofun3}()}, - \code{\link{foofun1}()}, - \code{\link{foofun2}()} + \code{\link{Foo3}()}, + \code{\link{foo1}()}, + \code{\link{foo2}()} } \concept{a} diff --git a/tests/testthat/test-rd-family.R b/tests/testthat/test-rd-family.R index 2aa036b0..fb7b8b59 100644 --- a/tests/testthat/test-rd-family.R +++ b/tests/testthat/test-rd-family.R @@ -125,24 +125,22 @@ test_that("custom family prefixes can be set", { }) test_that("careful ordering", { - # Can't use foo1 because it's used as class in another test - out <- roc_proc_text(rd_roclet(), " - #' foofun1 + #' foo1 #' @family a - foofun1 <- function() {} + foo1 <- function() {} - #' foofun2 + #' foo2 #' @family a - foofun2 <- function() {} + foo2 <- function() {} - #' Foofun3 + #' Foo3 #' @family a - Foofun3 <- function() {} + Foo3 <- function() {} - #' foofun + #' foo #' @family a - foofun <- function() {} + foo <- function() {} ") expect_snapshot({