Skip to contents

Extract the information of a BibTeX file or BibTeX entry and creates the corresponding cff object with cff_parse_citation().

Usage

cff_from_bibtex(x, encoding = "UTF-8", ...)

Arguments

x

The source that would be used for generating the cff object. A character object indicating either:

  • The path to a BibTeX file.

  • A vector of characters with the full BibTeX string. See Examples

encoding

Encoding to be assumed for x. See readLines().

...

Other arguments passed to bibtex::read.bib().

Value

A cff object ready to be used on cff_create().

Details

This function requires the package bibtex (>= 0.5.0), that is listed as Suggested by cffr.

See also

vignette("bibtex_cff", package = "cffr") to learn about the mapping of information between BibTeX and CITATION.cff.

Other BibTeX helpers: cff_to_bibtex(), encoded_utf_to_latex(), write_bib(), write_citation()

Examples

if (requireNamespace("bibtex", quietly = TRUE)) {
  x <- c(
    "@book{einstein1921,
    title        = {Relativity: The Special and the General Theory},
    author       = {Einstein, Albert},
    year         = 1920,
    publisher    = {Henry Holt and Company},
    address      = {London, United Kingdom},
    isbn         = 9781587340925
}",
    "@misc{misc-full,
    title        = {Handing out random pamphlets in airports},
    author       = {Joe-Bob Missilany},
    year         = 1984,
    month        = oct,
    note         = {This is a full MISC entry},
    howpublished = {Handed out at O'Hare}
}"
  )

  cff_from_bibtex(x)

  # From a file

  x2 <- system.file("examples/example.bib", package = "cffr")
  cff_from_bibtex(x2)
}
#> - type: generic
#>   title: Citation File Format
#>   authors:
#>   - family-names: Druskat
#>     given-names: Stephan
#>   - family-names: Spaaks
#>     given-names: Jurriaan H.
#>   - family-names: Chue Hong
#>     given-names: Neil
#>   - family-names: Haines
#>     given-names: Robert
#>   - family-names: Baker
#>     given-names: James
#>   - family-names: Bliven
#>     given-names: Spencer
#>   - family-names: Willighagen
#>     given-names: Egon
#>   - family-names: Pérez-Suárez
#>     given-names: David
#>   - family-names: Konovalov
#>     given-names: Alexander
#>   year: '2021'
#>   month: '8'
#>   doi: 10.5281/zenodo.5171937
#>   url: https://github.com/citation-file-format/citation-file-format
#>   date-accessed: '2021-11-07'
#>   copyright: CC-BY-4.0
#>   abstract: The Citation File Format lets you provide citation metadata for software
#>     or datasets in plaintext files that are easy to read by both humans and machines.
#> - type: article
#>   title: 'cffr: Generate Citation File Format Metadata for R Packages'
#>   authors:
#>   - family-names: Hernangómez
#>     given-names: Diego
#>   year: '2021'
#>   journal: Journal of Open Source Software
#>   publisher:
#>     name: The Open Journal
#>   volume: '6'
#>   issue: '67'
#>   doi: 10.21105/joss.03900
#>   url: https://doi.org/10.21105/joss.03900
#>   copyright: All rights reserved
#>   notes: 'Publisher: The Open Journal'
#>   start: '3900'