MyNixOS website logo
Description

R Interface to 'Zotero' via Better BibTeX.

Connects R to 'Zotero' through the 'Better BibTeX' for 'Zotero' connector <https://retorque.re/zotero-better-bibtex/>. Provides functions to insert in-text citations and bibliography entries directly into documents, detect citations already present in R Markdown and Quarto files, and synchronise bibliography files. Includes an 'RStudio addin' for interactive use.

zoteR

An R interface to Zotero via the Better BibTeX add-on. zoteR lets you insert citations, fetch bibliography data, and keep bibliography files in sync with your Zotero library — all from R, with RStudio addin support.

Prerequisites

Installation

# install.packages("pak")
pak::pkg_install("sarcastic-scientist/zoteR")

Usage

Check connection

zt_is_running()   # TRUE if Zotero + Better BibTeX are available

Insert citations

Open the Better BibTeX cite-as-you-write picker and return a formatted citation:

# Pandoc format: [@doe2020]
zt_cite(format = "pandoc", .action = zt_insert)

# LaTeX format: \cite{doe2020}
zt_cite(format = "latex", .action = zt_insert)

Fetch bibliography data

# For specific citation keys
zt_bib(c("doe2020", "smith2019"), format = "json")

# Interactively via CAYW picker
zt_bib_cayw(format = "biblatex")

# For currently selected items in Zotero
zt_bib_selected(format = "json")

Format note:"json" (CSL-JSON) is recommended for R Markdown and Quarto documents. Other formats undergo lossy conversion when pandoc processes the bibliography.

Sync bibliography files

The primary use case is keeping a bibliography file up to date as you write. Add this to your document's YAML front matter:

bibliography: "`r zoteR::zt_write_bib('refs.json', overwrite = TRUE)`"

Every time the document knits, zt_write_bib() detects all @key citations in the file and fetches the latest data from Zotero.

To update the bibliography file without knitting:

zt_update_bib("paper.Rmd")   # reads bibliography path from YAML front matter

Detect citations

# Scan a file for pandoc-style citation keys
zt_detect_citations("paper.Rmd")

# Scan a string
zt_detect_citations_text("See [@doe2020] and @smith2019.")

Code chunks, inline R expressions, and URLs are excluded from detection to avoid false positives. To force a key to be included (e.g. cited only in a figure caption), add it to a nocite field in your YAML front matter or in an HTML comment.

Library management

zt_libraries()              # data frame of all available libraries

# Look up library ID by name (more portable than hardcoding IDs)
zt_bib(keys, library_id = zt_library_id("Group Library Name"))

Output actions

All retrieval functions accept a .action argument that controls what happens to the result:

ActionBehaviour
zt_returnreturn invisibly (default; assign to a variable)
zt_printprint to console
zt_insertinsert at cursor in RStudio
zt_copycopy to clipboard

RStudio addins

Three addins are included (accessible via Addins menu or keyboard shortcuts):

AddinFunction
Insert Zotero CitationOpens CAYW picker; inserts citation at cursor
Insert Zotero Bibliography (Selected Items)Inserts bibliography for items selected in Zotero
Update Bibliography for Current DocumentSyncs bibliography file for the active .Rmd / .qmd

Citation format (Pandoc vs. LaTeX) is detected automatically from the active file's extension.

Package options

OptionDefaultDescription
zoter.default.format"biblatex"Default bibliography format
zoter.default.bib"biblatex"Format for .bib files ("biblatex" or "bibtex")
zoter.default.library_id1LDefault Zotero library ID
options(zoter.default.format = "json")

License

GPL (>= 3)

Metadata

Version

1.0.0

License

Unknown

Platforms (80)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    uefi
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-freebsd
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64-uefi
  • aarch64-windows
  • aarch64_be-none
  • arc-linux
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-linux
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • sh4-linux
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-uefi
  • x86_64-windows