Skip to content

inheritParams supports a single filtering instance #1879

Description

@dragosmg

It looks like a roxygen2 header can have a single filtering @inheritParams tag.

for example, if a function documents x

#' Add one to numeric vector
#'
#' @param x numeric vector
#'
#' @return a numeric vector
#' @export
add_one <- function(x) {
  x + 1
}

if the second function inherits the documentation for x, it cannot use inherit + filter from another function.

this fails:

#' Add two to numeric vector
#'
#' @inheritParams add_one x
#' @inheritParams rlang::check_bool call
#'
#' @return a numeric vector
#' @export
add_two <- function(x, call = rlang::caller_env()) {
    x + 2
}

with:

> document()
ℹ Updating packageA documentation
ℹ Loading packageA
Run `rlang::last_trace()` to see where the error occurred.
Error in `rd_section_inherit_params_args()`:
! `source` must be a single string, not a character vector.

The error surfaces from

check_string(source)

but succeeds if the second @inheritParams does not filter:

#' Add two to numeric vector
#'
#' @inheritParams add_one x
#' @inheritParams rlang::check_bool 
#'
#' @return a numeric vector
#' @export
add_two <- function(x, call = rlang::caller_env()) {
    x + 2
}

I don't think it's a major issue (definitely one that can be worked around), but it might be useful to document it.

In the past, inheriting (with no filtering) worked with no issues:

#' Add two to numeric vector
#'
#' @inheritParams add_one 
#' @inheritParams rlang::check_bool 
#'
#' @return a numeric vector
#' @export
add_two <- function(x, call = rlang::caller_env()) {
    x + 2
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions