bookdown:自定义输出文件名

bookdown: customize the output filename

这是对我之前在这里提出的一个问题的跟进: Bookdown 允许将文件编译成各种格式,包括多个 pdf。因此,问题是给输出不同的名称。如果没有,第二个 pdf 编译覆盖第一个!

在我之前问题的评论中,我写道:"I just need to understand how to change the file name - because bookdown::pdf_book and bookdown::pdf_document2 output to the same file - which gets therefore overwritten! I know how to change filenames and locations for all files at once using _bookdown.yml, but I do not know how to do it for individual files.... i will search more online, but did not see anything so far - do I need to post another question for this if I cannot find anything?"
YiHui Xie 回复: "Unfortunately you cannot customize the output filename through any YAML options"
我建议:"i guess the only option if so would be to hope for a future version of bookdown to allow for some extra options such as bookdown::slides for instance?"
并添加了 "I tried to pass "-o", "FILE.pdf" and variations to pandoc, but that did not seem to work"
抛出这个也不起作用:pandoc_args: [ "--output", "slides.pdf" ]
但我认为没有人再注意到这个问题,因此,我将其作为一个实际问题抛出,希望能找到解决方案!提前谢谢了。托马斯

有兴趣回答的朋友,我直接在(GitHub)上提问,包作者谢一辉亲切回复:

The only way at the moment is to render (bookdown::render_book()) to the default output filename, rename it (file.rename()), then render the next output format, and also rename the output file to your desired filename. This process could be automated via an R script. I don't have time for a more detailed answer. Sorry.