Skip to contents

This function creates BibTeX entries (in the form of bibentry() objects from different metadata sources (cff objects, DESCRIPTION files, etc.). The function tries to parse the information of the source x into a cff object and performs a mapping of the metadata to BibTeX, according to vignette("bibtex_cff", "cffr").

Usage

cff_to_bibtex(x, what = c("preferred", "references", "all"))

Arguments

x

The source that would be used for generating the bibentry() object via cff. It could be:

  • A missing value. That would retrieve the DESCRIPTION file on your in-development package.

  • An existing cff object,

  • Path to a CITATION.cff file ("*/CITATION.cff*"),

  • The name of an installed package ("jsonlite"), or

  • Path to a DESCRIPTION file ("*/DESCRIPTION*").

what

Fields to extract. The value could be:

  • preferred: This would create a single entry with the main citation info of the package.

  • references: Extract all the entries on references.

  • all: A combination of the previous two options. This would extract both the preferred citation info and the references.

Value

A bibentry object or a list of bibentry objects. This could be parsed to BibTeX using toBibtex()

References

See also

Examples

# \donttest{
# From a cff object
cff_object <- cff()

cff_object
#> authors:
#> - family-names: Doe
#>   given-names: John
#> cff-version: 1.2.0
#> message: If you use this software, please cite it using these metadata.
#> title: My Research Software

# bibentry object
bib <- cff_to_bibtex(cff_object)
#>  Entry "doe" does not have year 

class(bib)
#> [1] "bibentry"

bib
#> Doe J (????). “My Research Software.”

# Print as bibtex

toBibtex(bib)
#> @Misc{doe,
#>   title = {My Research Software},
#>   author = {John Doe},
#> }

# From a CITATION.cff file with options

path <- system.file("examples/CITATION_complete.cff", package = "cffr")
cff_file <- cff_to_bibtex(path, what = "all")

toBibtex(cff_file)
#> @InBook{vanderrealpersoniventityprojectteamconferenceentity:2017,
#>   title = {Book Title},
#>   author = {One Truly {van der Real Person IV} and {Entity Project Team Conference entity}},
#>   year = {2017},
#>   month = {mar},
#>   journal = {PeerJ},
#>   publisher = {Entity Project Team Conference entity},
#>   address = {22 Acacia Avenue, Citationburgh, Renfrewshire, GB},
#>   editor = {One Truly {van der Real Person IV} and {Entity Project Team Conference entity}},
#>   series = {Collection Title},
#>   volume = {2},
#>   number = {123},
#>   pages = {123--456},
#>   doi = {10.5281/zenodo.1003150},
#>   isbn = {978-1-89183-044-0},
#>   issn = {1234-543X},
#>   url = {http://j.mp},
#>   note = {A field for general notes about the reference, usable in other formats such as BibTeX.},
#>   chapter = {Chapter 2 - "Reference keys"},
#>   edition = {2nd edition},
#>   howpublished = {Hardcover book},
#>   institution = {Entity Project Team Conference entity},
#>   keywords = {Software, Citation},
#>   abstract = {Description of the book.},
#>   date = {2017-10-31},
#>   file = {book.zip},
#>   issuetitle = {Special Issue on Software Citation},
#>   pagetotal = {765},
#>   urldate = {2017-10-31},
#>   version = {0.0.1423-BETA},
#>   translator = {van der Real Person, IV, One Truly and {Entity Project Team Conference entity}},
#> }
#> 
#> @InBook{vanderrealpersoniventityprojectteamconferenceentity:2017,
#>   title = {Book Title},
#>   author = {One Truly {van der Real Person IV} and {Entity Project Team Conference entity}},
#>   year = {2017},
#>   month = {mar},
#>   journal = {PeerJ},
#>   publisher = {Entity Project Team Conference entity},
#>   address = {22 Acacia Avenue, Citationburgh, Renfrewshire, GB},
#>   editor = {One Truly {van der Real Person IV} and {Entity Project Team Conference entity}},
#>   series = {Collection Title},
#>   volume = {2},
#>   number = {123},
#>   pages = {123},
#>   doi = {10.5281/zenodo.1003150},
#>   isbn = {978-1-89183-044-0},
#>   issn = {1234-543X},
#>   url = {http://j.mp},
#>   note = {A field for general notes about the reference, usable in other formats such as BibTeX.},
#>   chapter = {Chapter 2 - "Reference keys"},
#>   edition = {2nd edition},
#>   howpublished = {Hardcover book},
#>   institution = {Entity Project Team Conference entity},
#>   keywords = {Software, Citation},
#>   abstract = {Description of the book.},
#>   date = {2017-10-31},
#>   file = {book.zip},
#>   issuetitle = {Special Issue on Software Citation},
#>   pagetotal = {765},
#>   urldate = {2017-10-31},
#>   version = {0.0.1423-BETA},
#>   translator = {van der Real Person, IV, One Truly and {Entity Project Team Conference entity}},
#> }

# For an installed package

installed_package <- cff_to_bibtex("jsonvalidate")

toBibtex(installed_package)
#> @Misc{fitzjohnashton,
#>   title = {jsonvalidate: Validate 'JSON' Schema},
#>   author = {Rich FitzJohn and Rob Ashton and Mathias Buus and Evgeny Poberezkin},
#>   year = {2023},
#>   url = {https://docs.ropensci.org/jsonvalidate/},
#>   keywords = {json, json-validation, jsonvalidate, r, r-package, rstats},
#>   abstract = {Uses the node library 'is-my-json-valid' or 'ajv' to validate 'JSON' against a 'JSON' schema. Drafts 04, 06 and 07 of 'JSON' schema are supported.},
#>   version = {1.4.2},
#> }


# Use a DESCRIPTION file

path2 <- system.file("examples/DESCRIPTION_gitlab", package = "cffr")
desc_file <- cff_to_bibtex(path2)
#>  Entry "boettigersalmon" does not have year 

toBibtex(desc_file)
#> @Misc{boettigersalmon,
#>   title = {codemetar: Generate 'CodeMeta' Metadata for R Packages},
#>   author = {Carl Boettiger and Maëlle Salmon},
#>   url = {https://ropensci.github.io/codemetar},
#>   keywords = {metadata, codemeta, ropensci, citation, credit, linked-data},
#>   abstract = {The 'Codemeta' Project defines a 'JSON-LD' format for describing software metadata, as detailed at <https://codemeta.github.io>. This package provides utilities to generate, parse, and modify 'codemeta.json' files automatically for R packages, as well as tools and examples for working with 'codemeta.json' 'JSON-LD' more generally.},
#>   version = {0.1.6},
#> }
# }