Skip to content

use litedown for rendering vignettes #6583

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

Open
wants to merge 30 commits into
base: master
Choose a base branch
from
Open

use litedown for rendering vignettes #6583

wants to merge 30 commits into from

Conversation

ben-schwen
Copy link
Member

@ben-schwen ben-schwen commented Oct 19, 2024

Closes #6394
Towards #6584

Copy link

codecov bot commented Oct 19, 2024

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.77%. Comparing base (84b0e32) to head (ea7eec4).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6583      +/-   ##
==========================================
- Coverage   98.77%   98.77%   -0.01%     
==========================================
  Files          81       81              
  Lines       15215    15213       -2     
==========================================
- Hits        15029    15027       -2     
  Misses        186      186              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ben-schwen
Copy link
Member Author

ben-schwen commented Oct 20, 2024

This PR is on hold until current GH version of xfun makes its way to CRAN.

@MichaelChirico
Copy link
Member

Earmark: after #6589, if {knitr} is not in Suggests it should be in Enhances.

@MichaelChirico
Copy link
Member

NB: After #6618, we'll also want to check this issue whether it should be included, or left as a TODO: yihui/litedown#67

Copy link

@yihui yihui left a comment

Choose a reason for hiding this comment

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

NB: After #6618, we'll also want to check this issue whether it should be included, or left as a TODO: yihui/litedown#67

It's safe to use litedown:::.env$input with the current CRAN version of litedown. The next CRAN release should take place in a few weeks, and you'll be able to use litedown::get_context('input').

@rikivillalba
Copy link
Contributor

Sorry I meant to push a sub-branch to merge but instead forget to switch and pushed the commit directly.
The commit updates the translation script with litedown and changes instances of `r ...` to `{r} ...` as is recognized by litedown

@@ -26,9 +26,9 @@ h2 {
}
</style>

```{r echo=FALSE, file='_translation_links.R'}
```{r, echo=FALSE, file='_translation_links.R'}
Copy link
Member

Choose a reason for hiding this comment

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

i imagine this will later trigger a test for un-named chunks, are names supported in this context?

@jangorecki
Copy link
Member

xfun is fixed on CRAN so we could proceed with this issue, isn't it? @ben-schwen

@ben-schwen
Copy link
Member Author

ben-schwen commented Apr 21, 2025

xfun is fixed on CRAN so we could proceed with this issue, isn't it? @ben-schwen

Yes. Only blocker, I'm aware of now is that := is printing on litedown and not printing on knitr

aitap added 2 commits April 22, 2025 12:50
Since we register a method for knitr::knit_print, keep it mentioned in
the DESCRIPTION.
As with knit_print, avoid printing x when !shouldPrint(x). Use the
overloaded method in the vignettes instead of relying on the
auto-printing detection in print.data.table.
@aitap
Copy link
Contributor

aitap commented Apr 22, 2025

This can be solved similarly to #6589, except that methods for xfun::record_print must return the printed output, not print it:

library(data.table)
library(xfun)
x <- data.table(a = 1)
xfun::record('x[,a:=1]') |> print(browse = FALSE)
# x[,a:=1]
# 
# #>        a
# #>    <num>
# #> 1:     1
#
.S3method(
  'record_print', 'data.table',
  \(x, ...) if (!shouldPrint(x)) character() else NextMethod()
)
xfun::record('x[,a:=1]') |> print(browse = FALSE)
# x[,a:=1]
# 
xfun::record('x[,a:=1][]') |> print(browse = FALSE)
# x[,a:=1][]
# 
# #>        a
# #>    <num>
# #> 1:     1
# 

Additionally, inline expressions of the form `r ... ` aren't parsed the same way. For example, data.table-intro.Rmd uses

In (1), for each group, a vector is returned, with length = 6,4,2 here. However, (2) returns a list of length 1 for each group, with its first element holding vectors of length 6,4,2. Therefore, (1) results in a length of ` 6+4+2 = `r 6+4+2``, whereas (2) returns `1+1+1=`r 1+1+1``.

...and with litedown, the inline expressions inside code blocks are not evaluated.

At some point we'll need to transition the translated vignettes too, right?

