如何在渲染時自定義 r quarto pdf 檔案的檔案名?在我使用 Rmarkdown 之前,我在 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"))) })
---
當我點擊“Knit”按鈕時,pdf 檔案的檔案名將是 2022-08-08_Report_FirstLast.pdf
有沒有辦法用 quarto pdf 做到這一點?我認為需要使用quarto_render函式但不知道如何使用。
uj5u.com熱心網友回復:
使用函式的output_file引數quarto_render。
file_name = paste0(Sys.Date(),"_Report","_FirstLast", ".pdf")
quarto_render("your_qmd_file.qmd", output_file = file_name, output_format = "pdf")
現在關于你正在嘗試的方法,
首先,在 quarto AFAIK 中沒有這樣的
knityaml 鍵其次,雖然 r-code 可以用于前綴為 be 的 code-chunk 選項
!expr,但在回答這個問題的那一刻,不可能在檔案 yaml 部分中使用行內 R 代碼(03 Sep, 2022)。請參閱 Github 上的此討論。
盡管在 Github 上的討論quarto_render中有一些在 yaml 中使用 r-code 的建議解決方法,但在您的情況下,使用來控制輸出檔案名似乎是最簡單的選擇。
此外,如果您的輸出檔案名很簡單(即沒有任何 r-code 語法),您可以使用output-fileyaml 選項。
---
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.
這將創建在output_file_name.pdf源檔案所在目錄中命名的輸出檔案。
uj5u.com熱心網友回復:
如果您習慣在 bash shell 中使用 Quarto CLI(這對于自動生成報告可能更方便),您可以像這樣對輸出進行日期標記。
now=`date "%Y-%m-%d"`
quarto render my_doc.qmd --output "./out_$now.pdf" --to pdf
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/504726.html
上一篇:打開pdf頁面
