bookdown: debugging / fixing incomprehensible error

[Env: R 3.6.3, R Studio 1.2.5042, bookdown 0.21]

I have the beginning of a bookdown project, with chapter stubs that used to compile OK before. Now I am getting a completely incomprehensible error in the pandoc step.

How can I track down where/why this is occurring?

The error, Error in x[i] <- sprintf("<a href=\"%s#%s\"", filenames[which.max(lines[lines <= : ... makes no sense to me.

output file: TOGS.knit.md

"C:/Program Files/RStudio/bin/pandoc/pandoc" +RTS -K512m -RTS TOGS.utf8.md --to html4 --from markdown+autolink_bare_uris+tex_math_single_backslash --output TOGS.html --lua-filter "C:\R\R-3.6.3\library\bookdown\rmarkdown\lua\custom-environment.lua" --lua-filter "C:\R\R-3.6.3\library\rmarkdown\rmarkdown\lua\pagebreak.lua" --lua-filter "C:\R\R-3.6.3\library\rmarkdown\rmarkdown\lua\latex-div.lua" --metadata-file "C:\Users\friendly\AppData\Local\Temp\Rtmp2PCoKw\file22e442b5735f" --email-obfuscation none --wrap preserve --standalone --section-divs --table-of-contents --toc-depth 3 --template "C:\R\R-3.6.3\library\bookdown\templates\gitbook.html" --highlight-style pygments --number-sections --css css/style.css --css css/chapters.css --include-in-header "C:\Users\friendly\AppData\Local\Temp\Rtmp2PCoKw\rmarkdown-str22e437505210.html" --mathjax --filter "C:/Program Files/RStudio/bin/pandoc/pandoc-citeproc.exe" 
Error in x[i] <- sprintf("<a href=\"%s#%s\"", filenames[which.max(lines[lines <=  : 
  replacement has length zero
Calls: local ... <Anonymous> -> split_chapters -> restore_links -> lapply -> FUN
Execution halted
Error in gzfile(file, "rb") : cannot open the connection
Calls: <Anonymous> ... unlist -> lapply -> FUN -> <Anonymous> -> readRDS -> gzfile
In addition: Warning message:
In gzfile(file, "rb") :
  cannot open compressed file 'C:\Users\friendly\AppData\Local\Temp\Rtmp251xjv\file2d9054dd5799.rds', probable reason 'No such file or directory'
Execution halted

Exited with status 1.

Did it happen after an update of bookdown ?

This error happen in the internal restore_links() function. Without the code, or generated html to debug it will be difficult for me.
Is the code available or would you be willing to share some file with me (privatly) ?

I am just unclear about this error:

Error in gzfile(file, "rb") : cannot open the connection
Calls: <Anonymous> ... unlist -> lapply -> FUN -> <Anonymous> -> readRDS -> gzfile
In addition: Warning message:
In gzfile(file, "rb") :
  cannot open compressed file 'C:\Users\friendly\AppData\Local\Temp\Rtmp251xjv\file2d9054dd5799.rds', probable reason 'No such file or directory'
Execution halted

Not sure it comes for bookdown;

Difficult to look from afar.

If you are willing to debug you can step through restore_links but that won't be the clearer path:
For that you can run this to enter the debugger

debugonce("bookdown:::restore_links")

Something is not correct in the post processing for your project.

First of all can you try with previous version ?

remotes::install_version("bookdown", "0.20")

to see if you have the issue.

Helping as I can...

Thanks for this reply @cderv

I tried reverting bookdown to v 0.20 as per your suggestion. Now, I only get the first error message,

Error in x[i] <- sprintf("<a href=\"%s#%s\"", filenames[which.max(lines[lines <=  : 
  replacement has length zero
Calls: <Anonymous> ... <Anonymous> -> split_chapters -> restore_links -> lapply -> FUN
Execution halted

Exited with status 1.

But, bookdown::restore_links() seems unavailable in the 0.20 version

debugonce("bookdown:::restore_links")
Error in debugonce("bookdown:::restore_links") :
could not find function "bookdown:::restore_links"

If you'll bear with me, I'll post the source on github and send you a link (if I can do this privately).

But, bookdown::restore_links() seems unavailable in the 0.20 version

This is an internal function, so accessible only with ::: like I shown.

There is something odd with the html file produced for your book, and the splitting process to several files does not go well.

I can't really help you more from here appart answering to your question and guiding your debugging.

Sorry for the inconvenience.

Hi Christophe

I am still totally stymied by this. I created a GitHub repo for the files in this bookdown project,

https://github.com/friendly/DataVisHistory-bookdown

As I said, it is just an initial stub, but the error(s) I get prevent me from going further. Any help would be greatly appreciated.

Thanks a lot for this repo.

I think you got the error here because your first header in the book is an header two (##) and not an header one (#).

Is this on purpose ? If so, I need to see how to improve how to handle this case.

Bookdown require header 1 section for each part. This is according to these h1 header that the book is split by default.
You can find some hint about the splitting in here: https://bookdown.org/yihui/bookdown/html.html

If I tranform to

# Cover image {-}

it seems to render ok.

Anyway, the error message is definitely cryptic and this should be improved IMO.

2 Likes

It’s odd that this is the error, as I distinctly remember making this same mistake and getting a more helpful error message.

Perhaps there is something different about how h2 and h3 or h4 (which I would have been using) are handled in this case. I wouldn’t be surprised, given how the splitting works, if the latter produce better errors.

Regardless, it’s kind of irritating that the front matter must start with an h1, since often you don’t want that to be the first thing.

You mean you want to include something above the chapter header ?

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.