From 630ab47cff290e94380e0bfa57d6de964c722af3 Mon Sep 17 00:00:00 2001 From: Hadley Wickham Date: Thu, 28 Apr 2022 13:02:24 -0500 Subject: [PATCH] Handle case where param matches more than once --- R/rd-inherit.R | 5 ++++- tests/testthat/test-rd-inherit.R | 23 ++++++++++++++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/R/rd-inherit.R b/R/rd-inherit.R index 0802b343..61141685 100644 --- a/R/rd-inherit.R +++ b/R/rd-inherit.R @@ -176,7 +176,10 @@ match_param <- function(from, to) { return(NULL) } - unique(c(to, to)[match(from, to_std)]) + union( + setdiff(to[match(from, to)], NA), + setdiff(to[match(from, flip_dot(to))], NA) + ) } inherit_dot_params <- function(topic, topics, env) { diff --git a/tests/testthat/test-rd-inherit.R b/tests/testthat/test-rd-inherit.R index f7afe85c..eda8203a 100644 --- a/tests/testthat/test-rd-inherit.R +++ b/tests/testthat/test-rd-inherit.R @@ -290,6 +290,7 @@ test_that("match_params can ignore . prefix", { expect_equal(match_param(c(".x", "y"), c(".x", ".y", ".z")), c(".x", ".y")) expect_equal(match_param(c(".x", "x"), c("x", ".x")), c(".x", "x")) expect_equal(match_param(c(".x", "x"), "x"), "x") + expect_equal(match_param("x", c(".x", "x")), c("x", ".x")) }) test_that("multiple @inheritParam tags gathers all params", { @@ -299,7 +300,6 @@ test_that("multiple @inheritParam tags gathers all params", { #' @param x X a <- function(x) {} - #' B #' #' @param y Y @@ -354,6 +354,27 @@ test_that("@inheritParam preserves mixed names", { expect_equal(out$get_value("param"), c(".x,x" = "X")) }) +test_that("can inherit from same arg twice", { + out <- roc_proc_text(rd_roclet(), " + #' A. + #' + #' @param x X + a <- function(x) {} + + #' B + #' + #' @inheritParams a + b <- function(x) {} + + #' C + #' + #' @inheritParams a + #' @rdname b + c <- function(.x) {} + ")[[2]] + expect_equal(out$get_value("param"), c("x,.x" = "X")) +}) + test_that("@inheritParams can inherit from inherited params", { out <- roc_proc_text(rd_roclet(), " #' C