【问题标题】:Specify files with bookdown's `rmd_files` for word document output? I get "Error in basename(files)"使用 bookdown 的 rmd_files 指定文件用于 word 文档输出?我收到“基本名称(文件)错误”
【发布时间】:2020-08-31 21:45:44
【问题描述】:

按照@yihui 的bookdown usage 1.3,我正在尝试通过在@yihui 的Minimal Book Example 中向_bookdown.yml 添加rmd_files 参数来选择要以每种输出格式呈现的特定文件。

rmd_files:
  html: ["index.Rmd", "01-intro.Rmd"]
  latex: ["index.Rmd", "01-intro.Rmd"]
  epub: ["index.Rmd", "01-intro.Rmd"]
  word: ["index.Rmd", "01-intro.Rmd"]

到_output.yml,我添加

bookdown::word_document2:
  toc: true

Minimal Book Example 中的其他所有内容均未更改。

rmarkdown::render_site(encoding = 'UTF-8') 渲染 html、latex 和 epub 文档,但 word 输出失败并显示 Error in basename(files) : a character vector argument expected Calls: <Anonymous> ... FUN -> render_book -> source_files -> grep -> basename

如果我删除 rmd_files 参数,word 文档就会呈现。

我尝试从文件列表中省略 index.Rmd,从两个 Rmd 文件中删除所有内容,并使用 word_document 而不是 word_document2

CRAN bookdown_0.20 和开发版本 0.20.3 在两台不同的机器(都是 mac)上的结果相同。

此错误可能类似于this post,但它没有提供最小示例,并且似乎已在最新的 bookdown 版本中得到修复。

Bookdown 太棒了,我可能在这里遗漏了一些简单的东西。非常感谢您的帮助!

【问题讨论】:

    标签: docx bookdown


    【解决方案1】:

    输出格式的名称是docx,而不是word

    rmd_files:
      docx: ["index.Rmd", "01-intro.Rmd"]
    

    名称是 Pandoc 的,所有名称都列在这里:https://pandoc.org/MANUAL.html#option--to

    【讨论】:

    • 谢谢!这在 1.3 中可能很有用,因为其他选项与给定的输出选项具有相同的名称——“LaTeX、HTML、EPUB 和 Word”。事后看来很明显,但看起来其他人已经被这个小不匹配弄糊涂了(例如barelysignificant.com/post/old/blogdown)。再次感谢!
    • @DevinJudge-Lord 因为这太混乱了,我只是让word 自动工作:github.com/rstudio/bookdown/commit/… 谢谢!
    猜你喜欢
    • 2019-10-31
    • 1970-01-01
    • 2021-10-08
    • 2018-10-16
    • 2014-03-31
    • 2019-08-08
    • 2011-06-29
    • 2023-03-03
    • 2012-03-04
    相关资源
    最近更新 更多