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

apply knitr print method for inline r code #1193

Merged
merged 22 commits into from
Apr 18, 2022
Merged

Conversation

maxheld83
Copy link
Member

@maxheld83 maxheld83 commented Jan 21, 2021

This replaces the custom roxygen2 evaluation of inline code with default knitr inline.
As such, this enables knit_print() methods and closes #1179.

I'll list the potential problems with this first:

  1. there might have been a good reason to go with a custom treatment of inline code, that I am ignorant of.
  2. this change may change existing documentation (so it's kind of a "breaking" change):
    1. knit_print() methods are applied (which might not always work with the roxygen2 markdown engine)
    2. in the custom engine `r x <- 10` would yield [1] 10.
      Knitr (and console) behavior is to print nothing in this case.
      I've changed the tests accordingly, but this might bite some (hopefully very few?) people.
      Since the whole dynamic R was marked as a beta feature, perhaps this minor breaking change is acceptable.

Advantages include:

  1. brings dynamic code inside roxygen2 more in line with rmarkdown/knitr expectations.
  2. more knitr features (knit_print() and some other niceties.
  3. overall somewhat streamlined test, usage and docs
  4. minor change may be acceptable because feature was marked as experimental.

To the extend that they pertain to inline dynamic R code, I've also streamlined the tests and documentation:

  • examples are simpler (but largely useless)
  • there are a couple more tests

Remaining todos before this read for review:

  • some real-life testing, general maturation
  • docs
  • tests
  • proofreading

@maxheld83 maxheld83 marked this pull request as ready for review January 27, 2021 11:08
@hadley
Copy link
Member

hadley commented Apr 9, 2022

Do you want to try and get this into this release? I'm aiming for release around the end of next week.

@hadley
Copy link
Member

hadley commented Apr 10, 2022

We could finish this one off too, if you wanted?

@maxheld83
Copy link
Member Author

I'm happy with this now, I think it's ready for review.

I have:

  • merged in main and resolved all merge conflicts
  • fixed build failures (an old release didn't support on.exit(after = FALSE), so I used the superior withr idiom instead).
  • completed another proofreading run

@hadley you've previously r-lib/testthat#1308 recommended not to be too clever about reusing code between tests and documentation, because it makes the tests harder to read.
I've violated and am reusing code between the vignette and the tests because:

  • the pattern is already in use with several tests/testthat/roxygen-block-*.Rs
  • the necessary duplication really would be quite onerous, and things are nice and small like this.

Does that seem ok to you @hadley?

Copy link
Member

@hadley hadley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this! I do think it's better to make the tests self-contained even if it leads to some repetition. See my explanation below.

R/markdown.R Outdated Show resolved Hide resolved
R/markdown.R Outdated Show resolved Hide resolved
tests/testthat/test-markdown-code.R Outdated Show resolved Hide resolved
tests/testthat/test-markdown-code.R Outdated Show resolved Hide resolved
vignettes/rd-formatting.Rmd Show resolved Hide resolved
vignettes/rd-formatting.Rmd Outdated Show resolved Hide resolved
vignettes/rd-formatting.Rmd Outdated Show resolved Hide resolved
maxheld83 and others added 8 commits April 16, 2022 23:01
this duplicates the vignette, but should stay in place
Co-authored-by: Hadley Wickham <h.wickham@gmail.com>
Co-authored-by: Hadley Wickham <h.wickham@gmail.com>
Co-authored-by: Hadley Wickham <h.wickham@gmail.com>
these used to be reused between tests and vignette,
but that is discouraged
@maxheld83
Copy link
Member Author

@hadley thanks for the thorough review -- very instructional.
rlang::local_bindings() is a great tip, and no, I would've never looked for it in rlang.

Hope I addressed everything ok and the tests still pass 🙏.

@hadley hadley merged commit 8279a15 into r-lib:main Apr 18, 2022
@hadley
Copy link
Member

hadley commented Apr 18, 2022

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

use knit_print methods for inline R
2 participants