@ben-schwen ben-schwen requested review from a team, jangorecki and tdhock as code owners July 7, 2025 21:17
@@ -182,6 +182,9 @@ if (loaded[["knitr"]]) {
# Which is fine and works thanks to cedta().
DT = data.table(x=1, y=2)
test(11, kable(DT), output="x.*y.*1.*2")
invisible(knit(testDir("knitr.Rmd"), quiet=TRUE))
Copy link
Member

Choose a reason for hiding this comment

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

I think we can delete the Rout.mock, right? IIRC that only exists to mock out when {knitr} is not installed, but other.Rraw should always be run where all the required packages are available, in dev.

Copy link
Member

Choose a reason for hiding this comment

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

We may way to migrate this check to litedown

tests/knitr.R Outdated
Copy link
Member

Choose a reason for hiding this comment

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

Should we instead replace this with tests/litedown.R?

At a minimum we should add a regression test of the new xfun method in other.Rraw.

Copy link
Member

Choose a reason for hiding this comment

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

Yes

Copy link
Member

@MichaelChirico MichaelChirico left a comment

Choose a reason for hiding this comment

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

I think this is ready to ship after maybe another round of touch-up as commented.

Feel free to mark any of my comments for follow-up.

Great work!

@jangorecki
Copy link
Member

Are there links for rendered versions?

Copy link
Contributor

@aitap aitap left a comment

Choose a reason for hiding this comment

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

In datatable-intro.Rmd, by-group j-expressions that call print() render like:

DT[, print(.SD), by = ID]
#        a     b     c
#    <int> <int> <int>
# 1:     1     7    13
# 2:     2     8    14
# 3:     3     9    15
#        a     b     c
#    <int> <int> <int>
# 1:     4    10    16
# 2:     5    11    17
#        a     b     c
#    <int> <int> <int>
# 1:     6    12    18
ID

I wonder where is the last ID coming from.


I couldn't make the `some text `r expression(...)`` syntax work in Litedown and wrote a replacement function for datatable-intro.Rmd.

In datatable-reference-semantics.Rmd, the CSS class syntax #### {.bs-callout .bs-callout-info} does not work; it produces a level-4 heading titled {.bs-callout .bs-callout-info} instead.

@MichaelChirico
Copy link
Member

NB: please Update branch before merging & possibly include #7151.

@aitap
Copy link
Contributor

aitap commented Jul 10, 2025

Unfortunately, pkgdown::build_site does not understand the new `{r} expression...` syntax in the vignettes, so the translation marks are lost, and so is other dynamic text.

@MichaelChirico
Copy link
Member

Per the {litedown} README, {litedown} itself is supposed to do the site rendering, right?

Otherwise, we should ask the {pkgdown} maintainers to support {litedown} rendering; IINM, the issue is that {pkgdown} relies on {rmarkdown} to render:

https://github.com/r-lib/pkgdown/blob/824ab4a4f20ecd895282b434d8652120e1f62ba4/R/build-article.R#L294
https://github.com/r-lib/pkgdown/blob/824ab4a4f20ecd895282b434d8652120e1f62ba4/R/build-article.R#L114

@jangorecki
Copy link
Member

It does support basic website.
https://github.com/jangorecki/pkgup/blob/a1ec87d02209423a28c432c92b7269a086cd3e7b/.github/workflows/pkgup.yaml#L56
https://jangorecki.github.io/pkgup/

pkgdown could support it anyway, but not sure if and how fast that will happen.
pkgdown did not support well markdown vignettes in the past, only rmarkdown.

@ChristianWia
Copy link
Contributor

ChristianWia commented Jul 24, 2025

comparing the results of html vignette generation with knitr and litedown on "data-table-joins.Rmd" :
litedownKnitrCompared.txt

knitr/litedown diff screenshot section 7.2:
litedownKnitrSection72

litedown resulting file to follow the comments:
litedownJointuresavecdatatable.pdf

My Windows environment :

R version 4.0.2 (2020-06-22) -- "Taking Off Again"
Copyright (C) 2020 The R Foundation for Statistical Computing
Platform: x86_64-w64-mingw32/x64 (64-bit)

installation from CRAN source packages : ‘commonmark’, ‘xfun’, ‘litedown’

URL 'https://pbil.univ-lyon1.fr/CRAN/src/contrib/commonmark_2.0.0.tar.gz'
URL 'https://pbil.univ-lyon1.fr/CRAN/src/contrib/xfun_0.52.tar.gz'
URL 'https://pbil.univ-lyon1.fr/CRAN/src/contrib/litedown_0.7.tar.gz'

@jangorecki
Copy link
Member

comparing the litedownKnitrCompared.txt results of html vignette generation with knitr and litedown on "data-table-joins.Rmd"

This may be as well interesting for @yihui

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.

Explore {litedown} for rendering vignettes
7 participants