1

No solution offered yet and cross-posted to RStudio community: https://community.rstudio.com/t/rmarkdown-does-not-render-pdfs-as-batch/136316

I have a rmarkdown file that renders well in RStudio with the Knitr button or with rmarkdown() but does not render when rendered as part of a batch with purrr::walk() and being passed a parameter. The batch issue only occurs when fig.show="hold", out.width="50%" is included in a section of the rmarkdown file.

library(purrr)
library(tinytex)
SurveySet <- c(20,19,68,79,30,18,42)
purrr::walk(
  .x = SurveySet,
  ~ rmarkdown::render(
    input = "Test.Rmd",
    output_file = glue::glue("REPORTS/Report Fails {.x}.pdf"),
    params = list(Unit = {.x})
  )
)
purrr::walk(
  .x = SurveySet,
  ~ rmarkdown::render(
    input = "TestWorks.Rmd",
    output_file = glue::glue("REPORTS/Report Works {.x}.pdf"),
    params = list(Unit = {.x})
  )
)

Test.Rmd as

---
title: "`r params$Unit`"
output: pdf_document
params:
  Unit: 68
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
```

## R Markdown
This Document renders with RStudio Knitr button but not with batch

```{r figures-side, fig.show="hold", out.width="50%"}
par(mar = c(4, 4, .1, .1))
plot(cars)
plot(mpg ~ hp, data = mtcars, pch = 19)
```

TestWorks.Rmd as

---
title: "`r params$Unit`"
output: pdf_document
params:
  Unit: 68
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
```

## R Markdown
Without fig.show="hold", out.width="50%" this document renders individually and as batch

```{r figures}
par(mar = c(4, 4, .1, .1))
plot(cars)
plot(mpg ~ hp, data = mtcars, pch = 19)
```
ajam21
  • 23
  • 4
  • I can't tell you _why_ this is happening, but it seems to be related to the whitespace characters in the output file name. Changing `REPORTS/Report Fails {.x}.pdf` to `REPORTS/Report-Fails-{.x}.pdf` works for me. Not sure why/how this is related to `fig.show` and `out.width`, though. – CL. May 06 '22 at 06:02
  • I have also just discovered that copying the files to the wd, ie. dropping REPORTS/ also seems to work. (Adding the addition argument to render() output_dir = "REPORTS" then seems to make it fail in the same way again.) Your solution to loose whitespace is perhaps more useful and it also works for me. How this is all dependent upon the fig.show and out.width is beyond me. – ajam21 May 06 '22 at 09:11

0 Answers0