I am posting this as a question, so I can answer it for the benefit of others.

The problem:

I wanted to produce an overview table of 50+ scientific articles included in a literature review.

I stored data of each article in an R data frame, including a column 'ref' which was a text that represented the unique identifier for that article in my bibTeX file.

I wanted to render (quarto) that data frame into a table in my output (html or docx), but with the appropriate citation, as managed by pandoc.

The issue here then is: How to go from a string variable representing a unique bibtex entry identifier in R code to a markdown citation inside a markdown table.

1

There are 1 best solutions below

0
On

One solution

The following is a minimal working example of a solution:

---
title: "Programmatically including bibTeX references in a table"
format: html
bibliography: references.bib
---

```{r}
#| echo: false
#| message: false
#| warning: false
#| label: tbl-overview
#| tbl-cap: "Overview of all included manuscripts"
#| output: asis
library(simplermarkdown)

df <- data.frame(
  Title = c("Paper 1", "Paper 2"),
  Name = c("Author 1", "Author 2"),
  ref = c("@ref1", "@ref2"))

df |> md_table() |> cat()

```

this requires a bibtex file called references.bib

@article{ref1,
  title={This is article 1},
  author={Lastname, Firstname},
  year={1999},
  publisher={Charles Scribners Sons}
}

@article{ref2,
  title={This is article 2},
  author={Familyname, Givenname},
  year={2010},
  publisher={Charles Scribners Parents}
}