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 byutils::person()
.bibentry
objects as produced byutils::bibentry()
.Bibtex
object as produced bytoBibtex()
.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, ...)
Value
as_cff.person()
returns an object with classescff_pers_lst, cff
.as_cff.bibentry()
andas_cff.Bibtex()
returns an object with classescff_ref_lst, cff
.
The rest of methods returns usually an object of class
cff
. However ifx
have an structure compatible withdefinitions.person
,definitions.entity
ordefinitions.reference
the object would have the corresponding subclass.
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.
See also
cff()
: Create a fullcff
object from scratch.cff_modify()
: Modify acff
object.cff_create()
: Create acff
object of a R package.cff_read()
: Create acff
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)
#> [1] "cff"
# Nice display thanks to yaml package
cffobj
#> cff-version: 1.2.0
#> title: Manipulating files
# bibentry method
a_cit <- citation("cffr")[[1]]
a_cit
#> Hernangómez D (2021). “cffr: Generate Citation File Format Metadata for
#> R Packages.” _Journal of Open Source Software_, *6*(67), 3900.
#> doi:10.21105/joss.03900 <https://doi.org/10.21105/joss.03900>,
#> <https://doi.org/10.21105/joss.03900>.
#>
#> A BibTeX entry for LaTeX users is
#>
#> @Article{hernangomez2021,
#> doi = {10.21105/joss.03900},
#> url = {https://doi.org/10.21105/joss.03900},
#> year = {2021},
#> publisher = {The Open Journal},
#> volume = {6},
#> number = {67},
#> pages = {3900},
#> author = {Diego Hernangómez},
#> title = {{cffr}: Generate Citation File Format Metadata for {R} Packages},
#> journal = {Journal of Open Source Software},
#> }
as_cff(a_cit)
#> - type: article
#> title: 'cffr: Generate Citation File Format Metadata for R Packages'
#> authors:
#> - family-names: Hernangómez
#> given-names: Diego
#> doi: 10.21105/joss.03900
#> url: https://doi.org/10.21105/joss.03900
#> year: '2021'
#> publisher:
#> name: The Open Journal
#> volume: '6'
#> issue: '67'
#> journal: Journal of Open Source Software
#> start: '3900'
# Bibtex method
a_bib <- toBibtex(a_cit)
a_bib
#> @Article{hernangomez2021,
#> doi = {10.21105/joss.03900},
#> url = {https://doi.org/10.21105/joss.03900},
#> year = {2021},
#> publisher = {The Open Journal},
#> volume = {6},
#> number = {67},
#> pages = {3900},
#> author = {Diego Hernangómez},
#> title = {{cffr}: Generate Citation File Format Metadata for {R} Packages},
#> journal = {Journal of Open Source Software},
#> }
as_cff(a_cit)
#> - type: article
#> title: 'cffr: Generate Citation File Format Metadata for R Packages'
#> authors:
#> - family-names: Hernangómez
#> given-names: Diego
#> doi: 10.21105/joss.03900
#> url: https://doi.org/10.21105/joss.03900
#> year: '2021'
#> publisher:
#> name: The Open Journal
#> volume: '6'
#> issue: '67'
#> journal: Journal of Open Source Software
#> start: '3900'