Skip to content

Rendering a parametrised Quarto report for multiple input parameters overwrites output figuresΒ #205

@milanmlft

Description

@milanmlft

Taking the following example Quarto file:

# life_expectancy_report.qmd
---
title: "Life Expectancy Report for `r params$country`"
format: html
params:
  country: "Afghanistan"
---

```{r}
library(tidyverse)
library(gapminder)
```

```{r}
#| label: life-expectancy-data
life_expectancy <-
  gapminder |>
  filter(country == params$country)
```

## Life Expectancy in `r params$country`

```{r}
#| label: life-expectancy-plot
ggplot(life_expectancy, aes(year, lifeExp)) +
  geom_line() +
  theme_minimal()
```

When we generate this report for different countries with the following script:

library(quarto)
countries <- c("Afghanistan", "Belgium", "India", "United Kingdom")

for (country in countries) {
  quarto_render(
    input = "life_expectancy_report.qmd",
    output_file = paste0("life_expectancy_", country, ".html"),
    execute_params = list(country = country)
  )
}

We get a different report for each country, but they will all show the exact same plot (namely the one for the last country).

I suspect this is because Quarto will overwrite life_expectancy_report_files/figure-html/life-expectancy-plot-1.png for each input parameter and thus the final HTML files will all show the same plot.

This behaviour is different from rmarkdown::render(), which would correctly show the specific plot in each report.

Metadata

Metadata

Assignees

No one assigned

    Labels

    upstreamconcerns an upstream library like quarto or pandoc

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions