paleolimbot / rbbt

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

rbbt detecting non-running Zotero #24

Closed dmi3kno closed 2 years ago

dmi3kno commented 3 years ago

First of all thanks again for the package. I adopted this line in my RMD and never looked back.

bibliography: "`r rbbt::bbt_write_bib('my_article.bib', overwrite = TRUE)`"

It has changed the way i use Zotero and referencing in general. I have some suggestions how to improve the collaborative experience when using rbbt.

First of all, rbbt is able to detect and warn the user when Zotero is not running. Rbbt is also able to check if the file it is trying to write already exists. This means Zotero is probably already aware when my rmd is being compiled on somebody else's machine. One of the reasonable behaviors might be to switch to "autonomous" mode and quit trying to overwrite the bib/json, treating the existing bibliography as valid. This is especially reasonable if rbbt does not find any missing keys against the existing file.

I am even suggesting the "autonomous" mode should be the default behavior,unless some keys exist in the RMD text that are missing in the existing bib/json file. I.e. I guess I am suggesting we reverse the workflow of rbbt. It first tries to read the file and parse the RMD against it and only iif something is missing does it query the Zotero API. If Zotero API is down it throws a warning and moves on.

This workflow might require options() or two and perhaps a new wrapper for bbt_write_bib() specifically tailored to be used in YAML. It would then inherit the logic I described to smooth out the collaborative experience when RMD is shared with a machine that does not have a copy of my Zotero library.

bwiernik commented 3 years ago

A simpler approach that would get you a similar result would be to make call to rbbt conditional in your script:

bibliography: "`r if (Sys.info()['user'] == "brenton") rbbt::bbt_write_bib('my_article.yaml', overwrite = TRUE)`"

You could even do that with each collaborator having their own bibliography file if they add unique references:

bibliography: 
  - "`r if (Sys.info()['user'] == "brenton") rbbt::bbt_write_bib('my_article_brenton.yaml', overwrite = TRUE)`"
  - "`r if (Sys.info()['user'] == "dmytro") rbbt::bbt_write_bib('my_article_dmytro.yaml', overwrite = TRUE)`"

I personally regard the bibliography file created by rbbt as an output file like a knitted HTML--it's not a source file that should be relied on. For example, if I correct an error in my Zotero library, that should make its way into the bibliography file.

(As a side note, you should use "bibliography.yaml" instead of "bibliography.bib". Pandoc needs to convert a bib file back to CSL YAML anyway, and that's a lossy process, so it's best to give it a file in its native format in the first place.)

paleolimbot commented 3 years ago

@bwiernik and I have very different workflows...my solution to this it to use bibliography: bibliography.bib (not dynamically generated) and instead run rbbt::bbt_write_bib() occasionally to keep it up-to-date. I use .bib because I switch to latex outputs occasionally. This approach is useful when you're collaborating because then your co-authors can update the .bib file too.

dmi3kno commented 3 years ago

I feel this discussion about the different workflows is useful. My collaborators also want to be able to use my .bib file without having an exact replica of my Zotero library. If Zotero is running and everything is happening on my machine, I appreciate the opportunity of updating the bib file at render time. Understanding alternative workflows could make a good vignette or two.

paleolimbot commented 3 years ago

It's a good point, I should document using bbt_write_bib() on its own as well (or maybe make that one of the addins)

bwiernik commented 3 years ago

Doing this would work well for that case:

bibliography: 
  - "`r if (Sys.info()['user'] == "dmytro") rbbt::bbt_write_bib('my_article.yaml', overwrite = TRUE)`"
  - "my_article.yaml"

That should regenerate the bibliography file on your machine, but use the existing file on others

bwiernik commented 3 years ago

You could also adapt that idea for other checks, like params$remake_bib = TRUE

paleolimbot commented 2 years ago

Adding bbt_update_bib() + the addin should fix this use-case!