rmarkdown: how to use multiple bibliographies for a document
For the record: I raised this as an issue for pandoc-citeproc at https://github.com/jgm/pandoc-citeproc/issues/220
It turns out that there were problems in how pandoc-citeproc
handles some characters in @{string={}}
and non-ASCII characters in .bib
files, so what I was trying now works, with hard-coded pathnames, in all the forms I tried.
To make it work more like processing of .Rnw
files via Latex/bibtex it would be nice to be able to use something like
bibliography:
- `r system(kpsewhich statistics.bib)`
- `r system(kpsewhich graphics.bib)`
Those commands do find the right files in an R session, but not from a YAML header.
How to insert two separate bibliographies (without citing them in the body text) under two separate headers in R Markdown?
You could use biblatex to split the bibliographies:
---
title: 'John Doe'
output:
pdf_document:
keep_tex: true
csl: vancouver.csl
header-includes:
- \include{preamble.tex}
---
with preamble.tex
:
\usepackage[style=vancouver]{biblatex}
\addbibresource{bib1.bib}
\addbibresource{bib2.bib}
\DeclareSourcemap{
\maps[datatype=bibtex]{
\map[overwrite]{
\perdatasource{bib1.bib}
\step[fieldset=keywords, fieldvalue={,peer}, append]
}
}
}
\AtEndDocument{\nocite{*}
\printbibliography[keyword={peer},title={Peer-reviewed publications}]
\DeclareFieldFormat{labelnumber}{%
\ifinteger{#1}
{\number\numexpr#1-2\relax}
{#1}}
\printbibliography[notkeyword={peer},title={Other publications}]}
And then compile the resulting filename.tex
file with
pdflatex filename
biber filename
pdflatex filename
Include extra bibliography in R Markdown
The contents of an external Word file can be included in R Markdown via officer::block_pour_docx
. I used Zotero to generate a Word bibliography based on pacakges.bib and then the following to include in my document:
```{r}
block_pour_docx("packages.docx")
```
CSL file not applied everywhere when having two bibliographies
The solution can be found in the comments of this answer. The only thing to do is to replace:
local tmp_meta = pandoc.Meta{bibliography = doc_meta['bibliography' .. name]}
by
local tmp_meta = pandoc.Meta{bibliography = doc_meta['bibliography' .. name], csl = doc_meta.csl}
in multiple-bibliographies.lua
Rmarkdown: how to import all the *.bib files in a directory for bibliography?
You can do this, but it's a little tricky. What Pandoc wants to see in the bibliography
field is something like
bibliography: ["file1.bib", "file2.bib"]
I can get that with this code:
bibliography: ["`r paste(c('file1.bib', 'file2.bib'), collapse='\",\"')`"]
Given your updated structure of the directory, I think this should work:
bibliography: ["`r paste(list.files(path = './includes', pattern = '^.+\\.bib$', full.names = TRUE), collapse='\",\"')`"]
The list.files()
call will give you usable names, you don't need to modify it.
Related Topics
How to Modify an Existing a Sheet in an Excel Workbook Using Openxlsx Package in R
Calculating Time Difference Between Two Columns
Adding Empty Graphs to Facet_Wrap in Ggplot2
How to Cumulatively Add Values in One Vector in R
Reshape Multiple Categorical Variables to Binary Response Variables
How to Find the Indices of the Top 10,000 Elements in a Symmetric Matrix(12K X 12K) in R
Pie Charts in Ggplot2 with Variable Pie Sizes
The Simplest Way to Convert a List with Various Length Vectors to a Data.Frame in R
R Solve:System Is Exactly Singular
Get First and Last Values Per Group - Dplyr Group_By with Last() and First()
Why Has Data.Table Defined := Rather Than Overloading <-
Optimized Rolling Functions on Irregular Time Series with Time-Based Window