Is there a way to format a 'BibEntry' (from RefManageR) using the .csl file specified in the rmarkdown yaml header?

22 Views Asked by At

I have an rmarkdown file that includes a bibliography and csl file in the yaml header:

---
output: 
  bookdown::word_document2: 
    number_sections: no
    reference_docx: "templates/my-template.docx"
documentclass: article
bibliography: "bibliography/refs.bib"
csl: "bibliography/nature.csl"
link-citations: false
---

This document has a main section and an appendix. In the main section, I cite references as described here: https://bookdown.org/yihui/rmarkdown-cookbook/bibliography.html. In the appendix, I want to print the bibliography entry for a single selected reference without citing it anywhere and without appearing in the main section's bibliography. I found a solution using RefManageR (see the reproducible example below). The only issue I'm having is that the print method for the BibEntry object does not include a way to specify the format of the output. Rather the output uses some default csl format that can't be changed. I'd like to be able to apply the csl style specified in the yaml header to the output of the print method for the BibEntry. I found this solution (Creating formatted references with different citation styles to academic papers without DOIs) but it doesn't work on a BibEntry and I don't want to create a new .bib file for each of the references I want to print in this way.

Note: the .csl file can be downloaded here: https://www.zotero.org/styles?q=nature

Reproducible example for the code I have:

bib <- RefManageR::GetBibEntryWithDOI("10.1038/s41558-020-0874-1")
print(bib, .opts = list(style = "text", bib.style = "authoryear"))

Which produces:

Befus, K. M., P. L. Barnard, D. J. Hoover, J. A. F. Hart, and C. I. Voss (2020). “Increasing threat of coastal groundwater hazards from sea-level rise in California”. In: Nature Climate Change 10.10, pp. 946-952. DOI: 10.1038/s41558-020-0874-1. https://doi.org/10.1038/s41558-020-0874-1.

But the journal format I'm looking for would be this:

Befus, K. M., Barnard, P. L., Hoover, D. J., Hart, J. A. F. & Voss, C. I. Increasing threat of coastal groundwater hazards from sea-level rise in California. Nat. Clim. Change 10, 946–952 (2020)

I'd love for something like this:

print(bib, 
      .opts = list(
          style = "text", 
          bib.style = "authoryear", 
          ref.style = "bibliography/nature.csl"
          )
      )

But I'd settle for a wrapper function around the print.BibEntry method in RefManageR, so long as the bib.style="authoryear" can be kept when applying the nature.csl

Thanks in advance!

0

There are 0 best solutions below