cff_writer: Citation File Format (cff) writer

View source: R/cff_writer.R

cff_writerR Documentation

Citation File Format (cff) writer

Description

Citation File Format (cff) writer

Usage

cff_writer(
  z,
  path = NULL,
  message = "Please cite the following works when using this software."
)

Arguments

z

an object of class handl; see handl for more

path

a file path or connection; default: stdout()

message

a message to display. Defaults to "Please cite the following works when using this software."

Details

uses yaml::write_yaml to write to yaml format that CFF uses

Value

text if one cff citation or list of many

Converting to CFF from other formats

CFF has required fields that can't be missing. This means that converting from other citation types to CFF will likely require adding the required CFF fields manually. Adding fields to a handl object is easy: it's really just an R list so add named elements to it. The required CFF fields are:

  • CFF v1.1.0:

    • cff-version: add cff_version

    • message: add message

    • version: add software_version

    • title: add title

    • authors: add author

    • date-released: add date_published

  • CFF v1.2.0:

    • Only fields cff-version, message, title and authors are required.

If cff_version is not provided, the value by default is "1.2.0".

References

CFF format: https://github.com/citation-file-format/citation-file-format

See Also

Other writers: bibtex_writer(), citeproc_writer(), codemeta_writer(), rdf_xml_writer(), ris_writer(), schema_org_writer()

Other cff: cff_reader()

Examples

(z <- system.file('extdata/citation.cff', package = "handlr"))
res <- cff_reader(x = z)
res
unclass(res)
cff_writer(res)
cat(cff_writer(res))
f <- tempfile()
cff_writer(res, f)
readLines(f)
unlink(f)

# convert from a different citation format
## see "Converting to CFF from other formats" above
z <- system.file('extdata/citeproc.json', package = "handlr")
w <- citeproc_reader(x = z)
# cff_writer(w) # fails unless we add required fields
w$cff_version <- "1.1.0"
w$software_version <- "2.5"
w$title <- "A cool library"
w$date_published <- "2017-12-18"
cff_writer(w)
cat(cff_writer(w))

ropensci/handlr documentation built on April 26, 2022, 7:37 a.m.