cff
classcffr implements a S3 object with
[class
] cff
, that it is used to represent the
information of a CITATION.cff
file in
R.
Under the hood, a cff
object is simply a named
[list
] to which we added additional methods, most notably
[print
] and [as_cff()].
a_named_list <- list(
first = "I", second = "am", third = "a", fourth = "list",
fifth = "with", sixth = "names", "none" = NULL
)
# As cff
a_cff_object <- as_cff(a_named_list)
class(a_cff_object)
[1] "cff"
a_cff_object
first: I
second: am
third: a
fourth: list
fifth: with
sixth: names
is.list(a_cff_object)
[1] TRUE
[as_cff()] not only converts a list
to cff
but also removes items (known as keys
in CFF terminology)
that are NULL
or NA
.
cffr implements two special sub-classes of
cff
, with the aim of representing two special types of
objects defined in the CFF
Schema:
definition.person
and
definition.entity
: CFF definition for sub-lists
representing persons or entities. In cffr the sub-class
cff_pers_lst
has been implemented to collect an array of
definition.person/entity
, where each individual person or
entity of the array has a sub-class cff_pers
.
Similarly, definition.reference
is the definition of
CFF for collecting references to related works and other articles of
software used in the development of the main work of the CFF file. This
is implemented in cffr as a sub-class named
cff_ref_lst
for arrays of definition.reference
where each element of the array has a sub-class named
cff_ref
.
These two sub-classes does not provide full valid cff
objects, but adapts information to the schema required by CFF:
# Using the utils::person() function
## Array
two_persons <- as_cff_person(
c(
person("A", "person", comment = c(ORCID = "0000-0000-0000-0000")),
person("An entity", email = "fake@gmail.com")
)
)
two_persons
- family-names: person
given-names: A
orcid: https://orcid.org/0000-0000-0000-0000
- name: An entity
email: fake@gmail.com
class(two_persons)
[1] "cff_pers_lst" "cff"
# Single element
two_persons[[1]]
family-names: person
given-names: A
orcid: https://orcid.org/0000-0000-0000-0000
class(two_persons[[1]])
[1] "cff_pers" "cff"
# Array of references
cit <- c(citation(), citation("cffr"))
ref_list <- as_cff(cit)
ref_list
- type: manual
title: 'R: A Language and Environment for Statistical Computing'
authors:
- name: R Core Team
institution:
name: R Foundation for Statistical Computing
address: Vienna, Austria
year: '2023'
url: https://www.R-project.org/
- 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'
- type: generic
title: Citation File Format
authors:
- family-names: Druskat
given-names: Stephan
- family-names: Spaaks
given-names: Jurriaan H.
- family-names: Chue Hong
given-names: Neil
- family-names: Haines
given-names: Robert
- family-names: Baker
given-names: James
- family-names: Bliven
given-names: Spencer
- family-names: Willighagen
given-names: Egon
- family-names: Pérez-Suárez
given-names: David
- family-names: Konovalov
given-names: Alexander
year: '2021'
month: '8'
doi: 10.5281/zenodo.5171937
url: https://github.com/citation-file-format/citation-file-format
date-accessed: '2021-11-07'
copyright: CC-BY-4.0
abstract: The Citation File Format lets you provide citation metadata for software
or datasets in plaintext files that are easy to read by both humans and machines.
class(ref_list)
[1] "cff_ref_lst" "cff"
# Single element
ref_list[[1]]
type: manual
title: 'R: A Language and Environment for Statistical Computing'
authors:
- name: R Core Team
institution:
name: R Foundation for Statistical Computing
address: Vienna, Austria
year: '2023'
url: https://www.R-project.org/
class(ref_list[[1]])
[1] "cff_ref" "cff"
cff
objectsCreating a cff
object does not ensure its validity
according to the CFF
Schema:
class(a_cff_object)
[1] "cff"
cff_validate(a_cff_object)
══ Validating cff ══════════════════════════════════════════════════════════════
✖ Oops! This <cff> has the following errors:
* cff.authors: is required
* cff["cff-version"]: is required
* cff.message: is required
* cff.title: is required
[cff_validate()] gives minimal messages of what’s wrong with our
cff
and (invisibly) returns the result of the validation
(TRUE/FALSE
).
cffr version 1.0.0 provides additional S3 Methods for common coercing functions of the base and utils package.
minimal_cff <- cff()
minimal_cff
cff-version: 1.2.0
message: If you use this software, please cite it using these metadata.
title: My Research Software
authors:
- family-names: Doe
given-names: John
as_df <- as.data.frame(minimal_cff)
class(as_df)
[1] "data.frame"
t(as_df)
[,1]
cff_version "1.2.0"
message "If you use this software, please cite it using these metadata."
title "My Research Software"
authors.00.family_names "Doe"
authors.00.given_names "John"
new_keys <- c("date-released" = "2020-01-31", abstract = "Minimal example")
c(minimal_cff, new_keys)
cff-version: 1.2.0
message: If you use this software, please cite it using these metadata.
title: My Research Software
authors:
- family-names: Doe
given-names: John
date-released: '2020-01-31'
abstract: Minimal example
as.list(minimal_cff)
$`cff-version`
[1] "1.2.0"
$message
[1] "If you use this software, please cite it using these metadata."
$title
[1] "My Research Software"
$authors
$authors[[1]]
$authors[[1]]$`family-names`
[1] "Doe"
$authors[[1]]$`given-names`
[1] "John"
Only for cff_pers_lst
and cff_pers
objects:
as.person(two_persons)
[1] "A person (<https://orcid.org/0000-0000-0000-0000>)"
[2] "An entity <fake@gmail.com>"
# For cff
toBibtex(minimal_cff)
@Misc{doe,
title = {My Research Software},
author = {John Doe},
}
# cff_ref, cff_ref_lst
toBibtex(cit)
@Manual{,
title = {R: A Language and Environment for Statistical Computing},
author = {{R Core Team}},
organization = {R Foundation for Statistical Computing},
address = {Vienna, Austria},
year = {2023},
url = {https://www.R-project.org/},
}
@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},
}
@Misc{druskat_citation_2021,
title = {Citation {File} {Format}},
author = {Stephan Druskat and Jurriaan H. Spaaks and Neil {Chue Hong} and Robert Haines and James Baker and Spencer Bliven and Egon Willighagen and David Pérez-Suárez and Alexander Konovalov},
year = {2021},
month = {aug},
doi = {10.5281/zenodo.5171937},
url = {https://github.com/citation-file-format/citation-file-format},
urldate = {2021-11-07},
copyright = {CC-BY-4.0},
date = {2021-08},
abstract = {The Citation File Format lets you provide citation metadata for software or datasets in plaintext files that are easy to read by both humans and machines.},
}
# cff_pers, cff_pers_lst
toBibtex(two_persons)
[1] "person, A and {An entity}"