Skip to content

roxygenising fails when inheriting a shared description #1925

Description

@JesseAlderliesten

Bug description

Documenting multiple arguments with a shared description (i.e., using the form @param x2,x3 second and third argument) leads to an error when inheriting filtered arguments of that function, even if the inherited arguments are not in this 'special' format, e.g., inheriting x1 from toy_fun_parent(), see below).

Setup for reprex

library(usethis)
path <- withr::local_tempdir(pattern = "inheritargs", clean = TRUE)
desc <- desc::description$new("!new")
desc$write(file = fs::path(path, "DESCRIPTION"))
local_project(path)

Creating functions

Create toy_fun_parent() in which arguments x2 and x3 share a single description:

use_r("toy_fun_parent")

Paste the following code in the created file:

#' Toy parent function
#' @param x1 first argument
#' @param x2,x3 second and third argument
#' @param x4 fourth argument
#' @returns NULL
#' @export
toy_fun_parent <- function(x1, x2, x3, x4) {
  NULL
}

Then create toy_fun_child() that inherits argument x1 from toy_fun_parent():

use_r("toy_fun_child")

Paste the following code in the created file

#' Toy child function
#' @inheritParams toy_fun_parent x1
#' @returns NULL
#' @export
toy_fun_child <- function(x1) {
  NULL
}

Triggering the bug

After saving the created function files, roxygenising leads to an error:

# Code taken from `devtools::document()` because that is how I encountered the error
roxygen2::roxygenise(devtools::as.package(".")$path, roclets = NULL)
# Error in vapply(.x, .f, .mold, ..., USE.NAMES = FALSE) :
#   values must be length 1,
# but FUN(X[[2]]) result is length 2

That error apparently occurs because .rlang_purrr_map_mold() (source code) produces a length-two result (i.e., one for x2 and one for x3) whereas vapply() expects a length-one result.

traceback()
10: vapply(.x, .f, .mold, ..., USE.NAMES = FALSE)
9: .rlang_purrr_map_mold(.x, .f, character(1), ...)
8: map_chr(inherited_params, "[[", "name")
7: fun(topic, self, ...)
6: topics$topo_apply(inherits("params"), inherit_params)
5: topics_process_inherit(topics, env)
4: roclet_process.roclet_rd(X[[i]], ...)
3: FUN(X[[i]], ...)
2: lapply(roclets, roclet_process, blocks = blocks, env = env, base_path = base_path)
1: roxygen2::roxygenise(devtools::as.package(".")$path, roclets = NULL)

Unfortunately I do not understand the syntax of inherited_params or topo_apply(), so I was not able to propose a fix.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions