简体   繁体   中英

customizing r quarto pdf output file name

How do I customize the filename of r quarto pdf document when I render? Before when I was using Rmarkdown I was using the following code in the YAML:

---
title: "Some title"
author: "First Last"
date: "`r format(Sys.Date(), '%d %B, %Y')`"
output: pdf_document
knit: (function(inputFile, encoding) { rmarkdown::render(inputFile, encoding = encoding, output_file = file.path(dirname(inputFile), paste0(Sys.Date(),"_Report","_FirstLast",".pdf"))) })
---

When I hit the "Knit" button the filename of the pdf document would be 2022-08-08_Report_FirstLast.pdf

Is there a way to do this with quarto pdf? I think the quarto_render function needs to be used but don't know how.

Use the output_file argument of quarto_render function.

file_name = paste0(Sys.Date(),"_Report","_FirstLast", ".pdf")

quarto_render("your_qmd_file.qmd", output_file = file_name, output_format = "pdf")

Now about the approach you are trying,

  • Firstly, there's no such knit yaml key in quarto AFAIK

  • Secondly, although r-code can be used in code-chunk option prefixed be !expr , it's not possible to use inline R code in document yaml section right at this moment of answering this question (03 Sep, 2022) . See this discussion on Github.

Though there are some suggested workaround for using r-code in yaml in this discussion on Github, but using quarto_render to control output filename seems the easiest option in your case.


And additionally, if your output file name is simple (that is, without any r-code syntax), you can use output-file yaml option.

---
title: "Testing Output file name"
format:
   pdf: 
    output-file: "output_file_name"
    output-ext:  "pdf"
---


## Quarto

Quarto enables you to weave together content 
and executable code into a finished document.
To learn more about Quarto 
see <https://quarto.org>.

## Running Code

When you click the **Render** button 
a document will be generated that 
includes both content and the output of 
embedded code. 

This will create the output file named output_file_name.pdf in the directory where the source file is.

If you're comfortable using Quarto CLI in bash shell (which may be more convenient for automatic report generation), you could time-stamp your outputs like this.

now=`date +"%Y-%m-%d"`
quarto render my_doc.qmd --output "./out_$now.pdf" --to pdf

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM