Open jooyoungseo opened 3 years ago
Hi,
In order to better understand your issue, I would like to know more about your usage.
bookdown is usually used with one of its book format. I see you are using render_book()
with xaringan format. What are your trying to do exactly? Why not use rmarkdown::render()
directly?
Thank you.
Thanks for asking, @cderv!
I prefer to manage my multiple Rmd files using bookdown style, especially when I prepare for a long research presentation (about an hour or longer). Because that is easier to organize multiple topics systematically. I hope this could answer why I am trying to use bookdown::render_book()
instead of rmarkdown::render()
.
Having said that, I don't think the issue we are having here is output-specific. In other words, this issue happens with another output formats, such as bookdown::pdf_book
: output_dir specified in _bookdown.yml
is ignored. Please kindly let me know if you could reproduce this issue using the system info that I shared above.
I think you encounter this because you are using render_book()
with other than book formats from bookdown.
I tried to reproduce with bookdown::pdf_bookt()
and it works ok: output_dir
in _bookdown.yml
is not ignored. See reprex below:
dir.create(tmp_dir <- tempfile())
owd <- setwd(tmp_dir)
xfun::download_file("https://github.com/rstudio/bookdown-demo/archive/master.zip")
#> [1] 0
unzip("master.zip")
setwd("bookdown-demo-master/")
# Add config for output_dir
config <- yaml::read_yaml("_bookdown.yml")
config$output_dir <- "docs"
yaml::write_yaml(config, "_bookdown.yml")
# output dir does not exist before rendering
xfun::dir_exists("docs")
#> [1] FALSE
bookdown::render_book("index.Rmd", output_format = "bookdown::pdf_book", quiet = TRUE)
#> [1] "C:/Users/chris/AppData/Local/Temp/Rtmp6XuL9D/file55b07326360e/bookdown-demo-master/docs/bookdown-demo.pdf"
# it does after
xfun::dir_exists("docs")
#> [1] TRUE
dir("docs")
#> [1] "bookdown-demo.pdf" "bookdown-demo.tex"
# clean
setwd(owd)
unlink(tmp_dir, recursive = TRUE)
It does not work with xaringan because I don't think render_book()
works the way you expect. output_dir
config in _bookdown.yml
is only used by bookdown format directly. For example, bookdown::pdf_book()
contains a line of code that will move the output to the directory specify in bookdown config. xaringan is not aware of _bookdown.yml
obviously.
Personally, I was not aware of such usage of bookdown as I don't think this is currently supported. render_book()
is aimed mainly to be used to render book format project from bookdown. I don't think we are currently supporting and testing the workflow you described where it could be used with other format. It is rather currently a hack and then every features of bookdown won't work for your usage (like output_dir in _bookdown.yml), also it could break in the future as not tested and supported.
So you're issue is : Currently, output_dir specified in _bookdown.yml is ignored for other formats than the one in bookdown. IMO, it is more a feature request, something maybe more specific to rmarkdown.
As I am curious, can you tell me more about what is bookdown style for xaringan project ?
I am thinking your usage of render_book()
may hide a need for a more generic approach in rmarkdown.
Thanks very much for your thorough testing, @cderv, and happy new year!
output_dir
metadata in _bookdown.yml
is only valid for bookdown
output_format.pagedown::book_crc
could be a good example that absolutely needs bookdown-style file management.xaringan::moon_reader
) is to split one Rmd file into multiple files according to their category, such as "intro.Rmd", "body.Rmd", "conclusion.Rmd", etc., and knit them all together as a whole via bookdown::render_book()
. My understanding of rmarkdown::render()
is for knitting a single file. (Please kindly correct me if I am wrong).
output_dir: "docs"
specified in_bookdown.yml
is ignored inbookdown::render_book()
; instead, the output is created in current working directory.Please take a look at the following reprex and result.
Reprex
_bookdown.yml
_output.yml
index.Rmd
Hello world!