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

Parsing \dontrun fails with conditionals #1087

Closed
agila5 opened this issue Jul 8, 2019 · 5 comments
Closed

Parsing \dontrun fails with conditionals #1087

agila5 opened this issue Jul 8, 2019 · 5 comments

Comments

@agila5
Copy link

@agila5 agila5 commented Jul 8, 2019

I tried running the examples in the documentation of the do function (tidyverse/dplyr#4394 ) and they seem to work fine. I think that the issue in the documentation is linked to the pkgdown package. The examples with \dontrun fails if they are surrounded by conditionals like

if (TRUE) {
\dontrun{
something
}
}
@IndrajeetPatil

This comment has been hidden.

@hadley

This comment has been hidden.

@agila5

This comment has been hidden.

@hadley
Copy link
Member

@hadley hadley commented Aug 27, 2019

Thanks @agila5!

Here's a minimal reprex created with internal functions:

rd <- pkgdown:::rd_text("\\examples{
  if (TRUE) {
    \\dontrun{1}
  }
}", fragment = FALSE)
str(rd)
#> List of 2
#>  $ :List of 6
#>   ..$ : 'RCODE' chr "\n"
#>   ..$ : 'RCODE' chr "  if (TRUE) {\n"
#>   ..$ : 'RCODE' chr "    "
#>   ..$ :List of 1
#>   .. ..$ : 'VERB' chr "1"
#>   .. ..- attr(*, "class")= chr [1:2] "tag_dontrun" "tag"
#>   ..$ : 'RCODE' chr "\n"
#>   ..$ : 'RCODE' chr "  }\n"
#>   ..- attr(*, "class")= chr [1:2] "tag_examples" "tag"
#>  $ : 'TEXT' chr "\n"
#>  - attr(*, "class")= chr [1:2] "Rd" "tag"

cat(pkgdown:::as_data.tag_examples(rd[[1]]))
#> <div class='input'>  if (TRUE) {
#>     </div><div class='output co'>#&gt; <span class='error'>Error: &lt;text&gt;:3:0: unexpected end of input</span>
#> #&gt; <span class='error'>1:   if (TRUE) {</span>
#> #&gt; <span class='error'>2:     </span>
#> #&gt; <span class='error'>  ^</span></div><span class='co'># NOT RUN {</span>
#> <span class='fl'>1</span>
#> <span class='co'># }</span><div class='input'>  }
#> </div><div class='output co'>#&gt; <span class='error'>Error: &lt;text&gt;:1:3: unexpected '}'</span>
#> #&gt; <span class='error'>1:   }</span>
#> #&gt; <span class='error'>      ^</span></div>

Created on 2019-08-27 by the reprex package (v0.3.0)

And similarly if we use \ldots:

rd <- pkgdown:::rd_text("\\examples{
  foo(\\ldots)
}", fragment = FALSE)
str(rd)
#> List of 2
#>  $ :List of 4
#>   ..$ : 'RCODE' chr "\n"
#>   ..$ : 'RCODE' chr "  foo("
#>   ..$ : list()
#>   .. ..- attr(*, "class")= chr [1:2] "tag_ldots" "tag"
#>   ..$ : 'RCODE' chr ")\n"
#>   ..- attr(*, "class")= chr [1:2] "tag_examples" "tag"
#>  $ : 'TEXT' chr "\n"
#>  - attr(*, "class")= chr [1:2] "Rd" "tag"

cat(pkgdown:::as_data.tag_examples(rd[[1]]))
#> <div class='input'>  foo(</div><div class='output co'>#&gt; <span class='error'>Error: &lt;text&gt;:2:0: unexpected end of input</span>
#> #&gt; <span class='error'>1:   foo(</span>
#> #&gt; <span class='error'>   ^</span></div># NOT RUN {
#> &#8230;
#> # }
#> <div class='input'>)
#> </div><div class='output co'>#&gt; <span class='error'>Error: &lt;text&gt;:1:1: unexpected ')'</span>
#> #&gt; <span class='error'>1: )</span>
#> #&gt; <span class='error'>    ^</span></div>

Created on 2019-08-27 by the reprex package (v0.3.0)

@hadley
Copy link
Member

@hadley hadley commented Aug 27, 2019

The key resource for understanding the parsing here is https://developer.r-project.org/parseRd.pdf and tools::Rd2ex(). Carefully reading its source suggests that as well as \dontrun, \donttest, \dontshow, \testonly and \ldots, I also need to handle \dots, \if, \ifelse, and \out.

@hadley hadley closed this in e6ab00a Aug 29, 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
3 participants