quarto-dev / quarto-r

R interface to quarto-cli
https://quarto-dev.github.io/quarto-r/
145 stars 23 forks source link

`quarto_render` not supporting both multiple output formats and a specified output file name #43

Open hgoers opened 2 years ago

hgoers commented 2 years ago

Hello,

In quarto_render(), I am trying both to render multiple format types and to provide the output file with a different name to that of the Quarto document I am using. However, quarto_render() does not adapt this supplied file name to each of the different file types. This results in a single document of type File, which gets overwritten each time the Quarto document renders each format type.

Example:

template.qmd:

---
title: "Example title"
format:
    html:
       toc: true
    docx: 
        toc: true
editor: source
---

This is a simple example file. 

Code to render template.qmd:

library(quarto)

quarto_render(input = "template.qmd",
              output_format = "all",
              output_file = "final_report")

Output: A single final_report document of type File.

Desired output: A final_report.html and a final_report.docx.

Thanks!

hgoers commented 2 years ago

My current workaround is this:

library(quarto)
library(purrr)

map(c("html", "docx"),
    ~ quarto_render(input = "template.qmd",
                    output_format = .x,
                    output_file = paste0("final_report.", .x)))

This produces final_report.html and final_report.docx.

cderv commented 9 months ago

Thinking about this, I think your workaround is a good one because you know what are the output format.

I tested with quarto CLI directly and it will indeed fails

quarto render index.qmd --output final_report

without any warning or workaround (to add an extension).

As this R package is only a wrapper of the CLI, I believe this should be fixed upstream directly, so I'll open an issue there to track this.

Thanks

cderv commented 9 months ago

I opened an issue upstream for this report

Current usage in this use case would be to set output-file config

---
title: "Example title"
output-file: final_report
format:
    HTML:
       toc: true
    docx: 
        toc: true
editor: source
---

From the R function, this could be done through metadata with the dev version of this package

quarto::quarto_render(input = "index.qmd",
                      output_format = "all", 
                      metadata = list(output_file = "final_report")
                      )
hgoers commented 9 months ago

Thanks so much for this!