Bookdown; how to pass the name of the _output.yml to use in render_book

Dear bookdown users,

I am using several Rmd files to produce different books based on my requirements. I am using render_book command to pass the _bookdown.yml file I want to use. I can define and reuse my compositions. That's working fine.

My question is: how can I do the same for _output.yml file?

I would like to be able to select different configs for using different template.tex or preamble.tex. I search the doc and the code but found nothing going in that direction.

Am I missing something here? Should I use file rename code before calling render_book?

Thanks in advance for your help,


1 Like

render_book has a output_format argument. You can pass here any output_format object that you would have a put into _output.yml, like bookdown::gitbook() or bookdown::pdf_book() with any argument you need as you would define them in output.yml.

Note also that _output.yaml is a rmarkdown feature not a bookdown one like _bookdown.yml. Output format and options are read from yaml front matter, from _site.yml and _output.yml and merge all together. Currently there is no way to change the name of those file read by any configuration. You would need to open a feature request, or use a renaming mechanism just before building to activate the one you want to use.

Hope it helps.

1 Like

Thank you for your explanation. It does help to understand the mechanism behind the render option. I will use so file renaming code for the time being.

Where are request features open? As an issue on the GitHub?


1 Like

Yes as issue in Github.

For this one, the use case is bookdown but the feature is in Rmarkdown where _output.yml is from. I would suggest there.

The impact can be non negligeable for this and output can already be pass to render_book as object in argument of the function. Maybe a function to help transform an output format stored in yaml to an object would be enough in your case

render_book("index.Rmd", output_format = as_output_format("my_output.yml"))

This is a different approach but could be easier to implement... We will see what they say.

Doing what you do (renaming to activate), is also a good way. You can use a Makefile or other workflow tool (like drake R package) to help automate this. Or just a wrapper aroung render_book :thinking:

render_book_with_yaml_output <- function(input, yaml_file, ...) {
  if (saved <- file.exists("_output.yml")) {
    file.copy('_output.yml', '')
  file.copy(yaml_file, "_output.yml")
    if (saved) {
      file.copy('', '_output.yml')
  bookdown::render_book(input = input, ...)

Somethink like that...

1 Like

Thank you again for the explanation.

I will go for the yaml to list transformation. It is cleaner than renaming file.

I will post the feature request on github to see if there is more feedback.



Thanks ! For reference this is here

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.