rstudio / bookdown

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

output_dir specified in _bookdown.yml is ignored #1052

Open jooyoungseo opened 3 years ago

jooyoungseo commented 3 years ago

output_dir: "docs" specified in _bookdown.yml is ignored in bookdown::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_dir: "docs"
book_filename: "test"

_output.yml

xaringan::moon_reader:
  lib_dir: libs
  nature:
    highlightStyle: github
    highlightLines: true
    countIncrementalSlides: false

index.Rmd

---
title: "Presentation Ninja"
subtitle: "⚔<br/>with xaringan"
author: "Yihui Xie"
institute: "RStudio, PBC"
date: "2016/12/12 (updated: `r Sys.Date()`)"
---

```{r setup, include=FALSE}
options(htmltools.dir.version = FALSE)

Hello world!



## Rendering Result and Session Info

        setwd("C:/dev/issue")
        bookdown::render_book()
    #> Rendering book in directory '.'
    #> processing file: test.Rmd
    #> output file: test.knit.md
    #> "C:/PROGRA~3/CHOCOL~1/bin/pandoc" +RTS -K512m -RTS test.utf8.md --to html4 --from markdown+autolink_bare_uris+tex_math_single_backslash --output test.html --lua-filter "C:\PROGRA~1\R\R-40~1.3\library\RMARKD~1\RMARKD~1\lua\PAGEBR~1.LUA" --lua-filter "C:\PROGRA~1\R\R-40~1.3\library\RMARKD~1\RMARKD~1\lua\LATEX-~1.LUA" -V "mathjax-url=https://mathjax.rstudio.com/latest/MathJax.js?config=TeX-MML-AM_CHTML" -V "title-slide-class=center, middle, inverse, title-slide" --standalone --section-divs --template "C:\PROGRA~1\R\R-40~1.3\library\xaringan\RMARKD~1\TEMPLA~1\xaringan\RESOUR~1\DEFAUL~1.HTM" --no-highlight --include-in-header "C:\Users\sjysk\AppData\Local\Temp\RtmpU7B1wE\rmarkdown-str2d5c5d272814.html" --include-before-body "C:\Users\sjysk\AppData\Local\Temp\RtmpU7B1wE\xaringan2d5c690256c8.md" --include-after-body "C:\Users\sjysk\AppData\Local\Temp\RtmpU7B1wE\xaringan2d5c150b150a.js" --variable title-slide=true --variable math=true
    #> 
    #> Output created: test.html
    #> [1] "C:/dev/issue/test.html"

    xfun::session_info("bookdown")
    #> R version 4.0.3 (2020-10-10)
    #> Platform: x86_64-w64-mingw32/x64 (64-bit)
    #> Running under: Windows 10 x64 (build 19042)
    #> 
    #> Locale:
    #>   LC_COLLATE=English_United States.1252 
    #>   LC_CTYPE=English_United States.1252   
    #>   LC_MONETARY=English_United States.1252
    #>   LC_NUMERIC=C                          
    #>   LC_TIME=English_United States.1252    
    #> system code page: 65001
    #> 
    #> Package version:
    #>   base64enc_0.1.3      bookdown_0.21.6      digest_0.6.27       
    #>   evaluate_0.14        glue_1.4.2           graphics_4.0.3      
    #>   grDevices_4.0.3      highr_0.8            htmltools_0.5.0.9003
    #>   jsonlite_1.7.2       knitr_1.30.4         magrittr_2.0.1      
    #>   markdown_1.1         methods_4.0.3        mime_0.9            
    #>   rlang_0.4.9          rmarkdown_2.6.4      stats_4.0.3         
    #>   stringi_1.5.3        stringr_1.4.0        tinytex_0.28.2      
    #>   tools_4.0.3          utils_4.0.3          xfun_0.19.5         
    #>   yaml_2.2.1

<sup>Created on 2020-12-27 by the [reprex package](https://reprex.tidyverse.org) (v0.3.0.9001)</sup>

<details style="margin-bottom:10px;">
<summary>
Session info
</summary>

    sessioninfo::session_info()
    #> - Session info ---------------------------------------------------------------
    #>  setting  value                       
    #>  version  R version 4.0.3 (2020-10-10)
    #>  os       Windows 10 x64              
    #>  system   x86_64, mingw32             
    #>  ui       RTerm                       
    #>  language (EN)                        
    #>  collate  English_United States.1252  
    #>  ctype    English_United States.1252  
    #>  tz       America/New_York            
    #>  date     2020-12-27                  
    #> 
    #> - Packages -------------------------------------------------------------------
    #>  package     * version    date       lib source                            
    #>  assertthat    0.2.1      2019-03-21 [1] CRAN (R 4.0.3)                    
    #>  backports     1.2.1      2020-12-09 [1] CRAN (R 4.0.3)                    
    #>  bookdown      0.21.6     2020-12-16 [1] Github (rstudio/bookdown@92c59d3) 
    #>  cli           2.2.0      2020-11-20 [1] CRAN (R 4.0.3)                    
    #>  crayon        1.3.4      2017-09-16 [1] CRAN (R 4.0.3)                    
    #>  digest        0.6.27     2020-10-24 [1] CRAN (R 4.0.3)                    
    #>  ellipsis      0.3.1      2020-05-15 [1] CRAN (R 4.0.3)                    
    #>  evaluate      0.14       2019-05-28 [1] CRAN (R 4.0.3)                    
    #>  fansi         0.4.1      2020-01-08 [1] CRAN (R 4.0.3)                    
    #>  fs            1.5.0      2020-07-31 [1] CRAN (R 4.0.3)                    
    #>  glue          1.4.2      2020-08-27 [1] CRAN (R 4.0.3)                    
    #>  highr         0.8        2019-03-20 [1] CRAN (R 4.0.3)                    
    #>  htmltools     0.5.0.9003 2020-12-05 [1] Github (rstudio/htmltools@d18bd8e)
    #>  knitr         1.30.4     2020-12-14 [1] Github (yihui/knitr@f8f90ba)      
    #>  lifecycle     0.2.0      2020-03-06 [1] CRAN (R 4.0.3)                    
    #>  magrittr      2.0.1      2020-11-17 [1] CRAN (R 4.0.3)                    
    #>  pillar        1.4.7      2020-11-20 [1] CRAN (R 4.0.3)                    
    #>  pkgconfig     2.0.3      2019-09-22 [1] CRAN (R 4.0.3)                    
    #>  purrr         0.3.4      2020-04-17 [1] CRAN (R 4.0.3)                    
    #>  reprex        0.3.0.9001 2020-10-25 [1] Github (tidyverse/reprex@d3fc4b8) 
    #>  rlang         0.4.9      2020-11-26 [1] CRAN (R 4.0.3)                    
    #>  rmarkdown     2.6.4      2020-12-23 [1] Github (rstudio/rmarkdown@da9791a)
    #>  rstudioapi    0.13       2020-11-12 [1] CRAN (R 4.0.3)                    
    #>  sessioninfo   1.1.1      2018-11-05 [1] CRAN (R 4.0.3)                    
    #>  stringi       1.5.3      2020-09-09 [1] CRAN (R 4.0.3)                    
    #>  stringr       1.4.0      2019-02-10 [1] CRAN (R 4.0.3)                    
    #>  styler        1.3.2      2020-02-23 [1] CRAN (R 4.0.3)                    
    #>  tibble        3.0.4      2020-10-12 [1] CRAN (R 4.0.3)                    
    #>  vctrs         0.3.6      2020-12-17 [1] CRAN (R 4.0.3)                    
    #>  withr         2.3.0      2020-09-22 [1] CRAN (R 4.0.3)                    
    #>  xaringan      0.19.1     2020-12-23 [1] Github (yihui/xaringan@e7d44c8)   
    #>  xfun          0.19.5     2020-12-14 [1] Github (yihui/xfun@95e1911)       
    #>  yaml          2.2.1      2020-02-01 [1] CRAN (R 4.0.3)                    
    #> 
    #> [1] C:/Program Files/R/R-4.0.3/library

</details>

<!--
Please keep the below portion in your issue. Your issue will be closed if any of the boxes is not checked (i.e., replace `[ ]` by `[x]`). In certain (rare) cases, you may be exempted if you give a brief explanation (e.g., you are only making a suggestion for improvement). Thanks!
-->

---

By filing an issue to this repo, I promise that

- [x] I have fully read the issue guide at https://yihui.org/issue/.
- [x] I have provided the necessary information about my issue.
    - If I'm asking a question, I have already asked it on Stack Overflow or RStudio Community, waited for at least 24 hours, and included a link to my question there.
    - If I'm filing a bug report, I have included a minimal, self-contained, and reproducible example, and have also included `xfun::session_info('bookdown')`. I have upgraded all my packages to their latest versions (e.g., R, RStudio, and R packages), and also tried the development version: `remotes::install_github('rstudio/bookdown')`.
    - If I have posted the same issue elsewhere, I have also mentioned it in this issue.
- [x] I have learned the Github Markdown syntax, and formatted my issue correctly.

- [x] I understand that my issue may be closed if I don't fulfill my promises.
cderv commented 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.

jooyoungseo commented 3 years ago

Thanks for asking, @cderv!

  1. 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().

  2. 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.

cderv commented 3 years ago

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.

jooyoungseo commented 3 years ago

Thanks very much for your thorough testing, @cderv, and happy new year!

  1. Yes, it seems like output_dir metadata in _bookdown.yml is only valid for bookdown output_format.
  2. Personally, I think this should be supporting other formats. pagedown::book_crc could be a good example that absolutely needs bookdown-style file management.
  3. My usage of bookdown-style file management (not just limited to 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).
  4. As an example, I have been managing my CV in bookdown style, which is very convenient.