From 464c3e67504f847be65b17607ffd10059b96641b Mon Sep 17 00:00:00 2001 From: Dan Chaltiel <dan.chaltiel@gmail.com> Date: Fri, 15 Apr 2022 15:05:05 +0200 Subject: [PATCH 1/3] remove duplicated authors --- R/rd-author.R | 7 +++++++ tests/testthat/test-rd-markdown.R | 20 ++++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 R/rd-author.R diff --git a/R/rd-author.R b/R/rd-author.R new file mode 100644 index 00000000..816b1f8b --- /dev/null +++ b/R/rd-author.R @@ -0,0 +1,7 @@ + +#' @export +merge.rd_section_author <- function(x, y, ...) { + stopifnot(identical(class(x), class(y))) + # Remove duplicated authors, e.g. when using @rdname + rd_section(x$type, unique(c(x$value, y$value))) +} diff --git a/tests/testthat/test-rd-markdown.R b/tests/testthat/test-rd-markdown.R index aa401def..011c6545 100644 --- a/tests/testthat/test-rd-markdown.R +++ b/tests/testthat/test-rd-markdown.R @@ -13,6 +13,26 @@ test_that("generic keys produce expected output", { expect_equal(out$get_value("author"), "test") }) + +test_that("author duplicated get removed", { + out <- roc_proc_text(rd_roclet(), " + #' @name a + #' @title a + #' @author A + NULL + + #' @name b + #' @rdname a + #' @author A + NULL + + #' @name c + #' @rdname a + #' @author B + NULL")[[1]] + expect_equal(out$get_value("author"), c("A", "B")) +}) + test_that("@format overrides defaults", { out <- roc_proc_text(rd_roclet(), " #' Title From bd10fed3165d60f26a8fa545a6287bbb9e75c691 Mon Sep 17 00:00:00 2001 From: Dan Chaltiel <dan.chaltiel@gmail.com> Date: Wed, 20 Apr 2022 15:47:11 +0200 Subject: [PATCH 2/3] export merge.rd_section_author() --- NAMESPACE | 1 + NEWS.md | 2 ++ 2 files changed, 3 insertions(+) diff --git a/NAMESPACE b/NAMESPACE index ed0de854..c3909784 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -47,6 +47,7 @@ S3method(format,rd_section_usage) S3method(format,rd_section_value) S3method(format,roxy_tag) S3method(merge,rd_section) +S3method(merge,rd_section_author) S3method(merge,rd_section_inherit) S3method(merge,rd_section_inherit_dot_params) S3method(merge,rd_section_inherit_section) diff --git a/NEWS.md b/NEWS.md index 7999002f..157e7b3c 100644 --- a/NEWS.md +++ b/NEWS.md @@ -55,6 +55,8 @@ * `@includeRmd` is now adapted to change in rmarkdown 2.12 regarding math support in `github_document()` (#1304). +* Authors are now only counted only once if mentioned in merged documentations (@DanChaltiel #1333). + # roxygen2 7.1.2 * The new `@examplesIf` tag can be used to create conditional From b560a2ed7ebba2d83c6e450a6394898f0592b0d6 Mon Sep 17 00:00:00 2001 From: Dan Chaltiel <dan.chaltiel@gmail.com> Date: Wed, 20 Apr 2022 15:49:16 +0200 Subject: [PATCH 3/3] move merge.rd_section_author() back to `rd-markdown.R` --- R/rd-author.R | 7 ------- R/rd-markdown.R | 7 +++++++ 2 files changed, 7 insertions(+), 7 deletions(-) delete mode 100644 R/rd-author.R diff --git a/R/rd-author.R b/R/rd-author.R deleted file mode 100644 index 816b1f8b..00000000 --- a/R/rd-author.R +++ /dev/null @@ -1,7 +0,0 @@ - -#' @export -merge.rd_section_author <- function(x, y, ...) { - stopifnot(identical(class(x), class(y))) - # Remove duplicated authors, e.g. when using @rdname - rd_section(x$type, unique(c(x$value, y$value))) -} diff --git a/R/rd-markdown.R b/R/rd-markdown.R index 95419127..6d2d6cda 100644 --- a/R/rd-markdown.R +++ b/R/rd-markdown.R @@ -10,6 +10,13 @@ roxy_tag_rd.roxy_tag_author <- function(x, base_path, env) { format.rd_section_author <- function(x, ...) { format_collapse(x, ...) } +#' @export +merge.rd_section_author <- function(x, y, ...) { + stopifnot(identical(class(x), class(y))) + # Remove duplicated authors, e.g. when using @rdname + rd_section(x$type, unique(c(x$value, y$value))) +} + #' @export roxy_tag_parse.roxy_tag_format <- function(x) tag_markdown(x)