diff --git a/DESCRIPTION b/DESCRIPTION index a635ff7875..fcb4906145 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: knitr Type: Package Title: A General-Purpose Package for Dynamic Report Generation in R -Version: 1.48.3 +Version: 1.48.4 Authors@R: c( person("Yihui", "Xie", role = c("aut", "cre"), email = "xie@yihui.name", comment = c(ORCID = "0000-0003-0645-5666")), person("Abhraneel", "Sarma", role = "ctb"), @@ -134,6 +134,7 @@ Suggests: jpeg, JuliaCall (>= 0.11.1), magick, + litedown, markdown (>= 1.3), png, ragg, @@ -156,7 +157,7 @@ License: GPL URL: https://yihui.org/knitr/ BugReports: https://github.com/yihui/knitr/issues Encoding: UTF-8 -VignetteBuilder: knitr +VignetteBuilder: litedown, knitr SystemRequirements: Package vignettes based on R Markdown v2 or reStructuredText require Pandoc (http://pandoc.org). The function rst2pdf() requires rst2pdf (https://github.com/rst2pdf/rst2pdf). Collate: diff --git a/NEWS.md b/NEWS.md index 3cced03f26..fb8bdbd402 100644 --- a/NEWS.md +++ b/NEWS.md @@ -16,6 +16,8 @@ - Changed the format of the reference card from PDF to HTML so building this package will not require LaTeX. See `vignette('knitr-refcard', package = 'knitr')`. +- Switched the vignette engine from **knitr** to `litedown::vignette` for some package vignettes. + # CHANGES IN knitr VERSION 1.48 ## BUG FIXES diff --git a/R/output.R b/R/output.R index 82cbfe2f1d..1cf447e32b 100644 --- a/R/output.R +++ b/R/output.R @@ -132,7 +132,7 @@ knit = function( oconc = knit_concord$get(); on.exit(knit_concord$set(oconc), add = TRUE) if (child_mode()) { - setwd(opts_knit$get('output.dir')) # always restore original working dir + setwd(opts_knit$get('output.dir') %n% '.') # always restore original working dir # in child mode, input path needs to be adjusted if (in.file && !is_abs_path(input)) { input = paste0(opts_knit$get('child.path'), input) diff --git a/vignettes/datatables.Rmd b/vignettes/datatables.Rmd index 38de83a200..ec1c345ec8 100644 --- a/vignettes/datatables.Rmd +++ b/vignettes/datatables.Rmd @@ -1,16 +1,16 @@ --- title: Display Tables with the JavaScript Library DataTables author: Yihui Xie -date: "`r Sys.Date()`" +date: "`{r} Sys.Date()`" output: - markdown::html_format: + litedown::html_format: meta: - css: ["@default", "@prism-xcode", "https://cdn.datatables.net/1.13.7/css/jquery.dataTables.min.css"] + css: ["@default", "https://cdn.datatables.net/1.13.7/css/jquery.dataTables.min.css"] js: ["@npm/jquery@3.7.1/dist/jquery.min.js", "https://cdn.datatables.net/1.13.7/js/jquery.dataTables.min.js"] --- @@ -18,23 +18,24 @@ output: We can use the JavaScript library [**DataTables**](https://datatables.net) to generate enhanced tables in HTML. In the example below, we create a table for the `mtcars` data: -```{r cool, results='asis'} -library(knitr) -kable(mtcars, 'html', table.attr='id="mtcars_table"') +::: {#mtcars-table} +```{r cool, print.args=list(data.frame=list(limit=NULL))} +mtcars ``` +::: Note we assigned an `id` to the table, and next we use the **DataTables** library to initialize the table and you will get an interactive table. ```{js} window.addEventListener('load', () => { - $('#mtcars_table').DataTable(); + $('#mtcars-table > table').DataTable(); }); ``` By comparison, below is an ordinary table: -```{r boring, results='asis'} -kable(head(mtcars), 'html') +```{r boring} +mtcars ``` This vignette is only a toy example. I'd recommend you to use the **DT** package instead: https://github.com/rstudio/DT diff --git a/vignettes/knit_expand.Rmd b/vignettes/knit_expand.Rmd index 4f9f2e9dda..05a896dc62 100644 --- a/vignettes/knit_expand.Rmd +++ b/vignettes/knit_expand.Rmd @@ -1,15 +1,15 @@ --- title: Templating with knit_expand() author: Yihui Xie -date: "`r Sys.Date()`" +date: "`{r} Sys.Date()`" output: - markdown::html_format: + litedown::html_format: meta: - css: ["@default", "@prism-xcode"] + css: ["@default"] --- @@ -56,14 +56,12 @@ res = knit_expand(text = c('{{i=0;h2=function(x){i<<-i+1;sprintf("
', gsub('^\\s*|\\s*$', '', res), '
', sep = '')
+litedown::fuse(unlist(src), 'markdown')
```
-`r res`
diff --git a/vignettes/knit_print.Rmd b/vignettes/knit_print.Rmd
index 096e77aee0..890f483ba0 100644
--- a/vignettes/knit_print.Rmd
+++ b/vignettes/knit_print.Rmd
@@ -3,11 +3,11 @@ title: "Custom Print Methods"
author: "Yihui Xie"
date: '`r Sys.Date()`'
output:
- markdown::html_format:
+ litedown::html_format:
options:
toc: true
meta:
- css: ["@default", "@prism-xcode"]
+ css: ["@default"]
vignette: >
%\VignetteEngine{knitr::knitr_notangle}
%\VignetteIndexEntry{Custom Print Methods}
diff --git a/vignettes/knitr-intro.Rmd b/vignettes/knitr-intro.Rmd
index e4d545e61a..73ba96edcc 100644
--- a/vignettes/knitr-intro.Rmd
+++ b/vignettes/knitr-intro.Rmd
@@ -1,14 +1,13 @@
---
title: "Not An Introduction to knitr"
author: "Yihui Xie"
-date: "`r Sys.Date()`"
+date: "`{r} Sys.Date()`"
output:
- markdown::html_format:
+ litedown::html_format:
meta:
- css: ["@default", "@prism-xcode"]
- js: ["@npm/@xiee/utils/js/center-img.min.js"]
+ css: ["@default"]
vignette: >
- %\VignetteEngine{knitr::knitr_notangle}
+ %\VignetteEngine{litedown::vignette}
%\VignetteIndexEntry{Not an Introduction to knitr}
---
@@ -24,18 +23,18 @@ and knitr" for this package, too.
Anyway, here is a code chunk that shows you can compile vignettes with **knitr**
as well using R 3.0.x, which supports non-Sweave vignettes:
-```{r show-off, tidy=TRUE}
-options(digits=4)
+```{r show-off}
+options(digits = 4)
rnorm(20)
-fit=lm(dist~speed, data=cars)
-b=coef(fit)
+fit = lm(dist ~ speed, data = cars)
+b = coef(fit)
```
```{r echo=FALSE}
-knitr::kable(summary(fit)$coefficients)
+summary(fit)$coefficients
```
-The fitted regression equation is $Y=`r b[1]`+`r b[2]`x$.
+The fitted regression equation is $Y=`{r} b[1]`+`{r} b[2]`x$.
```{r graphics, fig.cap='A scatterplot with a regression line.'}
par(mar=c(4, 4, 1, .1))
diff --git a/vignettes/knitr-markdown.Rmd b/vignettes/knitr-markdown.Rmd
index 7673218671..cbda8bcfe8 100644
--- a/vignettes/knitr-markdown.Rmd
+++ b/vignettes/knitr-markdown.Rmd
@@ -1,15 +1,19 @@
---
-title: An R Markdown (v1) Vignette with knitr
+title: R Markdown (v1) Vignettes with knitr
author: Yihui Xie
-date: "`r Sys.Date()`"
+date: "`{r} Sys.Date()`"
+output:
+ litedown::html_format:
+ meta:
+ css: ["@default"]
---
-This is an example of Markdown vignettes in R. Before R 3.0.0, only Sweave/PDF vignettes were supported in R. Markdown is gaining popularity over the years due to its simplicity, and R 3.0.0 starts to support package vignettes written in R Markdown.
+Before R 3.0.0, only Sweave/PDF vignettes were supported in R. Markdown is gaining popularity over the years due to its simplicity, and R 3.0.0 starts to support package vignettes written in R Markdown.
> Please note this example is for [R Markdown v1](https://cran.r-project.org/package=markdown) only. If you use [R Markdown v2](https://rmarkdown.rstudio.com), you should use the vignette engine `knitr::rmarkdown` instead of `knitr::knitr`.