Open piiskop opened 3 months ago
Thanks for the report - we are missing some details and information, so I will answer by guessing some of it. Please to share real information I am mistaken
Only also renaming the first-level caption inside the file allows compiling without an error.
Do you mean the h1 title like
# mehaanika
What format are you using ? bs4_book()
I am guessing as path_to_connection()
is from xml2.
If you have the change could your share the traceback of the error ? traceback()
or rlang::trace_back()
? We will know which part of bookdown is causing this. See about traceback at https://adv-r.hadley.nz/debugging.html#traceback
bs4_book
will split the file by chapters meaning it will use the h1 header name (or id more explicitly) to create the HTML files, and if your book filename is the same, there may be a conflict there. The fact that source file is a subfolder is not involved here because this is handling the HTML file results only.
We need to reproduce to be able to fix this. For now, you need to rename the first header or set a custom index
# mehaanika {#mehaanika-1}
try this above ☝️
So I can reproduce, and this is indeed related to book_filename
which will be used for the intermediate merged Rmd file and then for the name of the HTML file to be split.
From our doc : https://bookdown.org/yihui/bookdown/configuration.html
book_filename: the filename of the main Rmd file, i.e., the Rmd file that is merged from all chapters; by default, it is named _main.Rmd.
Is there any reason to configure this and change the default ? Is this for the download feature ?
You could use book_filename: _mehaanika
and it would solve the issue BTW.
I'll look more into that, but I think we'll add an error / warning or just rename the intermediate file at least temporarily.
Some more details, as it happens there:
https://github.com/rstudio/bookdown/blob/f614e894c04f39704ec231b3b767b23290635627/R/html.R#L416-L447
One of the nms
will be mehaanika.html
- name of chapter inside rmd/mehaanika.Rmd
The merged file will be mehaanika.Rmd
because of book filename, which leads to mehaanika.html
as main book intermediate HTML to be split by split_chapters()
.
And so there will be an overwrite. The initial output file is no more there for bs4_chapters_tweak()
to work on.
This is happening because all the files are written into the main root project behavior being moved to output_dir
Definitely an issue to fix.
@yihui if you have a preference over the behavior that should happen, let me know.
Another really easy solution would be to always preprend by _
the book_filename
provided. This could also create conflict for a chapter with same name, but it seems very unlikely to have a chapter name starting with _
or having an id starting with _
to create HTML files.
I think we should throw an error in this case, asking users to change either book_filename
or the section ID that happens to be identical to book_filename
.
Another really easy solution would be to always preprend by
_
thebook_filename
provided. This could also create conflict for a chapter with same name, but it seems very unlikely to have a chapter name starting with_
or having an id starting with_
to create HTML files.
Yes, I think that's a good idea, too.
The content of my _bookdown.yml:
The error message:
If I exclude the file mehaanika.Rmd from the list of the files to be compiled then compiling finishes without an error. Even if I rename the file to something else and change the name in the list as well the same old error message reappears.
Only also renaming the first-level caption inside the file allows compiling without an error.
xfun::session_info('bookdown')