Learn R Programming

rbibutils (version 2.4.1)

readBibentry: Read and write bibentry files or read bibtex strings

Description

Read and write bibentry files.

Usage

readBibentry(file, extra = FALSE, fbibentry = NULL)

writeBibentry(be, file = stdout(), style = c("Rstyle", "loose"))

Value

for writeBibentry, NULL (invisibly)

for readBibentry, a bibentry object with the keys as names

Arguments

be

a bibentry object.

file

filename, a character string or a connection. For readBibentry, input from the console can be specified by file = "". The default for writeBibentry is stdout (effectively, to write on the screen).

extra

if TRUE allow non-standard bibtex types.

style

if "Rstyle" (default), wrap in c(), otherwise don't wrap and don't put commas between the entries, see section “Details”.

fbibentry

a function to use for generating bib objects. The default is utils::bibentry().

Author

Georgi N. Boshnakov

Details

These functions read/write bibentry objects from/to R source files. Two styles are supported. "Rstyle" is the format used by print(be, style = "R"), which writes the bibentry calls as a comma separated sequence wrapped in c() (i.e., the file contains a single R expression). Style "loose" writes the entries without separators and no wrapping.

writeBibentry writes the object to the specified file in the requested style (default is "Rstyle"). The file is neatly formatted for humans to read and edit.

readBibentry reads the file and creates a bibentry object. It doesn't have argument for style, since that is inferred from the contents of the file.

bibentry() calls that throw errors are not included in the returned object. The errors are intercepted and converted to warnings, identifying the corresponding bibentry() calls by their keys, if present (otherwise the text of the whole bibentry is shown).

See Also

readBib and writeBib for reading/writing bib files,

bibConvert

charToBib for reading from a character vector

Examples

Run this code
bibs <- readBib(system.file("REFERENCES.bib", package = "rbibutils"),
                encoding = "UTF-8")
fn <- tempfile(fileext = ".bib")

writeBibentry(bibs, file = fn) # style = "Rstyle" (default)
cat(readLines(fn), sep = "\n")

writeBibentry(bibs, file = fn, style = "loose")
cat(readLines(fn), sep = "\n")

unlink(fn)

Run the code above in your browser using DataLab