如何在Rstudio中更改quarto文档的默认输出位置?

3
例如,我的四开本文件位于 D:\myr\index.qmd,我该如何将生成的 PDF 文件输出到 E:\myoutput
1个回答

4
输出文件的位置可以通过{quarto}包中的quarto_render()函数的output_file参数进行指定。

因此,我们可以尝试像这样:

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

index.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

解决方案

我们可以使用此函数将渲染输出文件移动到所需目录。


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")


请注意,此函数使用以下包:{quarto}{fs}{xfun}。请确保您已安装这些程序包。

另一种选择是使用fs包在之后移动文件:使用paths <- fs::dir_ls("Documents/input_folder", regexp = "html|pdf")获取路径,然后将文件移动到所需位置: fs::file_move(paths, "Documents/desired_folder") - undefined
嘿,沙菲,你有什么想法为什么会发生这种情况吗?看起来很奇怪,这个问题在一年以来还没有得到解决。 - undefined

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接