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

Parser bug? "mismatched braces" #1492

Open
MichaelChirico opened this issue Jun 30, 2023 · 2 comments
Open

Parser bug? "mismatched braces" #1492

MichaelChirico opened this issue Jun 30, 2023 · 2 comments
Labels
bug an unexpected problem or unintended behavior rd ✍️

Comments

@MichaelChirico
Copy link
Contributor

MichaelChirico commented Jun 30, 2023

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()
@MichaelChirico
Copy link
Contributor Author

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\\}"

@hadley hadley added bug an unexpected problem or unintended behavior rd ✍️ labels Nov 1, 2023
@hadley
Copy link
Member

hadley commented Nov 1, 2023

The parser is hand rolled, so quite possible there are problems with my code 😄

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 rd ✍️
Projects
None yet
Development

No branches or pull requests

2 participants