Skip to content

Commit

Permalink
Only link to R6 superclass if available
Browse files Browse the repository at this point in the history
Fixes #1236. Closes #1274.
  • Loading branch information
hadley committed Jul 10, 2022
1 parent c0b8e1f commit a6018ee
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 4 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# roxygen2 (development version)

* R6 only links to superclass docs if they're actually available (#1236).

* You can now use alternative knitr engines in markdown code blocks (#1149).

* Fix bug interpolating the results of indented inline RMarkdown (#1353).
Expand Down
8 changes: 7 additions & 1 deletion R/rd-r6.R
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,13 @@ r6_superclass <- function(block, r6data, env) {
push(paste0("\\section{", title, "}{"))

pkgs <- super$classes$package[match(cls, super$classes$classname)]
path <- sprintf("\\code{\\link[%s:%s]{%s::%s}}", pkgs, cls, pkgs, cls)
has_topic <- purrr::map2_lgl(cls, pkgs, has_topic)

path <- ifelse(
has_topic,
sprintf("\\code{\\link[%s:%s]{%s::%s}}", pkgs, cls, pkgs, cls),
sprintf("\\code{%s::%s}", pkgs, cls)
)
me <- sprintf("\\code{%s}", block$object$value$classname)
push(paste(c(rev(path), me), collapse = " -> "))

Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/_snaps/rd-r6.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
cat(format(rd$get_section("rawRd")))
Output
\section{Super class}{
\code{\link[R_GlobalEnv:C1]{R_GlobalEnv::C1}} -> \code{C2}
\code{R_GlobalEnv::C1} -> \code{C2}
}
\section{Methods}{
\subsection{Public methods}{
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/roxygen-block-3-B.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Class B Description.
Class B details.
}
\section{Super class}{
\code{\link[roxygen2:A]{roxygen2::A}} -> \code{B}
\code{roxygen2::A} -> \code{B}
}
\section{Public fields}{
\if{html}{\out{<div class="r6-fields">}}
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/roxygen-block-3-C.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Class C Description.
Classs C details.
}
\section{Super classes}{
\code{\link[roxygen2:A]{roxygen2::A}} -> \code{\link[roxygen2:B]{roxygen2::B}} -> \code{C}
\code{roxygen2::A} -> \code{roxygen2::B} -> \code{C}
}
\section{Public fields}{
\if{html}{\out{<div class="r6-fields">}}
Expand Down

0 comments on commit a6018ee

Please sign in to comment.