Roxygen2: Failures with inline R code in multiline @param tags

Created on 13 Jun 2020  ·  1Comment  ·  Source: r-lib/roxygen2

Consider the following @param tag:

#' @param some_param Some dynamically generated parameter documentation whose last 2 static
#'   chars are swallowed and instead contains a spurious ")'" at the end: 12`r paste0("test")`

When roxygen2 (latest 7.1.1.9001) renders this to .Rd, it swallows the last two "static" characters (12) and outputs two additional characters ()`) at the end of the parsed inline R code which shouldn't be there:

\item{some_param}{Some dynamically generated parameter documentation whose last 2 static
chars are swallowed and instead contains a spurious ")'" at the end: test)`}

Instead, it should actually produce this .Rd:

\item{some_param}{Some dynamically generated parameter documentation whose last 2 static
chars are swallowed and instead contains a spurious ")'" at the end: 12test}

The underlying issue looks like some "off-by-two"-error. The inline R code

... at the end: 12`r paste0("test")`

should be parsed to:

... at the end: 12test

but wrongly becomes:

... at the end: test)`


I simplified the inline R code in the above example as much as possible, thus it doesn't make much sense. What I was originally trying to do is auto-generate some doc in pkgsnip like this:

#' @param snippet The name of a snippet. Possible values include:
#'   `r paste0('- ``"', ls_file_snips()$name, '"``')`

bug markdown

Most helpful comment

Reprex:

roxygen2::roc_proc_text(roxygen2::rd_roclet(), "
  #' Title
  #' 
  #' @param some_param Foo 
  #'   bar 12`r paste0(\"test\")`
  #' @md
  foo <- function(some_param) {}
")
#> $foo.Rd
#> % Generated by roxygen2: do not edit by hand
#> % Please edit documentation in ./<text>
#> \name{foo}
#> \alias{foo}
#> \title{Title}
#> \usage{
#> foo(some_param)
#> }
#> \arguments{
#> \item{some_param}{Foo
#> bar test)`}
#> }
#> \description{
#> Title
#> }

Created on 2020-06-14 by the reprex package (v0.3.0)

>All comments

Reprex:

roxygen2::roc_proc_text(roxygen2::rd_roclet(), "
  #' Title
  #' 
  #' @param some_param Foo 
  #'   bar 12`r paste0(\"test\")`
  #' @md
  foo <- function(some_param) {}
")
#> $foo.Rd
#> % Generated by roxygen2: do not edit by hand
#> % Please edit documentation in ./<text>
#> \name{foo}
#> \alias{foo}
#> \title{Title}
#> \usage{
#> foo(some_param)
#> }
#> \arguments{
#> \item{some_param}{Foo
#> bar test)`}
#> }
#> \description{
#> Title
#> }

Created on 2020-06-14 by the reprex package (v0.3.0)

Was this page helpful?
0 / 5 - 0 ratings