roxygen2 icon indicating copy to clipboard operation
roxygen2 copied to clipboard

New `rd_section_minidesc` error with roxygen2 7.2.1

Open mjsteinbaugh opened this issue 1 year ago • 3 comments

With the roxygen2 7.2.1 update, I'm now seeing this error in one of my packages, and I'm having trouble locating the source:

Error in rd_section_minidesc(name = object_name(block$object), desc = tag$val$description,  :
  is_string(name) is not TRUE
Calls: <Anonymous> ... <Anonymous> -> inherits -> rd_section_minidesc -> stopifnot
Backtrace:
     ▆
  1. └─devtools::document()
  2.   └─roxygen2::roxygenise(pkg$path, roclets)
  3.     └─base::lapply(...)
  4.       ├─roxygen2 (local) FUN(X[[i]], ...)
  5.       └─roxygen2:::roclet_process.roclet_rd(X[[i]], ...)
  6.         ├─roxygen2:::block_to_rd(block, base_path, env)
  7.         └─roxygen2:::block_to_rd.roxy_block(block, base_path, env)
  8.           └─roxygen2:::topic_add_describe_in(rd, block, env)
  9.             ├─topic$add(...)
 10.             │ └─base::inherits(x, "RoxyTopic")
 11.             └─roxygen2:::rd_section_minidesc(...)
 12.               └─base::stopifnot(is_string(name))

Any ideas on how to improve the stack trace here? Would it be possible to modify the error handling to return which file is problematic?

Best, Mike

mjsteinbaugh avatar Aug 18 '22 17:08 mjsteinbaugh

Use options(error = recover) and then try to find more info interactively in the roxygen2 frames.

gaborcsardi avatar Aug 18 '22 19:08 gaborcsardi

Cool thanks I'll try that!

mjsteinbaugh avatar Aug 18 '22 21:08 mjsteinbaugh

I'm running into the same issue.

I think it is related to a @describeIn tag. Using @gaborcsardi's suggestion above I think I tracked it down to that line: https://github.com/r-lib/roxygen2/blob/07e4d1d5d1f70a1ab79089e78de9fa58bd98cf76/R/rd-describe-in.R#L29 This returns NULL instead of a string, and roxygen2:::rd_section_minidesc(...) chokes expecting is_string(name) to be true. In this case I would assume that object_name() should return the equivalent of block$object$topic, the topic in which the block should be described.

For context, below is the code that lead to the issue. For that block the output of block$object$topic is "sspm_discrete_boundary-class".

See code
# -------------------------------------------------------------------------

#' sspm boundary structure
#'
#' One of the first step in the `sspm` workflow is to create one or more
#' object(s) of class `sspm_boundary` from an `sf` object.
#'
#' @slot boundaries **\[sf\]** Spatial boundaries (polygons).
#' @slot boundary **\[character\]** The column of `data` that represents the
#'     spatial boundaries.
#' @slot boundary_area **\[character\]** The column of `data` that represents the
#'     area of spatial boundaries.
#' @slot method **\[[discretization_method][discretization_method-class]\]**
#'     *(if discrete)* discretization method used.
#' @slot patches **\[sf\]** *(if discrete)* Patches resulting from
#'     discretization.
#' @slot points **\[sf or NULL\]** *(if discrete)* Sample points used for
#'     discretization.
#' @slot patches_area **\[character\]** The column of `data` that represents the
#'     area of patches.
#'
#' @name sspm_boundary-class
#' @rdname sspm_boundary-class
#'
setClass("sspm_boundary",
         slots = list(boundaries = "sf",
                      boundary = "character",
                      boundary_area = "character")
)

#' @describeIn sspm_boundary-class sspm_discrete_boundary
setClass("sspm_discrete_boundary",
         slots = list(method = "discretization_method",
                      patches_area = "character",
                      patches = "sf",
                      points = "ANY"),
         contains = "sspm_boundary"
)

VLucet avatar Aug 22 '22 16:08 VLucet

I'm running into this same issue. It is really hard to track, especially as I'm not even given a file name, so I don't know where to start. There needs to be better handling of context information when running into even an unexpected error.

ralmond avatar Jun 21 '23 16:06 ralmond

This should be better in the dev version, but no one provided a reprex, so I can't be sure.

hadley avatar Nov 21 '23 18:11 hadley