'RStudio' Add-in to Insert Markdown Citations

Functions and an 'RStudio' add-in that search 'Bib(La)TeX'-files or 'Zotero' libraries (via the 'Better BibTeX' plugin) to insert formatted Markdown citations into the current document.

CRANstatus Downloadcounter Project Status: Active - The project has reached a stable, usablestate and is being activelydeveloped. Buildstatus

citr provides functions and an RStudio addin to search a BibTeX-file to create and insert formatted Markdown citations into the current document.

You can either use the stable version of citr from CRAN,


or the current development snapshot from this GitHub repository:


How to use citr

The RStudio addin

Once citr is installed and you have restarted your R session, the addin appears in the menus. Alternatively, you can define a keyboard shortcut to call the addin.

The addin will automatically look up the bibliography files specified in the YAML front matter. If the document does not contain a YAML front matter the addin will attempt to locate a parent document and look up the bibliography file specified therein. That is, the addin works its automagic even if you edit R Markdown documents that are included as children in another R Markdown document. The expected names of a parent document default to c("index.Rmd", "master.Rmd"), it thus works with bookdown out of the box, but can be customized (e.g., options(citr.parent_documents = "my_parent.Rmd")).

Using citr without RStudio

The following call searches a bibliography file and creates formatted Markdown citations for the results.

md_cite("foo 2016", bib_file = "references.bib")

md_cite() searches the author, year, title, and journal fields of your references.

Better Bib(La)TeX integration

If you are using Zotero citr can access your reference database directly. For this to work, you need to install the Better Bib(La)TeX extension. Once the extension is installed and your reference manager is running, citr can access all your references and keep your bibliography file updated by adding missing references.

Tidying bibliography files

When you are done writing, your bibliography file is likely to contain some unneeded references, which you added while writing but removed during revisions. tidy_bib_file() removes unneeded (or duplicate) entries from your bibliography file.

  rmd_file = "report.Rmd"
  , messy_bibliography = "references.bib"
  , file = "tidy_references.bib"

Known problems

citr relies on RefManager::ReadBib() and, thus, indirectly on bibtex::read.bib() to load bibliographies. I have noticed that very long Bib(La)TeX fields can cause these underlying functions to fail (e.g., Error in do_read_bib(file, encoding = .Encoding, srcfile): lex fatal error: input buffer overflow, can't enlarge buffer because scanner uses REJECT). To avoid such problems, I strongly recommend to disable the export of potentially long metadata fields, such as abstract and notes. The Better Bib(La)TeX-plugin allows users to specify fields to omit:

Once, the above error has occurred, it may be necessary to restart the R session. Otherwise reading any other file may fail with Error: lex fatal error: fatal flex scanner internal error--end of buffer missed.

Other RStudio addins

If you are interested in other handy addins take a look at this list. There you can find other useful addins, such as rcrossref or wordcountaddin.

Package dependencies


citr 0.3.0

  • New function tidy_bib_file() removes duplicate and unneeded entries from a Bib(La)Tex-file.
  • Added encoding option to functions that read Bib(La)TeX-files and a corresponding global option. (reported by @sammo3182 #11)
  • Error message in insert_citation() are printed to the dialog instead of the console (reported by @sammo3182 #11)
  • RStudio addin
    • Access to Zotero group libraries (#9)
    • New settings tab

citr 0.2.0

  • Zotero/Juris-M library can now be accessed directly via the Better Bib(La)TeX extension (https://github.com/retorquere/zotero-better-bibtex). The document's bibliography file is updated accordingly. See ?insert_citation.
  • bibliography entries are no longer checked for missing fields (suggested by @awmercer, #8)
  • If the current document is a child (i.e., included in a larger R Markdown document) the parent file is searched for bibliography paths (suggested and contributed to by @yihui, #7, #10)
  • References in addin selection and inserted markdown citations are ordered alphabetically

citr 0.1.0

Initial release.

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.


0.3.2 by Frederik Aust, a year ago


Report a bug at https://github.com/crsh/citr/issues

Browse source code at https://github.com/cran/citr

Authors: Frederik Aust [aut, cre] , Yihui Xie [ctb] , Robin Lovelace [ctb] , Garrick Aden-Buie [ctb]

Documentation:   PDF Manual  

MIT + file LICENSE license

Imports RefManageR, yaml, rstudioapi, miniUI, shiny, shinyjs, assertthat, methods, curl, httr

Suggests testthat

Imported by rmd.

See at CRAN