Search code examples
docxbookdown

Specify files with bookdown's `rmd_files` for word document output? I get "Error in basename(files)"


Following @yihui's bookdown usage 1.3, I'm attempting to select specific files to render in each output format by adding a rmd_files argument to _bookdown.yml in @yihui's Minimal Book Example.

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

To _output.yml, I add

bookdown::word_document2:
  toc: true

Everything else in the Minimal Book Example is unchanged.

rmarkdown::render_site(encoding = 'UTF-8') renders html, latex, and epub documents, but word output fails with Error in basename(files) : a character vector argument expected Calls: <Anonymous> ... FUN -> render_book -> source_files -> grep -> basename

The word document renders if I remove the rmd_files argument.

I tried omitting index.Rmd from the files list, deleting all content from both Rmd files, and using word_document instead of word_document2.

Same results with CRAN bookdown_0.20 and development version 0.20.3 on two different machines (both macs).

This error may be similar to this post, but it did not provide a minimal example and appears to have been fixed in the latest bookdown release.

Bookdown is amazing, and I could be missing something simple here. Thanks so much for any help!


Solution

  • The name of the output format is docx instead of word.

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

    The name is for Pandoc, and all names are listed here: https://pandoc.org/MANUAL.html#option--to