rstudio / bookdown

Authoring Books and Technical Documents with R Markdown
https://pkgs.rstudio.com/bookdown/
GNU General Public License v3.0
3.76k stars 1.27k forks source link

output_dir in _bookdown.yml is ignored for bookdown::html_document2 #1469

Closed florisvdh closed 4 months ago

florisvdh commented 4 months ago

This issue extends on issue #1052. It seems that output_dir works for bookdown::pdf_book. However it does not for bookdown::html_document2 (and maybe others too).

dir.create(tmp_dir <- tempfile())
owd <- setwd(tmp_dir)
xfun::download_file("https://github.com/rstudio/bookdown-demo/archive/main.zip")
#> [1] 0
unzip("main.zip")
setwd("bookdown-demo-main/")
# 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::html_document2", quiet = TRUE)
#> [1] "/tmp/RtmpyCgUja/filecdc073efa451/bookdown-demo-main/bookdown-demo.html"
# output dir exists after rendering
xfun::dir_exists("docs")
#> [1] TRUE
# but its contents are:
dir("docs")
#> [1] "reference-keys.txt"
# rendering took place in working dir:
file.exists("bookdown-demo.html")
#> [1] TRUE
# clean
setwd(owd)
unlink(tmp_dir, recursive = TRUE)

Created on 2024-06-04 with reprex v2.1.0

Session info ``` r sessioninfo::session_info() #> ─ Session info ─────────────────────────────────────────────────────────────── #> setting value #> version R version 4.4.0 (2024-04-24) #> os Linux Mint 21.3 #> system x86_64, linux-gnu #> ui X11 #> language nl_BE:nl #> collate nl_BE.UTF-8 #> ctype nl_BE.UTF-8 #> tz Europe/Brussels #> date 2024-06-04 #> pandoc 3.1.11 @ /usr/lib/rstudio/resources/app/bin/quarto/bin/tools/x86_64/ (via rmarkdown) #> #> ─ Packages ─────────────────────────────────────────────────────────────────── #> package * version date (UTC) lib source #> bookdown 0.39 2024-04-15 [3] RSPM (R 4.3.0) #> bslib 0.7.0 2024-03-29 [3] RSPM (R 4.3.0) #> cachem 1.1.0 2024-05-16 [3] RSPM (R 4.4.0) #> cli 3.6.2 2023-12-11 [3] RSPM (R 4.3.0) #> curl 5.2.1 2024-03-01 [3] RSPM (R 4.3.0) #> digest 0.6.35 2024-03-11 [3] RSPM (R 4.3.0) #> evaluate 0.23 2023-11-01 [3] RSPM (R 4.3.0) #> fastmap 1.2.0 2024-05-15 [3] RSPM (R 4.4.0) #> fs 1.6.4 2024-04-25 [3] RSPM (R 4.3.0) #> glue 1.7.0 2024-01-09 [3] RSPM (R 4.3.0) #> highr 0.11 2024-05-26 [3] RSPM (R 4.4.0) #> htmltools 0.5.8.1 2024-04-04 [3] RSPM (R 4.3.0) #> jquerylib 0.1.4 2021-04-26 [3] RSPM (R 4.3.2) #> jsonlite 1.8.8 2023-12-04 [3] RSPM (R 4.3.0) #> knitr 1.47.2 2024-06-04 [1] Github (yihui/knitr@f50b75b) #> lifecycle 1.0.4 2023-11-07 [3] RSPM (R 4.3.0) #> magrittr 2.0.3 2022-03-30 [3] RSPM (R 4.2.0) #> purrr 1.0.2 2023-08-10 [3] RSPM (R 4.2.0) #> R.cache 0.16.0 2022-07-21 [3] RSPM (R 4.2.0) #> R.methodsS3 1.8.2 2022-06-13 [3] RSPM (R 4.2.0) #> R.oo 1.26.0 2024-01-24 [3] RSPM (R 4.3.0) #> R.utils 2.12.3 2023-11-18 [3] RSPM (R 4.3.0) #> R6 2.5.1 2021-08-19 [3] RSPM (R 4.2.0) #> reprex 2.1.0 2024-01-11 [3] RSPM (R 4.3.0) #> rlang 1.1.3 2024-01-10 [3] RSPM (R 4.3.0) #> rmarkdown 2.27 2024-05-17 [3] RSPM (R 4.4.0) #> rstudioapi 0.16.0 2024-03-24 [3] RSPM (R 4.3.0) #> sass 0.4.9 2024-03-15 [3] RSPM (R 4.3.0) #> sessioninfo 1.2.2 2021-12-06 [3] RSPM (R 4.2.0) #> styler 1.10.3 2024-04-07 [3] RSPM (R 4.3.0) #> vctrs 0.6.5 2023-12-01 [3] RSPM (R 4.3.0) #> withr 3.0.0 2024-01-16 [3] RSPM (R 4.3.2) #> xfun 0.44 2024-05-15 [3] RSPM (R 4.4.0) #> xml2 1.3.6 2023-12-04 [3] RSPM (R 4.3.0) #> yaml 2.3.8 2023-12-11 [3] RSPM (R 4.3.0) #> #> [1] /home/floris/lib/R/library #> [2] /usr/local/lib/R/site-library #> [3] /usr/lib/R/site-library #> [4] /usr/lib/R/library #> #> ────────────────────────────────────────────────────────────────────────────── ```
cderv commented 4 months ago

This is not an extension of #1052, this is a duplicate. Same observation: output_dir configuration in bookdown is for book format. bookdown::html_document2 and any other single document variants are not considered book and do not support this configuration. They also can be rendered using rmarkdown::render() directly.

It would be an enhancement to add this feature, which is what #1052 is about. Not sure about which side effect this could have...

cderv commented 4 months ago

Duplicate of #1052

florisvdh commented 4 months ago

Thanks for clarifying. Indeed, it appears that bookdown::html_book does respect output_dir.

Feel free to close this one.