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

Escaped quote not parsed correctly #873

Closed
espinielli opened this issue Jun 19, 2019 · 3 comments
Closed

Escaped quote not parsed correctly #873

espinielli opened this issue Jun 19, 2019 · 3 comments

Comments

@espinielli
Copy link

@espinielli espinielli commented Jun 19, 2019

Examples with strings containing quoted quotation marks (char ", ASCII 34) are not parsed correctly and do not show up in the output .Rd file.
A simplified reproducible example is shown at the bottom.

A realistic one from my code (containing strings with both quotation mark character (" or ASCII 34) and apostrophe character (' or ASCII 39)) is the following:

#' Convert  Degree Minute Seconds (DMS) format to Decimal Degrees (DD)
#'
#' @param value a string representation of an angle (i.e. longitude) in
#'              Degree Minute Second (DMS)), i.e. "51° 43' 34.00\" N"
#'              Note the escaping of double quote.
#'
#' @return a decimal degrees value
#' @export
#'
#' @examples
#' \dontrun{
#' tribble(
#'             ~latitude,           ~longitude,   ~id,
#'   "51° 43' 34.00\" N", "000° 32' 59.00\" W", "BNN",
#'   "51° 19' 51.15\" N", "000° 02' 05.32\" E", "BIG",
#'   "51° 38' 46.00\" N", "000° 09' 06.00\" E", "LAM",
#'   "51° 18' 18.00\" N", "000° 26' 50.00\" W", "OCL"
#' ) %>% mutate(latitude  = ddm2dd(latitude),
#'              longitude = ddm2dd(longitude))
#' }
dms2dd <- function(value) {
  # ...
}

Here is a reprex for a simplified case:

library(roxygen2)
lines <- c("#' with escaped quotation mark",
           "#' @examples",
           "#' \"34.00\\\"\"",
           "h <- function() {}")

writeLines(lines)
#> #' with escaped quotation mark
#> #' @examples
#> #' "34.00\""
#> h <- function() {}

roc_proc_text(rd_roclet(), lines)
#> Warning: @examples [C:/Users/spi/Documents/R/win-library/3.5/
#> temp\RtmpuEYWhL\filec5870af65b9e#3]: mismatched braces or quotes
#> $h.Rd
#> % Generated by roxygen2: do not edit by hand
#> % Please edit documentation in RtmpuEYWhL/filec5870af65b9e
#> \name{h}
#> \alias{h}
#> \title{with escaped quotation mark}
#> \usage{
#> h()
#> }
#> \description{
#> with escaped quotation mark
#> }

Created on 2019-06-19 by the reprex package (v0.3.0)

@espinielli espinielli changed the title strings with quoted quotation mark (") in examples does not render in .Rd string with quoted quotation mark (") in examples does not render in .Rd Jun 19, 2019
@hadley hadley changed the title string with quoted quotation mark (") in examples does not render in .Rd Escaped quote not parsed correctly Jul 21, 2019
@hadley
Copy link
Member

@hadley hadley commented Jul 21, 2019

The problem is specifically with the mismatched braces or quotes; it seems like roxygen2 is failing to handle the escape correctly. Slightly more minimal reprex:

library(roxygen2)
out <- roc_proc_text(rd_roclet(), "
  #' with escaped quotation mark
  #' @examples
  #' '34.00\''
  h <- function() {}
")
#> Warning: @examples [/tmp/Rtmpvb1beU/filef5c3560a55d6#4]: mismatched braces
#> or quotes

Created on 2019-07-21 by the reprex package (v0.3.0)

@hadley
Copy link
Member

@hadley hadley commented Jul 25, 2019

Oops my reprex was slightly off — It should be:

library(roxygen2)
out <- roc_proc_text(rd_roclet(), "
  #' with escaped quotation mark
  #' @examples
  #' '34.00\\''
  h <- function() {}
")
#> Warning: @examples [/tmp/RtmpVuA2Uf/file90ef5044bb20#4]: mismatched braces
#> or quotes

rdComplete() seems to be working correctly, but maybe there's a layer of escaping I'm missing?

roxygen2:::rdComplete("'34.00'", is_code = TRUE)
#> [1] TRUE
roxygen2:::rdComplete("'34.00\\''", is_code = TRUE)
#> [1] TRUE

@hadley
Copy link
Member

@hadley hadley commented Jul 25, 2019

Ah, the problem is escape_examples() which adds an extra backslash:

x1 <- "'34.00\\''\n"
cat(x1)
#> '34.00\''

x2 <- roxygen2:::escape_examples(x1)
cat(x2)
#> '34.00\\''

roxygen2:::rdComplete(x2, is_code = TRUE)
#> [1] FALSE

Maybe escape() shouldn't be escaping things that are already in strings?

@hadley hadley closed this in 57e3649 Sep 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants