Skip to content

Commit

Permalink
Inherit examples
Browse files Browse the repository at this point in the history
Fixes #588
  • Loading branch information
hadley committed Aug 17, 2017
1 parent 827b9f8 commit 8259871
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 3 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# roxygen2 6.0.1.9000

* `@inherits` can now inherits examples (#588).

* The default description (i.e. the title) is now added much later in the
process. That means that `@inherit description` now works when you have
specified a title for the inheritor (#629) and the default description
Expand Down
1 change: 1 addition & 0 deletions R/rd-inherit.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ topics_process_inherit <- function(topics, env) {
topics$topo_apply(inherits("details"), inherit_field, "details")
topics$topo_apply(inherits("seealso"), inherit_field, "seealso")
topics$topo_apply(inherits("references"), inherit_field, "references")
topics$topo_apply(inherits("examples"), inherit_field, "examples")

# First inherit individual sections, then all sections.
topics$topo_apply(function(x) x$inherits_section_from(), inherit_section)
Expand Down
2 changes: 1 addition & 1 deletion R/tag.R
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ tag_inherit <- function(x) {
fields <- pieces[-1]

all <- c("params", "return", "title", "description", "details", "seealso",
"sections", "references")
"sections", "references", "examples")
if (length(fields) == 0) {
fields <- all
} else {
Expand Down
7 changes: 5 additions & 2 deletions tests/testthat/test-Rd-inherit.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ test_that("no options gives default values", {
expect_equal(
block$inherit$fields,
c(
"params", "return", "title", "description", "details", "seealso", "sections",
"references"
"params", "return", "title", "description", "details", "seealso",
"sections", "references", "examples"
)
)
})
Expand Down Expand Up @@ -462,6 +462,8 @@ test_that("can inherit all from single function", {
#'
#' @param x x
#' @param y y
#' @examples
#' x <- 1
foo <- function(x, y) {}
#' @inherit foo
Expand All @@ -473,4 +475,5 @@ test_that("can inherit all from single function", {
expect_equal(out$get_field("title")$values, "Foo")
expect_equal(out$get_field("description")$values, "Description")
expect_equal(out$get_field("details")$values, "Details")
expect_equal(out$get_field("examples")$values, rd("x <- 1"))
})

0 comments on commit 8259871

Please sign in to comment.