Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gitbook split_by : "section+number" works no more #1369

Closed
WdeNooy opened this issue Aug 17, 2022 · 10 comments
Closed

gitbook split_by : "section+number" works no more #1369

WdeNooy opened this issue Aug 17, 2022 · 10 comments
Assignees
Labels
bug an unexpected problem or unintended behavior

Comments

@WdeNooy
Copy link

WdeNooy commented Aug 17, 2022

If a multiple-chapter book is built into a gitbook with option split_by : "section+number", no separate HTML files are produced for sections. Warning message(s):

In file.rename(files[i], files2[i]) :
cannot rename file '1.html' to '_book/1.html', reason 'The system cannot find the file specified'

In contrast, the options split_by : "section" and split_by : "chapter+number" work fine.

The problem has arisen between mid July and mid August. I rolled back packages 'bookdown', 'rmarkdown', and 'tinytex' to previous versions (0.25, 2.13, 0.38 respectively), which are versions on another computer that renders a gitbook with option split_by : "section+number" correctly. However, rolling back these packages did not remedy the problem. Apparently, the problem is situated in another package.

A test set can be found in the attached zip file (containing 3 Rmd files): RenderProblems.zip

My session info:

 setting  value
 version  R version 4.2.1 (2022-06-23 ucrt)
 os       Windows 10 x64 (build 19044)
 system   x86_64, mingw32
 ui       RStudio
 language (EN)
 collate  English_United States.utf8
 ctype    English_United States.utf8
 tz       Europe/Berlin
 date     2022-08-17
 rstudio  2022.07.1+554 Spotted Wakerobin (desktop)
 pandoc   2.19 @ C:/Users/wdnooy1/AppData/Local/Pandoc/ (via rmarkdown)

─ Packages ───────────────────────────────────────────────────────────────────
 package     * version date (UTC) lib source
 bookdown      0.25    2022-03-16 [1] CRAN (R 4.2.1)
 cachem        1.0.6   2021-08-19 [1] CRAN (R 4.2.1)
 callr         3.7.1   2022-07-13 [1] CRAN (R 4.2.1)
 cli           3.3.0   2022-04-25 [1] CRAN (R 4.2.1)
 crayon        1.5.1   2022-03-26 [1] CRAN (R 4.2.1)
 devtools      2.4.4   2022-07-20 [1] CRAN (R 4.2.1)
 digest        0.6.29  2021-12-01 [1] CRAN (R 4.2.1)
 ellipsis      0.3.2   2021-04-29 [1] CRAN (R 4.2.1)
 evaluate      0.16    2022-08-09 [1] CRAN (R 4.2.1)
 fastmap       1.1.0   2021-01-25 [1] CRAN (R 4.2.1)
 fs            1.5.2   2021-12-08 [1] CRAN (R 4.2.1)
 glue          1.6.2   2022-02-24 [1] CRAN (R 4.2.1)
 htmltools     0.5.3   2022-07-18 [1] CRAN (R 4.2.1)
 htmlwidgets   1.5.4   2021-09-08 [1] CRAN (R 4.2.1)
 httpuv        1.6.5   2022-01-05 [1] CRAN (R 4.2.1)
 knitr         1.38    2022-03-25 [1] CRAN (R 4.2.1)
 later         1.3.0   2021-08-18 [1] CRAN (R 4.2.1)
 lifecycle     1.0.1   2021-09-24 [1] CRAN (R 4.2.1)
 magrittr      2.0.3   2022-03-30 [1] CRAN (R 4.2.1)
 memoise       2.0.1   2021-11-26 [1] CRAN (R 4.2.1)
 mime          0.12    2021-09-28 [1] CRAN (R 4.2.0)
 miniUI        0.1.1.1 2018-05-18 [1] CRAN (R 4.2.1)
 pkgbuild      1.3.1   2021-12-20 [1] CRAN (R 4.2.1)
 pkgload       1.3.0   2022-06-27 [1] CRAN (R 4.2.1)
 prettyunits   1.1.1   2020-01-24 [1] CRAN (R 4.2.1)
 processx      3.7.0   2022-07-07 [1] CRAN (R 4.2.1)
 profvis       0.3.7   2020-11-02 [1] CRAN (R 4.2.1)
 promises      1.2.0.1 2021-02-11 [1] CRAN (R 4.2.1)
 ps            1.7.1   2022-06-18 [1] CRAN (R 4.2.1)
 purrr         0.3.4   2020-04-17 [1] CRAN (R 4.2.1)
 R6            2.5.1   2021-08-19 [1] CRAN (R 4.2.1)
 Rcpp          1.0.9   2022-07-08 [1] CRAN (R 4.2.1)
 remotes       2.4.2   2021-11-30 [1] CRAN (R 4.2.1)
 rlang         1.0.4   2022-07-12 [1] CRAN (R 4.2.1)
 rmarkdown     2.13    2022-03-10 [1] CRAN (R 4.2.1)
 rstudioapi    0.13    2020-11-12 [1] CRAN (R 4.2.1)
 sessioninfo   1.2.2   2021-12-06 [1] CRAN (R 4.2.1)
 shiny         1.7.2   2022-07-19 [1] CRAN (R 4.2.1)
 stringi       1.7.8   2022-07-11 [1] CRAN (R 4.2.1)
 stringr       1.4.0   2019-02-10 [1] CRAN (R 4.2.1)
 urlchecker    1.0.1   2021-11-30 [1] CRAN (R 4.2.1)
 usethis       2.1.6   2022-05-25 [1] CRAN (R 4.2.1)
 xfun          0.32    2022-08-10 [1] CRAN (R 4.2.1)
 xtable        1.8-4   2019-04-21 [1] CRAN (R 4.2.1)
 yaml          2.3.5   2022-02-21 [1] CRAN (R 4.2.1)

 [1] C:/Users/wdnooy1/AppData/Local/R/win-library/4.2
 [2] C:/Program Files/R/R-4.2.1/library```
@cderv
Copy link
Collaborator

cderv commented Aug 24, 2022

Thanks for the report and for the reproducible example. I believe the issue comes from this line

nms = basename(with_ext(nms, '.html')) # the HTML filenames to be generated

The title extracted that should be used to create the filenames will be like this

> nms
[1] "index"                "1-first-chapter"      "1.1-first-section"   
[4] "1.2-second-section"   "1.3-last-section"     "2-second-chapter"    
[7] "2.1-first-section-1"  "2.2-second-section-1" "2.3-last-section-1"

Using section+number correctly selected level 2 headers. Note the . in the number.
This is what will make xfun::with_ext() wrongly generate the filename

> basename(with_ext(nms, ".html"))
[1] "index.html"            "1-first-chapter.html" 
[3] "1.html"                "1.html"               
[5] "1.html"                "2-second-chapter.html"
[7] "2.html"                "2.html"               
[9] "2.html"  

This is because the name doesn't have another extension and so it replaces anything after the period.

@yihui xfun::with_ext() seems to be used since 5 years in bookdown (74c059c) and I don't see any recent change.

Maybe it is pandoc who have change the numbering with a . in file name. I'll check that.

I think we could just replace the . in the numbering by a -. This would solves this.

Thoughts ?

@cderv cderv added the bug an unexpected problem or unintended behavior label Aug 24, 2022
@cderv
Copy link
Collaborator

cderv commented Aug 24, 2022

Maybe it is pandoc who have change the numbering with a . in file name. I'll check that.

I still get the same result with Pandoc 2.7.3 which seems old enough.

The problem has arisen between mid July and mid August.

I am not quite sure to see what maybe have cause this issue to arise at this timing. Strange.

@WdeNooy
Copy link
Author

WdeNooy commented Aug 24, 2022

Thanks for addressing this problem.

I have been experimenting and I think the problem is in package xfun. The HTML is correctly split by section and number with xfun versions 0.31 and below, but not with xfun version 0.32.

Hope this helps.

- Session info --------------------------------------------------------------------------
 setting  value
 version  R version 4.1.2 (2021-11-01)
 os       Windows 10 x64 (build 19043)
 system   x86_64, mingw32
 ui       RStudio
 language (EN)
 collate  English_United States.1252
 ctype    English_United States.1252
 tz       Europe/Berlin
 date     2022-08-24
 rstudio  2022.07.1+554 Spotted Wakerobin (desktop)
 pandoc   2.18 @ C:/Program Files/RStudio/bin/quarto/bin/tools/ (via rmarkdown)

- Packages ------------------------------------------------------------------------------
 package   * version date (UTC) lib source
 base64enc   0.1-3   2015-07-28 [1] CRAN (R 4.0.3)
 bookdown    0.28    2022-08-09 [1] CRAN (R 4.1.3)
 bslib       0.4.0   2022-07-16 [1] CRAN (R 4.1.3)
 cachem      1.0.6   2021-08-19 [1] CRAN (R 4.1.2)
 digest      0.6.29  2021-12-01 [1] CRAN (R 4.1.2)
 evaluate    0.16    2022-08-09 [1] CRAN (R 4.1.3)
 fastmap     1.1.0   2021-01-25 [1] CRAN (R 4.1.2)
 fs          1.5.2   2021-12-08 [1] CRAN (R 4.1.2)
 glue        1.6.2   2022-02-24 [1] CRAN (R 4.1.3)
 highr       0.9     2021-04-16 [1] CRAN (R 4.1.2)
 htmltools   0.5.3   2022-07-18 [1] CRAN (R 4.1.3)
 jquerylib   0.1.4   2021-04-26 [1] CRAN (R 4.1.2)
 jsonlite    1.8.0   2022-02-22 [1] CRAN (R 4.1.3)
 knitr       1.39    2022-04-26 [1] CRAN (R 4.1.3)
 magrittr    2.0.3   2022-03-30 [1] CRAN (R 4.1.3)
 memoise     2.0.1   2021-11-26 [1] CRAN (R 4.1.2)
 R6          2.5.1   2021-08-19 [1] CRAN (R 4.1.2)
 rappdirs    0.3.3   2021-01-31 [1] CRAN (R 4.1.2)
 rlang       1.0.4   2022-07-12 [1] CRAN (R 4.1.3)
 rmarkdown   2.15    2022-08-16 [1] CRAN (R 4.1.3)
 sass        0.4.2   2022-07-16 [1] CRAN (R 4.1.3)
 stringi     1.7.6   2021-11-29 [1] CRAN (R 4.1.2)
 stringr     1.4.1   2022-08-20 [1] CRAN (R 4.1.3)
 tinytex     0.41    2022-08-16 [1] CRAN (R 4.1.2)
 xfun        0.31    2022-08-24 [1] local
 yaml        2.3.5   2022-02-21 [1] CRAN (R 4.1.2)

@cderv
Copy link
Collaborator

cderv commented Aug 24, 2022

@WdeNooy can you confirm to us the name of the HTML files inside the output folder please ?
When this is working obviously so with xfun 0.31

@yihui
Copy link
Member

yihui commented Aug 24, 2022

I think this is caused by a change in xfun: yihui/xfun@49a9c7e I'll see what I can do.

@cderv
Copy link
Collaborator

cderv commented Aug 24, 2022

I can confirm that xfun 0.31 handles those . correctly :

> nms
[1] "introduction"         "1-first-chapter"     
[3] "1.1-first-section"    "1.2-second-section"  
[5] "1.3-last-section"     "2-second-chapter"    
[7] "2.1-first-section-1"  "2.2-second-section-1"
[9] "2.3-last-section-1" 

> basename(with_ext(nms, ".html"))
[1] "introduction.html"        
[2] "1-first-chapter.html"     
[3] "1.1-first-section.html"   
[4] "1.2-second-section.html"  
[5] "1.3-last-section.html"    
[6] "2-second-chapter.html"    
[7] "2.1-first-section-1.html" 
[8] "2.2-second-section-1.html"
[9] "2.3-last-section-1.html" 

Too bad we have some tests, but not for this situation

assert(
'with_ext() works',
with_ext(NULL, 'a') %==% NULL,
with_ext('a', NULL) %==% 'a',
with_ext('a', 'bcd') %==% 'a.bcd',
with_ext('a.html', '') %==% 'a',
with_ext('a.html', 'tex') %==% 'a.tex',
with_ext('a.html', '.tex') %==% 'a.tex',
with_ext(c('a', 'b', 'c'), 'css') %==% c('a.css', 'b.css', 'c.css'),
with_ext(c('a.html', 'b', 'c.js'), 'css') %==% c('a.css', 'b.css', 'c.css'),
with_ext(c('a.html', 'b', 'c'), '.css') %==% c('a.css', 'b.css', 'c.css'),
with_ext('a', c('css', '.html')) %==% c('a.css', 'a.html'),
with_ext(c('a.doc', 'b.gz', 'c'), c('css', '.tar', '.png')) %==% c('a.css', 'b.tar', 'c.png')
)

That is why we missed before 0.32 release

@WdeNooy
Copy link
Author

WdeNooy commented Aug 24, 2022 via email

@yihui
Copy link
Member

yihui commented Aug 25, 2022

Should be fixed in the dev version of xfun now:

remotes::install_github('yihui/xfun')

Thanks!

@yihui
Copy link
Member

yihui commented Sep 12, 2022

The new version of xfun is on CRAN now. Its Windows binary package may take one or two more days to be available there.

clrpackages pushed a commit to clearlinux-pkgs/R-xfun that referenced this issue Sep 13, 2022
Christophe Dervieux (1):
      Use ubuntu-latest on GHA (#69)

Yihui Xie (4):
      deprecate stringsAsStrings()
      fix rstudio/bookdown#1369: revert 49a9c7ec79879ce26891e6dace662c771efbc5cb and provide another way for users to specify which extra characters are allowed in filename extensions (#68)
      create an empty `recheck` file instead of writing placeholder text into it, because the latter will cause rev_check() to skip all rev deps, e.g., mitchelloharawild/crandalf@91169cd
      CRAN release 0.33
netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this issue Dec 18, 2022
# CHANGES IN xfun VERSION 0.35

- Added a new argument `token` to `protect_math()` to optionally
  include a token around math expressions.

- `base64_uri()` relies less on the **mime** package now. For some
  common file extensions (e.g., `.jpg`/`.png`), this function knows
  their MIME types.

- `stringsAsStrings()` has been removed from this package.

# CHANGES IN xfun VERSION 0.34

- Added a new function `alnum_id()` to generate ID strings from a character vector.

- The function `stringsAsStrings()` has been deprecated.

# CHANGES IN xfun VERSION 0.33

- Reverted the change for #68: the characters `-+!_#` are no longer
  accepted by default in filename extensions, since they are
  relatively rare and caused a breakage in rstudio/bookdown#1369. If
  you wish to allow for these characters, you may use the new `extra`
  argument in `file_ext()` and related functions, e.g.,
  `xfun::file_ext(x, extra = '-+!_#')`.

- The function `stringsAsStrings()` will be deprecated in a future
  release of **xfun**, because the global option `stringsAsFactors =
  FALSE` has become the default in base R since 4.0.0.

# CHANGES IN xfun VERSION 0.32

- Added a function `shrink_images()` to shrink images to a maximum
  width using the **magick** package (thanks, @apreshill,
  rstudio/blogdown#614).

- Added a function `tinify_dir()` as a wrapper of `tinify()` to
  compress images under a directory.

- `file_ext()` supports more file extensions now, such as `.c++`,
  `.FB2K-COMPONENT`, and so on (thanks, @tentacles-from-outer-space,
  #68).

- Fixed the issue that `xfun::base_pkgs()` could hang R (thanks,
  @mmaechler, #66).

- The `...` argument in `dir_create()` was not passed to `dir.create()`.
@github-actions
Copy link

This old thread has been automatically locked. If you think you have found something related to this, please open a new issue by following the issue guide (https://yihui.org/issue/), and link to this old issue if necessary.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 15, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug an unexpected problem or unintended behavior
Projects
Archived in project
Development

No branches or pull requests

3 participants