bookdown package: Why can't I build a book which I could earlier, getting an error message related to split_by option?
Asked Answered
M

3

7

The R project and related files are available here.

I built a gitbook with bookdown package last December, which you may find in https://bookdown.org/ritsu_kitagawa/_book6/.

When I first built it, there was no error related to the split_by option. But now I get an error message saying

Error in split_chapters(output, gitbook_page, number_sections, split_by,  : 
  Automatically generated filenames contain duplicated ones: -, -, -, -, -, -, -, -, -
Calls: <Anonymous> ... <Anonymous> -> <Anonymous> -> split_chapters -> <Anonymous>

when I tried to build the same book.

My YAML is the following.

--- 
title: "『Rによる原因を推論する』"
author: "北川 梨津,原 健人"
date: "`r Sys.time()`"
site: bookdown::bookdown_site
output: bookdown::gitbook
documentclass: book
bibliography: [book.bib, packages.bib]
biblio-style: apalike
link-citations: yes
github-repo: rstudio/bookdown-demo
description: "久米ゼミのプレゼミのための教材です."
cover-image: "gennin.png"
favicon: "gennin.png"
apple-touch-icon: "gennin.png"
---

The book is written in Japanese. I know I can force it to be built if I set the split_by option to none. I am wondering why I cannot build a file which I could.

Can anyone tell me why this is occurring? Were there any updates or something?

Thank you.


Here is a minimal working example. I cannot build this one, either. I got the same error message:

Error in split_chapters(output, gitbook_page, number_sections, split_by,  : 
  Automatically generated filenames contain duplicated ones: -
Calls: <Anonymous> ... <Anonymous> -> <Anonymous> -> split_chapters -> <Anonymous>
Execution halted

Exited with status 1.

Below is my session info:

R version 3.6.2 (2019-12-12)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Mojave 10.14.6

Locale: en_US.UTF-8 / en_US.UTF-8 / en_US.UTF-8 / C / en_US.UTF-8 / en_US.UTF-8

Package version:
  base64enc_0.1.3 bookdown_0.17   compiler_3.6.2  digest_0.6.24   evaluate_0.14   glue_1.3.1     
  graphics_3.6.2  grDevices_3.6.2 highr_0.8       htmltools_0.4.0 jsonlite_1.6.1  knitr_1.28     
  magrittr_1.5    markdown_1.1    methods_3.6.2   mime_0.9        Rcpp_1.0.3      rlang_0.4.4    
  rmarkdown_2.1   stats_3.6.2     stringi_1.4.5   stringr_1.4.0   tinytex_0.19    tools_3.6.2    
  utils_3.6.2     xfun_0.12       yaml_2.2.1 

If I include some alphabets in chapter names, it can be successfully built.

Monoclinous answered 1/2, 2020 at 5:41 Comment(0)
C
2

You may not have seen it anymore, but I've gone through the same trouble myself and I think I found a solution, so I leave here my answer.

In my case, I had several chapters that I didn't want to be numbered, and when I was trying to create html files from the rmd files, the names of the html files of those chapters would all be "-.html." So, as the error message says, the "automatically generated filenames contain duplicated ones."

The same thing also happens when the title of chapters or sections (in case you specified "split_by: section" in the YAML part) are Japanese, and all those file names will be "-.html." I think that's probably the reason in your case.

In the past version of bookdown, each file was named differently in that case with serialized numbers like "-01.html," "-02.html," and the like. Somehow, however, it seems to have changed in the current version.

So, the solution to this is to explicitly add different tags for each chapter (or section) title, such as:

#はじめに {#intro}

If you don't want to number the chapter title, put a minus sign in front of the tag, such as:

#はじめに {-#intro}

In my case, this solved the problem.

In such a case, it should work if I used split_by: section+number option in the YAML section, but that didn't work.

Contemplative answered 5/5, 2020 at 14:33 Comment(0)
M
2

Seiji's answer was to the point. I would like to explain more deeply why the problem arose and how the solutions worked.

Yihui (the author of Bookdown) mentioned this issued at the end of this page in the official documentation of Bookdown:

There is one caveat when you write in a language that uses multibyte characters, such as Chinese, Japanese, and Korean (CJK): Pandoc cannot generate identifiers from section headings that are pure CJK characters, so you will not be able to cross-reference sections (they do not have labels), unless you manually assign identifiers to them by appending {#identifier} to the section heading, where identifier is an identifier of your choice.

If you don't specify the split-by option within output.yml, Bookdown's default setting will be split-by: "chapter. Let's say you are using English only, and you have three chapters: # Chapter 1, # Chapter 2 and # Chapter 3. After you build and publish the book, the URL of # Chapter 1 will be https://www.thedomainofyourproject.com/chapter-1. The other two chapters will have similar URLs.

Now, let's back to your working example. The titles of the three chapters (including that of index.Rmd) are "要求", "はじめに", and "先行研究". When you try to build the book, you'll find the Error message of "Automatically generated filenames contain duplicated ones" because, as Yihui pointed out, "Pandoc cannot generate identifiers from section headings that are pure CJK characters". That is to say, even though "要求", "はじめに" and "先行研究" are not the same, Pandoc thinks they are.

To solve the problem, as Seiji mentioned, simply assign different tags to each title: "# 要求{#require}", "# はじめに{#first}", "# 先行研究{#lit}".

If you specified split-by: "section, you'll need to assign tags to subtitles as well. For example, if under "# 先行研究", you have three subtitles: "中国の研究", "日本の研究", and "アメリカの研究", you'll need to give them different tags: "中国の研究{#cn}", "日本の研究{#jp}", and "アメリカの研究{#us}".

You mentioned that

If I include some alphabets in chapter names, it can be successfully built.

This is because Pandoc can ignore the CJK characters and generate identifiers based on the alphabets you included. Be aware, however, if the alphabets you included are the same, the building will fail. For example, "litChina 中国の研究", "litJapan 日本の研究", and "litUSA アメリカの研究" will work, but "lit 中国の研究", "lit 日本の研究", and "lit アメリカの研究" won't.

Mucosa answered 13/1, 2021 at 17:24 Comment(0)
T
0

Both Hongtao Hao and Seiji have mentioned one correct solution. That is, add an identifier (consisting of ASCII characters) after the section header.

I have also fixed the original problem in the dev version of bookdown. You can install and test the dev version via

remotes::install_github('rstudio/bookdown')
Trochilus answered 12/8, 2021 at 21:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.