print_refs: Print and Format '.bib' Entries as References

View source: R/print_refs.R

print_refsR Documentation

Description

print_refs() is a convenience function I found and edited that will allow a user to print and format .bib entries as if they were references. This function is useful if you want to load a .bib entry or set of entries and print them in the middle of a document in R Markdown.

Usage

print_refs(
  bib,
  csl = "american-political-science-association.csl",
  toformat = "markdown_strict",
  cslrepo = "https://raw.githubusercontent.com/citation-style-language/styles/master",
  spit_out = TRUE,
  delete_after = TRUE
)

Arguments

bib

a valid .bib entry

csl

a CSL file, matching one available on the Github repository, that the user wants to format the references. Default is "american-political-science-association.csl".

toformat

the output wanted by the user. Default is "markdown_strict".

cslrepo

a directory of CSL files. Defaults to the one on Github.

spit_out

logical, defaults to TRUE. If TRUE, wraps ("spits out") formatted citations in a writeLines() output for the console. If FALSE, returns a character vector.

delete_after

logical, defaults to TRUE. If TRUE, deletes CSL file when it's done. If FALSE, retains CSL for (potential) future use.

Details

print_refs() assumes an active internet connection in the absence of the appropriate CSL file in the working directory. The citation style language (CSL) file supplied by the user must match a file in the massive Github repository of CSL files. Users interested in potential outputs should read more about Pandoc (https://pandoc.org/MANUAL.html). The Github repository of CSL files is available here: https://github.com/citation-style-language/styles.

Value

print_refs() takes a .bib entry and returns the requested formatted reference or references from it.

Examples



example <- "@Book{vasquez2009twp, Title = {The War Puzzle Revisited},
Author = {Vasquez, John A}, Publisher = {New York, NY: Cambridge University Press},
Year = {2009}}"

print_refs(example)


stevemisc documentation built on Sept. 11, 2024, 5:23 p.m.