簡體   English   中英

如何更改 Rstudio 中四開文檔的默認 output 位置?

[英]How do I change the default output location of the quarto document in Rstudio?

例如,我的 quarto 文件在D:\myr\index.qmd ,我怎樣才能將生成的 output 文件 PDF 文件到E:\myoutput

output 文件位置可以使用來自{quarto} package 的quarto_render() function 的output_file參數指定。

所以理想情況下,我們可以嘗試這樣的事情,

quarto::quarto_render("index.qmd", output_file = "E:/index.pdf")

索引.qmd

---
title: "Untitled"
format: 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. You can embed code like this:

但這導致我出錯,

ERROR: The system cannot move the file to a different disk drive. (os error 17), 
rename 'index.pdf' -> 'E:/index.pdf'

版本信息

> xfun::session_info()
R version 4.2.1 (2022-06-23 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19044), RStudio 2022.7.1.554

> quarto::quarto_version()
[1] ‘1.0.38’

解決方案

我們可以使用這個 function 將渲染的 output 文件移動到所需的目錄。


render_qmd <- function(input_file, output_path, file_ext, ...) {
    # Extract just the input file name (without the file-extension)
    file_name <- xfun::sans_ext(input_file)

    # render the input document and output file will be in the
    # current working directory.
    quarto::quarto_render(input = input_file, output_format = file_ext, ...)

    # name of the rendered output file
    output_name <- paste0(file_name, ".", file_ext)

    # move the file to the output path
    fs::file_move(paste0(output_name), output_path)

    msg <- paste0(paste0(output_name, collapse = " and "), " moved to ", output_path)
    message(msg)
}

render_qmd("index.qmd", "E:/myoutput", file_ext = "pdf")

請注意,此 function 中使用了包{quarto}{fs}{xfun} 因此,請確保您已安裝這些 pkg。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM