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
pkgload::run_examplegenerates the errorsubscript out of boundsin the following situation:\donttestblock@examplesIftag instead of the classic@examplesHere is a example:
Created on 2026-04-09 with reprex v2.1.1