yml_reference() creates YAML fields for references to be used in citation. reference() is a simple function to add references to yml_reference(). The easiest way to add references to an R Markdown file is to use a bibliography file, such as .bib, in the bibliography field (see yml_citations()). For documents with very few references, however, it might be useful to make the references self-contained in the YAML. yml_reference() can also transform to YAML bibentry and citation objects created bybibentry() and citation(). To cite many R packages and convert the references to YAML, it may be better to use knitr::write_bib() to write a bibliography file and convert it with bib2yml().

yml_reference(.yml, ..., .bibentry = NULL)

reference(id = NULL, ...)

Arguments

.yml

a yml object created by yml(), as_yml(), or returned by a yml_*() function

...

Fields relevant to the citation (e.g. bibtex fields)

.bibentry

An object created by bibentry() or citation(). Note that this requires pandoc-citeproc to be installed.

id

a character vector to use as the reference ID

Value

a yml object

See also

Examples

ref <- reference( id = "fenner2012a", title = "One-click science marketing", author = list( family = "Fenner", given = "Martin" ), `container-title` = "Nature Materials", volume = 11L, URL = "http://dx.doi.org/10.1038/nmat3283", DOI = "10.1038/nmat3283", issue = 4L, publisher = "Nature Publishing Group", page = "261-263", type = "article-journal", issued = list( year = 2012, month = 3 ) ) yml() %>% yml_reference(ref)
#> --- #> author: Malcolm Barrett #> date: '`r format(Sys.Date())`' #> reference: #> - id: fenner2012a #> title: One-click science marketing #> author: #> family: Fenner #> given: Martin #> container-title: Nature Materials #> volume: 11 #> URL: http://dx.doi.org/10.1038/nmat3283 #> DOI: 10.1038/nmat3283 #> issue: 4 #> publisher: Nature Publishing Group #> page: 261-263 #> type: article-journal #> issued: #> year: 2012.0 #> month: 3.0 #> --- #>
# from ?bibentry bref <- c( bibentry( bibtype = "Manual", title = "boot: Bootstrap R (S-PLUS) Functions", author = c( person("Angelo", "Canty", role = "aut", comment = "S original"), person(c("Brian", "D."), "Ripley", role = c("aut", "trl", "cre"), comment = "R port, author of parallel support", email = "ripley@stats.ox.ac.uk") ), year = "2012", note = "R package version 1.3-4", url = "https://CRAN.R-project.org/package=boot", key = "boot-package" ), bibentry( bibtype = "Book", title = "Bootstrap Methods and Their Applications", author = as.person("Anthony C. Davison [aut], David V. Hinkley [aut]"), year = "1997", publisher = "Cambridge University Press", address = "Cambridge", isbn = "0-521-57391-2", url = "http://statwww.epfl.ch/davison/BMA/", key = "boot-book" ) ) # \donttest{ # requires pandoc-citeproc to be installed yml() %>% yml_reference(.bibentry = bref)
#> --- #> author: Malcolm Barrett #> date: '`r format(Sys.Date())`' #> references: #> - id: boot-package #> type: book #> author: #> - family: Canty #> given: Angelo #> - family: Ripley #> given: Brian D. #> issued: #> - year: 2012 #> title: 'Boot: Bootstrap r (s-plus) functions' #> title-short: Boot #> note: R package version 1.3-4 #> URL: https://CRAN.R-project.org/package=boot #> - id: boot-book #> type: book #> author: #> - family: Davison #> given: Anthony C. #> - family: Hinkley #> given: David V. #> issued: #> - year: 1997 #> title: Bootstrap methods and their applications #> publisher: Cambridge University Press #> publisher-place: Cambridge #> URL: http://statwww.epfl.ch/davison/BMA/ #> ISBN: 0-521-57391-2 #> --- #>
yml() %>% yml_reference(.bibentry = citation("purrr"))
#> --- #> author: Malcolm Barrett #> date: '`r format(Sys.Date())`' #> references: #> - id: R-purrr #> type: book #> author: #> - family: Henry #> given: Lionel #> - family: Wickham #> given: Hadley #> issued: #> - year: 2019 #> title: 'Purrr: Functional programming tools' #> title-short: Purrr #> note: R package version 0.3.3 #> URL: https://CRAN.R-project.org/package=purrr #> --- #>
# }