Skip to content

Examples with \donttest and @examplesIf: subscript out of bounds #329

@TanguyBarthelemy

Description

@TanguyBarthelemy

pkgload::run_example generates the error subscript out of bounds in the following situation:

  • If all the code of the example is in a \donttest block
  • AND if there is a @examplesIf tag instead of the classic @examples

Here is a example:

content <- "
\\name{test}
\\title{Test}
\\examples{
\\dontshow{if (2+2 > 3) withAutoprint(\\{ # examplesIf}
\\donttest{2+2}
\\dontshow{\\}) # examplesIf}
}
"

doc_path <- tempfile(fileext = ".Rd")

write(content, doc_path)
pkgload::run_example(path = doc_path)
#> 
#> > ### Name: test
#> > ### Title: Test
#> > 
#> > ### ** Examples
#> > 
#> > ## Don't show: 
#> > if (2+2 > 3) withAutoprint({ # examplesIf
#> + ## End(Don't show)
#> + ## No test: 
#> + ##D 2+2
#> + ## End(No test)
#> + ## Don't show: 
#> + }) # examplesIf
#> Error in `srcrefs[[1L]]`:
#> ! subscript out of bounds

Created on 2026-04-09 with reprex v2.1.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    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