Skip to content

Inherit parameter types from source topics and preserve donors during Rename - #899

Open
renkun-ken wants to merge 8 commits into
masterfrom
codex/roxygen-inherit-params
Open

renkun-ken wants to merge 8 commits into
masterfrom
codex/roxygen-inherit-params

Conversation

@renkun-ken

@renkun-ken renkun-ken commented Nov 26, 2026 •

Copy link
Copy Markdown
Member

Part 5 of the review split for #894. This PR targets master after #898 merged.

This adds @inheritParams type propagation and its Rename handling together. A recipient can inherit matching formals from a unique source topic in the same file or package. Local @param documentation takes precedence, including a prose-only description. Unrestricted @inherit donor and @inherit donor params also contribute parameter descriptions. A directive such as @inherit donor title participates in donor Rename without supplying parameter types.

Box <- R6::R6Class("Box", public = list(value = 1L))

#' @param x (`Box`) A box.
donor <- function(x) x

#' @inheritParams donor x
consumer <- function(x) x$value
consumer(Box$new())  # 1L

Renaming an implicit donor topic updates the verified donor token in the directive. The selector is preserved. A qualified donor such as mypkg::donor points to installed help, including when developing mypkg. Local Rename leaves that spelling alone. A fixed @name has its own documentation identity. Rename declines ambiguous ownership, capture, unverifiable edits and formal changes that would invalidate inherited documentation. These protections also apply when documentation-derived inference is disabled.

The package index records consumers by unqualified donor spelling. Parameter inference follows roxygen2’s donor order and applies argument selectors from @inheritParams. The reviewer’s two-donor example selects the first donor, as verified against roxygen2 8.1.0. Tests exercise opened, closed, unsaved and restored source files.

@renkun-ken
renkun-ken added this pull request to stack #909 November 30, 2026 02:07
Base automatically changed from codex/roxygen-generator-references to master December 1, 2026 00:16

@eitsupi eitsupi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed by ChatGPT.

Two concerns regarding compatibility with roxygen2:

  1. Package-qualified inheritance references

    In roxygen2 8.1.0, @inheritParams mypkg::donor resolves to the installed package's documentation, even when mypkg is the package currently being developed. See get_rd() in R/rd-inherit.R.

    The current implementation instead resolves such references to the local source topic and updates them during Rename. This does not match roxygen2's semantics.

    Package-qualified references should not be resolved against local source topics or rewritten during Rename. Supporting inheritance from installed packages can remain outside the scope of this PR.

  2. Interaction with @inherit

    Parameter documentation can also be inherited through @inherit donor params or an unrestricted @inherit donor.

    For example:

    #' @param x (`First`) Input.
    first <- function(x) x
    
    #' @param x (`Second`) Input.
    second <- function(x) x
    
    #' @inherit first params
    #' @inheritParams second
    consumer <- function(x) x

    Ignoring @inherit can lead to inferred types that differ from the documentation generated by roxygen2. Rename may also leave affected inheritance references unchanged.

    Full support for @inherit is not necessary in this PR, but inference and Rename should conservatively handle unsupported inheritance directives rather than assume that @inheritParams describes all relevant dependencies.

Please add regression tests covering these cases.

@renkun-ken
renkun-ken requested a review from eitsupi December 1, 2026 15:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants