paleolimbot / rbbt

R Interface to the Better BiBTex Zotero Connector
142 stars 25 forks source link

bbt_write_bib() throws error in bookdown YAML #21

Closed mccarthy-m-g closed 2 years ago

mccarthy-m-g commented 3 years ago

I tried to use the following from your README in the YAML of a bookdown book using the “Knit and Merge” (K-M) method, but it throws an error when building the book.

---
bibliography: "`r rbbt::bbt_write_bib('biblio.json', overwrite = TRUE)`"
---

Here's the error:

Error reading bibliography ./biblio.json Error in $: not enough input
Error running filter /Applications/RStudio.app/Contents/MacOS/pandoc/pandoc-citeproc:
Filter returned error status 1
Error: pandoc document conversion failed with error 83
Execution halted

Exited with status 1.

Additionally, when I inspect the biblio.json file it's empty despite having in-text citations.

However, the syntax above works fine when using bookdown's "Merge and Knit" method. I'm not sure if you can create a YAML-only workaround for the error (likely not since K-M knits every chapter in a new session), so a disclaimer in your README and function documentation to only use this YAML syntax with the "Merge and Knit" method might be helpful.

paleolimbot commented 3 years ago

My guess is that it's only finding the citations in index.Rmd in the K-M method (and it's unlikely you have any). What you really need is to find the citations in all of your files...something like

unique(unlist(lapply(list.files(".", ".Rmd$"), bbt_detect_citations))))

I don't know if it's possible to specifically detect "bookdown", but I could probably add the ability of bbt_detect_citations() to handle a vector of files.

paleolimbot commented 2 years ago

Fixed in https://github.com/paleolimbot/rbbt/commit/5df97f714c32471858317557335288f57a9dfb7c !