Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failures with inline R code in multiline @param tags #1112

Closed
salim-b opened this issue Jun 13, 2020 · 3 comments
Closed

Failures with inline R code in multiline @param tags #1112

salim-b opened this issue Jun 13, 2020 · 3 comments
Labels
bug an unexpected problem or unintended behavior markdown ⬇️

Comments

@salim-b
Copy link
Contributor

salim-b commented Jun 13, 2020

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, '"``')`
@gaborcsardi gaborcsardi added the bug an unexpected problem or unintended behavior label Jun 14, 2020
@gaborcsardi
Copy link
Member

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)

@salim-b
Copy link
Contributor Author

salim-b commented Sep 8, 2021

Update: I just realized that the indentation of the second line is central to the bug.

No indentation, no problem:

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 12test}
#> }
#> \description{
#> Title
#> }

Created on 2021-09-09 by the reprex package (v2.0.1)

OTOH, we can escalate the problem with more indentation:

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
#> test     bar 12\verb{r "test"}}
#> }
#> \description{
#> Title
#> }

Created on 2021-09-09 by the reprex package (v2.0.1)

Appears to me there's some erroneous whitespace stripping or the like involved when inline code is replaced with the evaluated strings.

salim-b added a commit to rpkg-dev/pkgpins that referenced this issue Sep 8, 2021
salim-b added a commit to rpkg-dev/pal that referenced this issue Sep 24, 2021
@hadley
Copy link
Member

hadley commented Jul 11, 2022

Fixed in #1391

@hadley hadley closed this as completed Jul 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug an unexpected problem or unintended behavior markdown ⬇️
Projects
None yet
Development

No branches or pull requests

3 participants