Parser bug? "mismatched braces"
I think this comes down to whether or not we are supposed to escape things ourselves in @examples? In any case it took a looong time to figure out what could be going wrong here. I hadn't the slightest inkling to check the % tokens until I popped into the parser C++, so at a minimum we should try and improve the error message.
#' A function
#' @examples
#' \dontrun{
#' # glue::glue(R"['{format(Sys.Date(), "%Y%m%d")}']")
#' # glue::glue(R"['{format(Sys.Date() - 1, "%Y%m%d")}']")
#' }
#' @export
foo <- function() invisible()
roxygenize() will warn:
[foo.R:2] @examples has mismatched braces or quotes
It's extra puzzling since whatever may be mismatched is happening inside a code comment, so I'm surprised it's even evaluated to begin with?
Note that the source comment is required -- uncommenting silences the warning:
#' A function
#' @examples
#' \dontrun{
#' glue::glue(R"['{format(Sys.Date(), "%Y%m%d")}']")
#' glue::glue(R"['{format(Sys.Date() - 1, "%Y%m%d")}']")
#' }
#' @export
foo <- function() invisible()
Came across another example, I can't figure out what the issue is here, I had to end up using @rawRd:
#' @examples
#' StringSubstitute('{greeting} {thing}', thing = 'world', greeting = 'hello')
#' # [1] "hello world"
#' StringSubstitute('{a}', a = '{b}', b = 'c')
#' # [1] "c"
#' StringSubstitute('{a}', b = 'c', a = '{b}')
#' # [1] "{b}"
#' StringSubstitute('\\{greeting\\}', greeting = 'hello') returns
#' # [1] "\\{greeting\\}"
The parser is hand rolled, so quite possible there are problems with my code 😄
Another case:
https://github.com/r-lib/lintr/blob/c315bafb766ef72f532d52533689423f5402d3e2/R/pipe_return_linter.R#L3-L7
Debugging, looks like here's the MRE:
.Call(`_roxygen2_rdComplete`, "`{x %>% y}`", FALSE)
# [1] FALSE
I don't see any handling of ` in the parser, maybe it's as simple as checking for in/out of code region. But I'm not sure if maybe {roxygen2} is meant to be handling the code prior to it being passed to this parser.