cff_write_bib {cffr}R Documentation

Export R objects to different file types

Description

Export R objects representing citations to specific file types:

Usage

cff_write_bib(
  x,
  file = tempfile(fileext = ".bib"),
  append = FALSE,
  verbose = TRUE,
  ascii = FALSE,
  ...
)

cff_write_citation(
  x,
  file = tempfile("CITATION_"),
  append = FALSE,
  verbose = TRUE,
  ...
)

Arguments

x

A bibentry or a cff object.

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 (key preferred-citation).

  • references: Extract all the entries of references key.

  • all: A combination of the previous two options. This would extract both the preferred-citation and the references key.

See vignette("crosswalk", package = "cffr").

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.

Value

Writes the corresponding file specified on the file parameter.

References

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)

cat(readLines(my_temp_bib), sep = "\n")

cff_write_bib(bib, file = my_temp_bib, ascii = TRUE, append = TRUE)

cat(readLines(my_temp_bib), sep = "\n")

# 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)

# Check by reading, use meta object
meta <- packageDescription("cffr")
meta$Encoding <- "UTF-8"

utils::readCitationFile(out, meta)

[Package cffr version 1.1.0 Index]