as_bibentry: Create 'bibentry' objects from multiple sources

View source: R/as-bibentry.R

as_bibentryR Documentation

Create bibentry objects from multiple sources

Description

This function creates bibentry objects from multiple metadata sources (cff objects, DESCRIPTION files and other sources). The inverse transformation from a bibentry object to cff_ref_lst can be performed with the corresponding as_cff.bibentry() method.

With toBibtex(), you can convert cff objects to BibTeX markup on the fly. See Examples.

Usage

as_bibentry(x, ...)

## Default S3 method:
as_bibentry(x, ...)

## S3 method for class 'character'
as_bibentry(x, ..., what = c("preferred", "references", "all"))

## S3 method for class ''NULL''
as_bibentry(x, ...)

## S3 method for class 'list'
as_bibentry(x, ...)

## S3 method for class 'cff'
as_bibentry(x, ..., what = c("preferred", "references", "all"))

## S3 method for class 'cff_ref_lst'
as_bibentry(x, ...)

## S3 method for class 'cff_ref'
as_bibentry(x, ...)

Arguments

x

The source used to generate the bibentry object with cffr. It can be:

  • A missing value, which retrieves the DESCRIPTION file from your in-development package.

  • An existing cff object created with cff(), cff_create() or as_cff().

  • A path to a CITATION.cff file ("CITATION.cff").

  • The name of an installed package ("jsonlite").

  • A path to a DESCRIPTION file ("DESCRIPTION").

...

Additional arguments passed to or from methods.

what

Fields to extract from a full cff object. It can be:

  • preferred: Create a single entry with the main citation information of the package (key preferred-citation).

  • references: Extract all entries of the references key.

  • all: Extract both the preferred-citation and references keys.

See vignette("r-cff", package = "cffr").

Details

An R bibentry object is the representation of a BibTeX entry. These objects can be converted to BibTeX markup with utils::toBibtex(), which creates an object of class Bibtex that can be printed and exported as a valid BibTeX entry.

as_bibentry() tries to map the information of the source x into a cff object and maps the metadata to BibTeX as described in vignette("bibtex-cff", package = "cffr").

Value

as_bibentry() returns a bibentry object with one or more entries.

References

Patashnik O (1988). "BIBTEXing." https://osl.ugr.es/CTAN/biblio/bibtex/base/btxdoc.pdf.

Haines R, The Ruby Citation File Format Developers (2022). "Ruby CFF Library." \Sexpr[results=rd]{tools:::Rd_expr_doi("10.5281/zenodo.7294987")}. https://github.com/citation-file-format/ruby-cff.

Hernangómez D (2022). "BibTeX and CFF, a potential crosswalk." cffr vignette. https://docs.ropensci.org/cffr/articles/bibtex-cff.html.

See Also

  • utils::bibentry() documents the bibentry class.

  • vignette("r-cff", package = "cffr") explains how the metadata of a package is mapped to produce a cff object.

  • vignette("bibtex-cff", package = "cffr") provides details about the internal mapping performed between cff objects and BibTeX markup, both cff to BibTeX and BibTeX to cff.

  • utils::toBibtex() converts bibentry objects to BibTeX markup.

Work with BibTeX metadata: cff_read(), cff_read_bib_text(), cff_write_bib(), encoded_utf_to_latex()

Convert between R classes: as_cff(), as_cff_person(), cff_class

Examples


# From a `cff` object ----
cff_object <- cff()

cff_object

# A `bibentry` object.
bib <- as_bibentry(cff_object)

class(bib)

bib

# Print as BibTeX.
toBibtex(bib)

# The S3 method also supports this.
toBibtex(cff_object)

# Other sources ----
# From a CITATION.cff.

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

cff_file

# For an installed package with options.
installed_package <- as_bibentry("jsonvalidate", what = "all")

installed_package

# Use a DESCRIPTION file.
path2 <- system.file("examples/DESCRIPTION_gitlab", package = "cffr")
desc_file <- as_bibentry(path2)

toBibtex(desc_file)



cffr documentation built on Aug. 24, 2026, 5:11 p.m.