例如,我的四开本文件位于
D:\myr\index.qmd
,我该如何将生成的 PDF 文件输出到 E:\myoutput
?D:\myr\index.qmd
,我该如何将生成的 PDF 文件输出到 E:\myoutput
?{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