r-尝试使用参数呈现html_paged-rmarkdown文档时,无法生成分页pdf文档



我正在尝试创建一个参数化的html_paged文档。当我使用render函数来渲染。Rmd文件。它创建分页的html文档,但不创建分页的pdf文档。但当我使用针织纽扣时。然后它可以创建分页的html文档和pdf文档。

因为我想让它成为参数化报告,所以我更喜欢渲染函数。有没有一种方法可以使用render函数生成一个分页的pdf文档。以下是可复制的示例:

---
title: "A Multi-page HTML Document"
author: "Yihui Xie and Romain Lesur"
date: "`r Sys.Date()`"
output:
pagedown::html_paged:
toc: true
# change to true for a self-contained document, but it'll be a litte slower for Pandoc to render
self_contained: false
# uncomment this line to produce HTML and PDF in RStudio:
knit: pagedown::chrome_print
params:
test: 'html' 
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
# Introduction
This is an example of a multi-page HTML document. See https://pagedown.rbind.io for the full documentation. The rest of this document is random text.
# Random text
```{r, results='asis', echo = FALSE}
random_markdown = function(len = 100) {
uri = knitr::image_uri(file.path(R.home('doc'), params$test, 'logo.jpg'))
text = function(len) {
trimws(paste(sample(c(letters, rep(' ', 10)), len, TRUE), collapse = ''))
}
id = function() paste(sample(letters, 8, TRUE), collapse = '')
figure = function() {
sprintf('![(#fig:%s)The R logo.](%s){width=%d%%}', id(), uri, sample(20:60, 1))
}
tab = paste(knitr::kable(head(mtcars[, 1:5])), collapse = 'n')
table = function() {
c(sprintf('Table: (#tab:%s)A table example.', id()), tab)
}
unlist(lapply(seq_len(len), function(i) {
if (i %% 20 == 0) return(paste('#', text(sample(10:30, 1))))
if (i %% 10 == 0) return(paste('##', text(sample(10:30, 1))))
type = sample(1:3, 1, prob = c(.9, .03, .07))
switch(type, text(sample(50:300, 1)), figure(), table())
}))
}
cat(random_markdown(), sep = 'nn')
```

现在,如果我使用render函数来渲染它。

rmarkdown::render("reprex.Rmd", params=list(test="html"))

它会创建分页的html输出,但不会创建分页的pdf文档
我使用的是最新的rmarkdown(版本2.3(和pagedown(版本0.11(软件包。

我在这里找到了解决方案:

根据建议,目前chrome_print不支持传递参数。此功能已在此处请求。目前,我必须在下面这样的两步过程中创建参数化的页面pdf报告,这似乎很好。

output <- rmarkdown::render("reprex.Rmd", params=list(test="html"))
pagedown::chrome_print(output)

最新更新