as_cff: Coerce lists, 'person' and 'bibentry' objects to 'cff'

View source: R/as_cff.R

as_cffR Documentation

Coerce lists, person and bibentry objects to cff

Description

as_cff() turns an existing list-like R object into a so-called cff, a list with class cff, with the corresponding sub-class if applicable, .

as_cff is an S3 generic, with methods for:

  • person objects as produced by utils::person().

  • bibentry objects as produced by utils::bibentry().

  • Bibtex object as produced by toBibtex().

  • Default: Other inputs are first coerced with as.list().

Usage

as_cff(x, ...)

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

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

## S3 method for class 'person'
as_cff(x, ...)

## S3 method for class 'bibentry'
as_cff(x, ...)

## S3 method for class 'Bibtex'
as_cff(x, ...)

Arguments

x

A person, bibentry or other object that could be coerced to a list.

...

Additional arguments to be passed on to other methods.

Details

For as_cff.bibentry() / as_cff.Bibtex() see vignette("bibtex_cff", "cffr") to understand how the mapping is performed.

as_cff_person() is preferred over as_cff.person(), since it can handle character person such as "Davis, Jr., Sammy". For person objects both functions are similar.

Value

  • as_cff.person() returns an object with classes cff_pers_lst, cff.

  • as_cff.bibentry() and as_cff.Bibtex() returns an object with classes cff_ref_lst, cff.

  • The rest of methods returns usually an object of class cff. However if x have an structure compatible with definitions.person, definitions.entity or definitions.reference the object would have the corresponding subclass.

Learn more about the cffr class system in cff_class.

See Also

  • cff(): Create a full cff object from scratch.

  • cff_modify(): Modify a cff object.

  • cff_create(): Create a cff object of a R package.

  • cff_read(): Create a cff object from a external file.

  • as_cff_person(): Recommended way for creating persons in CFF format.

Learn more about the cffr class system in cff_class.

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

Examples


# Convert a list to "cff" object
cffobj <- as_cff(list(
  "cff-version" = "1.2.0",
  title = "Manipulating files"
))

class(cffobj)

# Nice display thanks to yaml package
cffobj

# bibentry method
a_cit <- citation("cffr")[[1]]

a_cit

as_cff(a_cit)

# Bibtex method
a_bib <- toBibtex(a_cit)

a_bib

as_cff(a_cit)


cffr documentation built on April 3, 2025, 9:33 p.m.