Skip to content

Commit c5a8584

Browse files
authored
Drop pkg:: prefix for superclasses in the same package (#1816)
Fixes #1567
1 parent d357b5a commit c5a8584

5 files changed

Lines changed: 34 additions & 7 deletions

File tree

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* `@examplesIf` now warns when there is no example code after the condition (#1695).
44
* `tag_words_line()` is deprecated in favour of `tag_words()`, which now checks for single-line content by default. Use `tag_words(x, multiline = TRUE)` or `tag_value(x, multiline = TRUE)` if your tag legitimately spans multiple lines.
55
* R6 improvements:
6+
* The "Super classes" section now omits the `pkg::` prefix for parent classes from the same package, making the inheritance chain easier to read (#1567).
67
* R6 classes with only active bindings and `cloneable = FALSE` no longer error during documentation (#1610).
78
* `initialize()` method parameters now automatically inherit documentation from `@field` tags with the same name, reducing the need to duplicate descriptions. Explicit `@param` tags still take precedence (#1004).
89
* New `needs_roxygenize()` provides a lightweight check that man pages are up-to-date by comparing modification times of `.Rd` files with their source files (#1411).

R/rd-r6-super.R

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,17 @@ format.rd_r6_super <- function(x, ...) {
2727

2828
title <- if (length(cls) > 1) "Super classes" else "Super class"
2929

30-
path <- ifelse(
31-
ht,
32-
sprintf("\\code{\\link[%s:%s]{%s::%s}}", pkgs, cls, pkgs, cls),
33-
sprintf("\\code{%s::%s}", pkgs, cls)
34-
)
30+
self_pkg <- roxy_meta_get("current_package") %||% ""
31+
same_pkg <- pkgs == self_pkg
32+
33+
label <- ifelse(same_pkg, cls, paste0(pkgs, "::", cls))
34+
path <- map_chr(seq_along(cls), function(i) {
35+
if (ht[[i]]) {
36+
rd_link(pkgs[[i]], cls[[i]], label[[i]], code = TRUE)
37+
} else {
38+
paste0("\\code{", label[[i]], "}")
39+
}
40+
})
3541
me <- sprintf("\\code{%s}", x$class)
3642

3743
c(

tests/testthat/_snaps/rd-r6-super.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,12 @@
77
\code{mypkg::Parent} -> \code{Child}
88
}
99

10+
# format.rd_r6_super omits pkg:: for same-package classes
11+
12+
Code
13+
cat(format(supers), sep = "\n")
14+
Output
15+
\section{Super classes}{
16+
\code{otherpkg::GrandParent} -> \code{Parent} -> \code{Child}
17+
}
18+

tests/testthat/_snaps/rd-r6.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@
217217
A method 4.
218218
}
219219
\section{Super class}{
220-
\code{testR6::A} -> \code{B}
220+
\code{A} -> \code{B}
221221
}
222222
\section{Public fields}{
223223
\if{html}{\out{<div class="r6-fields">}}
@@ -323,7 +323,7 @@
323323
C method 5.
324324
}
325325
\section{Super classes}{
326-
\code{testR6::A} -> \code{testR6::B} -> \code{C}
326+
\code{A} -> \code{B} -> \code{C}
327327
}
328328
\section{Public fields}{
329329
\if{html}{\out{<div class="r6-fields">}}

tests/testthat/test-rd-r6-super.R

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,17 @@ test_that("format.rd_r6_super with one superclass", {
3333
expect_snapshot(cat(format(supers), sep = "\n"))
3434
})
3535

36+
test_that("format.rd_r6_super omits pkg:: for same-package classes", {
37+
local_roxy_meta_set("current_package", "mypkg")
38+
supers <- rd_r6_super(
39+
"Child",
40+
package = c("mypkg", "otherpkg"),
41+
classname = c("Parent", "GrandParent"),
42+
has_topic = c(FALSE, FALSE)
43+
)
44+
expect_snapshot(cat(format(supers), sep = "\n"))
45+
})
46+
3647
test_that("format.rd_r6_super returns nothing when empty", {
3748
expect_null(format(rd_r6_super("Foo")))
3849
})

0 commit comments

Comments
 (0)