In answer to your question:
I typed into the Console of RStudio
bookdown::dir_exists("./source-posts")
and got
Error: 'dir_exists' is not an exported object from 'namespace:bookdown'
In answer to your other questions, I understand also your suggestion to add a move after files have been written to _book. The solution shown in OP was what I found and what seemed to be working and therefore I didn't think an extra move was necessary. It is hard to find best practices for this stuff so all I was going on was the ? render_book help and the options indicated to me there.
I had to use output_file because without it when writing to output_dir I could not control the name of the file (render_book ended up writing something like _main.html). That is, upon rendering the file would not be named by the rmd_files from _bookdown.yml which seemed odd to me, so I had to find the output_file work around with paste0.
Essentially what I was trying to figure out was how to find some version of what I understood and was working from
render_site(
input = "./source-body",
output_format = "all",
envir = parent.frame(),
quiet = FALSE,
encoding = "UTF-8"
)
The goal and intention of the script in the OP was (according to my perhaps inaccurate mental model)
- take the the rmd_file in _bookdown.yml
- which is in input folder
- and render to the output folder
- with name given by output_file
- according to the options in _output.yml.
Am I reading the render_book incorrectly or thinking wrong in my mental model?
The biggest difficulty I have had with RMarkdown and Bookdown so far is having rendered files writing with the name I wish and to the location I want which is why I was so happy to find the help file for render_book. For example, from the help file for render_book
output_dir The output directory. If NULL , a field named output_dir in the configuration file ‘_bookdown.yml’ will be used (possibly not specified, either, in which case a directory name ‘_book’ will be used).
I was never able to get output_dir in _bookdown.yml to write to that location so I had to make output_dir in render_book not NULL which meant to me it should write where specified.
BTW, using the Knit button (which I have stopped using mostly in favor of the R scripts) writes files to the _book location mentioned in the help file.
BTW, I have renderscripts for other bookdown formats (like e-pub) that have been working
render_book(
input = "./source-posts",
output_format = "bookdown::epub_book",
output_dir = "../output/posts",
output_file = paste0(file_to_render,"-ebook",".epub"),
envir = parent.frame(),
output_yaml= "_output.yml",
config_file= "_bookdown.yml",
quiet = FALSE,
encoding = "UTF-8"
)
so I really hope we can get this worked out. The tools you all are giving us are fantastic, being able to write LaTeX and export to html, pdf, pub is exactly what I need.
Best,
Jason