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

Don't list inherited methods if there aren't any #1387

Merged
merged 5 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
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# roxygen2 (development version)

* R6 documentation no longer shows inherited methods if there aren't any
(#1371).

* If you have a daily build of RStudio, the lists of changed Rd files are
now clickable so you can immediately see the rendered development
documentation (#1354).
Expand Down
4 changes: 3 additions & 1 deletion R/rd-r6.R
Original file line number Diff line number Diff line change
Expand Up @@ -258,9 +258,11 @@ r6_inherited_method_list <- function(block, r6data) {
self <- r6data$self
super_meth <- super_meth[! super_meth$name %in% self$name, ]
super_meth <- super_meth[! duplicated(super_meth$name), ]
if (nrow(super_meth) == 0) {
return()
}

super_meth <- super_meth[rev(seq_len(nrow(super_meth))), ]

details <- paste0(
"<details",
if (nrow(super_meth) <= 5) " open",
Expand Down
26 changes: 26 additions & 0 deletions tests/testthat/_snaps/rd-r6.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,32 @@
Warning:
[<text>:10] @description Cannot find matching R6 method

# class with no inherited methods

Code
cat(format(rd$get_section("rawRd")))
Output
\section{Super class}{
\code{\link[R_GlobalEnv:C1]{R_GlobalEnv::C1}} -> \code{C2}
}
\section{Methods}{
\subsection{Public methods}{
\itemize{
\item \href{#method-C2-meth1}{\code{C2$meth1()}}
}
}
\if{html}{\out{<hr>}}
\if{html}{\out{<a id="method-C2-meth1"></a>}}
\if{latex}{\out{\hypertarget{method-C2-meth1}{}}}
\subsection{Method \code{meth1()}}{
method1
\subsection{Usage}{
\if{html}{\out{<div class="r">}}\preformatted{C2$meth1()}\if{html}{\out{</div>}}
}

}
}

# integration test

Code
Expand Down
27 changes: 27 additions & 0 deletions tests/testthat/test-rd-r6.R
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,33 @@ test_that("warning if no method comes after the docs", {
doc <- format(rd)
})

test_that("class with no inherited methods", {
text <- "
C1 <- R6::R6Class('C1', cloneable = FALSE)

#' @title Title
#' @description Description.
#' @details Details.
C2 <- R6::R6Class('C2',
inherit = C1,
cloneable = FALSE,
public = list(
#' @description method1
meth1 = function() 1
)
)"

env <- new.env(parent = globalenv())

eval(parse(text = text, keep.source = TRUE), envir = env)
block <- parse_text(text, env = env)[[1]]
rd <- RoxyTopic$new()

topic_add_r6_methods(rd, block, env)
expect_snapshot(cat(format(rd$get_section("rawRd"))))
})


test_that("integration test", {

wd <- getwd()
Expand Down