Git Product home page Git Product logo

citr's Introduction

citr: RStudio Addin to Insert Markdown Citations

CRAN status Download counter Project Status: Active - The project has reached a stable, usable state and is being actively developed. Build status

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

Installation

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

install.packages("citr")

or the current development snapshot from this GitHub repository:

devtools::install_github("crsh/citr")

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 Bib(La)TeX-file(s) 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 Bib(La)TeX-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 Bib(La)TeX-file and creates formatted Markdown citations for the results.

library("citr")
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 or Juris-M citr can access your reference database directly. For this to work, you need to install the Better Bib(La)TeX extension, which I would recommend anyway. Once the extension is installed and your reference manager is running, citr will automatically access all your references and keep your Bib(La)Tex-file updated by adding missing references. If you dislike this behavior, you can disable it by setting options(citr.use_betterbiblatex = FALSE).

Tidying bibliography files

When you are done writing, your Bib(La)Tex 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 Bib(La)Tex-file.

tidy_bib_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 occured, it may be neccessary 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's People

Contributors

batpigandme avatar crsh avatar yihui avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.