Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

write_bib() function needs to be reviewed and edited at the end of chapters #59

Open
pauldpickell opened this issue Sep 29, 2021 · 2 comments
Assignees
Labels
aesthetics css, html, and formatting issues citation references, permissions, citations

Comments

@pauldpickell
Copy link
Contributor

There was a code block that was originally distributed in the chapter template rmd file that looks like below:

knitr::write_bib(c(
  .packages(), 'bookdown', 'knitr', 'rmarkdown', 'htmlwidgets', 'webshot', 'DT',
  'miniUI', 'tufte', 'servr', 'citr', 'rticles'
), 'packages.bib')

This should be modified for each chapter individually so that only the R packages that are used in a given chapter are written to a bib file that is unique to each chapter. For example, chapter 9 that uses the leaflet and raster packages would have the following code block at the end of the chapter:

knitr::write_bib(c(
  .packages(), 'leaflet', 'raster'
), 'chapter_09.bib')

As well, we need to add a code block perhaps in chapter 1 (or a preface?) that provides the citations for knitr, bookdown, and other packages for the entire book:

knitr::write_bib(c(
  .packages(), 'bookdown', 'knitr', 'rmarkdown'
), 'allchapters.bib')

Then, these .bib files can be linked together following the bookdown documentation:

---
bibliography: ["allchapters.bib", "chapter_01.bib", "chapter_02.bib, "chapter_03.bib", "chapter_04.bib", "chapter_05.bib", "chapter_06.bib", "chapter_07.bib", "chapter_08.bib", "chapter_09.bib", "chapter_10.bib", "chapter_11.bib", "chapter_12.bib", "chapter_13.bib", "chapter_14.bib", "chapter_15.bib", "chapter_16.bib", "chapter_17.bib"]
biblio-style: "apalike"
link-citations: true
---
@pauldpickell pauldpickell added the aesthetics css, html, and formatting issues label Sep 29, 2021
@pauldpickell pauldpickell added the citation references, permissions, citations label Dec 16, 2021
@nickmmurphy
Copy link
Contributor

I did some digging in the Knitr documentation and I wanted to make sure I understood the problem with issue #59 "write_bib() function needs to be reviewed and edited at the end of chapters". We need to dynamically update the package bibliographies and not the packages themselves? In this case, if we want the packages to be cited and displayed at the end of the chapter (and have each chapter be different) then I do believe that the proposed solution of having packages-ch1.bib, packages-ch2.bib, etc. is the way to go. If the bibliographies will all be shown at the end of the book, then there will only need to be one packages.bib file containing all of the information. The documentation here https://www.rdocumentation.org/packages/knitr/versions/1.29/topics/write_bib shows an example of a package file being written to that is only for a project's GUI packages, which I feel like supports the idea of multiple .bib files within one project.

@nickmmurphy
Copy link
Contributor

According to this section at https://bookdown.org/yihui/rmarkdown-cookbook/write-bib.html, the write_bib() function is indeed meant to rewrite the file it is accessing, so that is why the packages are being rewritten upon each render. To fix this, I believe there should be only one write_bib() function in the book, which would live in the "Packages Index" chapter (or something similarly named). That way, each of the packages would be updated at the beginning of rendering the "Packages Index" chapter, which would then mean that the references within the chapter would be correct.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
aesthetics css, html, and formatting issues citation references, permissions, citations
Projects
None yet
Development

No branches or pull requests

4 participants