Export R objects representing citations to specific file types:
cff_write_bib()
creates a.bib
file.cff_write_citation()
creates a R citation file as explained in Section 1.9 CITATION files of Writing R Extensions (R Core Team 2023).
Arguments
- x
- file
Name of the file to be created. If
NULL
it would display the lines to be written.- append
Whether to append the entries to an existing file or not.
- verbose
Display informative messages
- ascii
Whether to write the entries using ASCII characters only or not.
- ...
Arguments passed on to
as_bibentry.cff
,as_bibentry.cff_ref
,as_bibentry.cff_ref_lst
what
Fields to extract from a full
cff
object. The value could be:preferred
: This would create a single entry with the main citation info of the package (keypreferred-citation
).references
: Extract all the entries ofreferences
key.all
: A combination of the previous two options. This would extract both thepreferred-citation
and thereferences
key.
Details
When x
is a cff
object it would be converted to Bibtex
using
toBibtex.cff()
.
For security reasons, if the file already exists the function would create a backup copy on the same directory.
References
R Core Team (2023). Writing R Extensions. https://cran.r-project.org/doc/manuals/r-release/R-exts.html
See also
vignette("bibtex_cff", "cffr")
, knitr::write_bib()
and the
following packages:
Other functions for working with BibTeX format:
as_bibentry()
,
cff_read()
,
cff_read_bib_text()
,
encoded_utf_to_latex()
Other functions for creating external files:
cff_write()
Examples
bib <- bibentry("Misc",
title = "My title",
author = "Fran Pérez"
)
my_temp_bib <- tempfile(fileext = ".bib")
cff_write_bib(bib, file = my_temp_bib)
#> ℹ Writing 4 entries ...
#> ✔ Results written to /tmp/RtmpPM4N6J/filea22319d7ca1.bib
cat(readLines(my_temp_bib), sep = "\n")
#> @Misc{,
#> title = {My title},
#> author = {Fran Pérez},
#> }
cff_write_bib(bib, file = my_temp_bib, ascii = TRUE, append = TRUE)
#> ℹ Creating a backup of /tmp/RtmpPM4N6J/filea22319d7ca1.bib in /tmp/RtmpPM4N6J/filea22319d7ca1.bib.bk1
#> ℹ Writing 4 entries ...
#> ✔ Results written to /tmp/RtmpPM4N6J/filea22319d7ca1.bib
cat(readLines(my_temp_bib), sep = "\n")
#> @Misc{,
#> title = {My title},
#> author = {Fran Pérez},
#> }
#> @Misc{,
#> title = {My title},
#> author = {Fran P{\'e}rez},
#> }
# Create a CITATION file
# Use a system file
f <- system.file("examples/preferred-citation-book.cff", package = "cffr")
a_cff <- cff_read(f)
out <- file.path(tempdir(), "CITATION")
cff_write_citation(a_cff, file = out)
#> ℹ Writing 2 entries ...
#> ✔ Results written to /tmp/RtmpPM4N6J/CITATION
# Check by reading, use meta object
meta <- packageDescription("cffr")
meta$Encoding <- "UTF-8"
utils::readCitationFile(out, meta)
#> To cite package ‘cffr’ in publications use:
#>
#> Bueler E (2021). _PETSc for Partial Differential Equations: Numerical
#> Solutions in C and Python_. SIAM Press, Philadelphia. ISBN
#> 978111976304, <https://github.com/bueler/p4pdes>.
#>
#> A BibTeX entry for LaTeX users is
#>
#> @Book{bueler:2021,
#> title = {PETSc for Partial Differential Equations: Numerical Solutions in C and Python},
#> author = {Ed Bueler},
#> year = {2021},
#> publisher = {SIAM Press},
#> address = {Philadelphia},
#> isbn = {978111976304},
#> url = {https://github.com/bueler/p4pdes},
#> }