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

Only link to R6 superclass if available #1393

Merged
merged 2 commits into from
Jul 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
5 changes: 3 additions & 2 deletions R/utils-rd.R
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,9 @@ make_as_character_rd <- function() {
has_topic <- function(topic, package) {
tryCatch(
{
out <- utils::help((topic), package = (package))
length(out) == 1
out <- inject(help(!!topic, !!package), global_env())
inherits(out, "dev_topic") ||
(inherits(out, "help_files_with_topic") && length(out) == 1)
},
error = function(c) FALSE
)
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