as_bibentry {cffr}R Documentation

Create bibentry objects from several sources

Description

This function creates bibentry objects from different metadata sources (cff objects, DESCRIPTION files, etc.). The inverse transformation (bibentry object to cff_ref_lst) can be done with the corresponding as_cff.bibentry() method.

With toBibtex() it is possible to 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 that would be used for generating the bibentry object via cffr. It could be:

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

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

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

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

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

...

Additional arguments to be passed to or from methods.

what

Fields to extract from a full cff object. The value could be:

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

  • references: Extract all the entries of references key.

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

See vignette("crosswalk", package = "cffr").

Details

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

as_bibtex() tries to map 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")'.

Value

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

References

See Also

utils::bibentry() to understand more about the bibentry class.

Other related functions:

Other functions for working with BibTeX format: cff_read(), cff_read_bib_text(), cff_write_bib(), encoded_utf_to_latex()

Coercing between R classes with S3 Methods: as_cff(), as_cff_person(), cff_class

Examples


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

cff_object

# bibentry object
bib <- as_bibentry(cff_object)

class(bib)

bib

# Print as bibtex
toBibtex(bib)

# Thanks to the S3 Method we can also do
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)



[Package cffr version 1.0.1 Index]