Skip to content

Commit a5d9561

Browse files
authored
Add format support to @inherit (#1531)
Fixes #1293
1 parent 95cd25f commit a5d9561

File tree

6 files changed

+11
-10
lines changed

6 files changed

+11
-10
lines changed

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# roxygen2 (development version)
22

3+
* `@inherit` can now also inherit from `@format` (#1293).
4+
35
* `@describeIn()` gives a more informative warning if you use it with an
46
unsupported type (#1490).
57

R/collate.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ update_collate <- function(base_path) {
5353

5454
generate_collate <- function(base_path) {
5555
paths <- sort_c(dir(base_path, pattern = "[.][Rr]$", full.names = TRUE))
56-
includes <- lapply(paths, find_includes)
56+
includes <- lapply(paths, function(x) intersect(find_includes(x), basename(paths)))
5757
names(includes) <- paths
5858

5959
n <- sum(map_int(includes, length))

R/rd-inherit.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ topics_process_inherit <- function(topics, env) {
109109
topics$topo_apply(inherits("author"), inherit_field, "author")
110110
topics$topo_apply(inherits("source"), inherit_field, "source")
111111
topics$topo_apply(inherits("note"), inherit_field, "note")
112+
topics$topo_apply(inherits("note"), inherit_field, "format")
112113

113114
# First inherit individual sections, then all sections.
114115
topics$topo_apply(function(x) x$inherits_section_from(), inherit_section)

R/tag-parser.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ tag_value <- function(x) {
3232
# Also recorded in tags.yml
3333
inherit_components <- c(
3434
"params", "return", "title", "description", "details", "seealso",
35-
"sections", "references", "examples", "author", "source", "note"
35+
"sections", "references", "examples", "author", "source", "note",
36+
"format"
3637
)
3738

3839
#' @export

inst/roxygen2-tags.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,8 @@
209209
210210
Otherwise, specify individual components to inherit by picking one or
211211
more of `params`, `return`, `title`, `description`, `details`, `seealso`,
212-
`sections`, `references`, `examples`, `author`, `source`, and `note`.
212+
`sections`, `references`, `examples`, `author`, `source`, `note`,
213+
and `format`.
213214
template: ' ${1:source} ${2:components}'
214215
vignette: reuse
215216
recommend: true

tests/testthat/test-rd-inherit.R

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,7 @@ test_that("no options gives default values", {
7474
NULL
7575
")[[1]]
7676

77-
expect_equal(
78-
block_get_tag_value(block, "inherit")$fields,
79-
c(
80-
"params", "return", "title", "description", "details", "seealso",
81-
"sections", "references", "examples", "author", "source", "note"
82-
)
83-
)
77+
expect_equal(block_get_tag_value(block, "inherit")$fields, inherit_components)
8478
})
8579

8680
test_that("some options overrides defaults", {
@@ -707,6 +701,7 @@ test_that("can inherit all from single function", {
707701
#' @author Hadley
708702
#' @source my mind
709703
#' @note my note
704+
#' @format my format
710705
#' @examples
711706
#' x <- 1
712707
foo <- function(x, y) {}
@@ -722,6 +717,7 @@ test_that("can inherit all from single function", {
722717
expect_equal(out$get_value("examples"), rd("x <- 1"))
723718
expect_equal(out$get_value("author"), "Hadley")
724719
expect_equal(out$get_value("source"), "my mind")
720+
expect_equal(out$get_value("format"), "my format")
725721
expect_equal(out$get_value("note"), "my note")
726722
})
727723

0 commit comments

Comments
 (0)