Not able to produce paged pdf document when trying to render html_paged rmarkdown document using parameters

I am trying to create a parametric html_paged document.
When I use render function to render the .Rmd file. It creates the paged html document but it doesn't create paged pdf document.
But when I use the knit button. Then it can create both paged html doc and pdf doc.

As I want to make it parametric report, that's why I prefer the render function. Is there a way to produce a paged pdf document using render function. Below is the reproducible example:

---
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 = '\n\n')
```

Now, if I render it using render function.

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

It would create paged html output but it wont't create paged pdf document.
I am using the latest rmarkdown (version 2.3) and pagedown (version 0.11) packages.

This is only to tell the Knit button in the RStudio IDE to use pagedown::chrome_print to render the document.

You can call pagedown::chrome_print on a Rmd file

pagedown::chrome_print("reprex.Rmd")

but currently it don't accept parametrized report.

You would be able to do the same at the command line for parametrized report if only pagedown::chrome_print would take params to render. This is a feature request. For now, you need to do a two step process I think

Try something like

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

I opened one

1 Like

Thank you so much, this was helpful.

1 Like