as_cff: Coerce lists and citation objects to 'cff'

View source: R/as-cff.R

as_cffR Documentation

Coerce lists and citation objects to cff

Description

as_cff() turns an existing list-like R object into a cff object, a list with class cff and the corresponding subclass when 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 objects as produced by utils::toBibtex().

  • Default: Other inputs are first coerced with base::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 can be coerced to a list.

...

Additional arguments passed on to other methods.

Details

For as_cff.bibentry() and as_cff.Bibtex(), see vignette("bibtex-cff", package = "cffr") to understand how the mapping is performed.

as_cff_person() is preferred over as_cff.person() because it can handle character inputs such as "Davis, Jr., Sammy". For person objects both functions behave similarly.

Value

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

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

  • The remaining methods return an object of class cff. However, if x has a structure compatible with definitions.person, definitions.entity or definitions.reference, the object has the corresponding subclass.

Learn more about the cffr class system in cff_class.

See Also

  • cff() creates a full cff object from scratch.

  • cff_modify() modifies a cff object.

  • cff_create() creates a cff object for an R package.

  • cff_read() creates a cff object from an external file.

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

Examples

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

class(cffobj)

# Display the YAML representation.
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 Aug. 24, 2026, 5:11 p.m.