get_bibentries: Get all references from a Bibtex file

Description Usage Arguments Details Value Author(s) References Examples

View source: R/bib.R

Description

Get all references from a Bibtex file.

Usage

1
2
get_bibentries(..., package = NULL, bibfile = "REFERENCES.bib", 
               url_only = FALSE, stop_on_error = TRUE)

Arguments

...

arguments to be passed on to the file getting functions, character strings, see ‘Details’.

package

name of a package, a character string or NULL.

bibfile

name of a Bibtex file, a character string.

url_only

if TRUE, restrict percent escaping to BibTeX field "URL".

stop_on_error

if TRUE stop on error, otherwise issue a warning and return an empty bibentryRd object.

Details

get_bibentries parses the specified file using read.bib from package bibtex \insertCiteRpack:bibtexRdpack and sets its names attribute to the keys of the bib elements (read.bib() does this since version version 0.4.0 of bibtex, as well). Here is what get_bibentries does on top of read.bib (the details are further below):

bibfile should normally be the base name of the Bibtex file. Calling get_bibentries without any "\dots" arguments results in looking for the Bibtex file in the current directory if package is NULL or missing, and in the installation directory of the specified package, otherwise. Argument "..." may be used to specify directories. If package is missing or NULL, the complete path is obtained with file.path(..., bibfile). Otherwise package must be a package name and the file is taken from the installation directory of the package. Again, argument "..." can specify subdirectory as in system.file.

If the current working directory is in the development directory of package, the bib file is first sought there before resorting to the installation directory.

Although the base R packages do not have files REFERENCES.bib, argument package can be set to one of them, e.g. "base". This works since package bibtex provides bib files for the core packages.

By default, get_bibentries escapes unescaped percent signs in all fields of bibtex objects. To restrict this only to field "url", set argument url_only to FALSE.

get_bibentries returns an object from class "bibentryRd", which inherits from bibentry. The printing method for "bibentryRd" unescapes percent signs in URLs for some styles where the escapes are undesirable.

Value

a bibentryRd object inheriting from bibentry

Author(s)

Georgi N. Boshnakov

References

\insertAllCited

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
r <- get_bibentries(package = "Rdpack")
r
print(r, style = "html")

b <- get_bibentries(package = "stats")
print(b[[1]], style = "R")
print(b[[1]], style = "citation")

## here the url field contains percent encoding
fn_url <- system.file("examples", "url_with_percents.bib", package = "Rdpack") 
u <- get_bibentries(bibfile = fn_url)

## the links produced by all of the following are valid
## and can be put in a browser
print(u, style = "html")
print(u, style = "bibtex")
print(u, style = "R")
print(u, style = "text")
print(u, style = "citation")

## The link here contains escapes but when put in a LaTeX document
## which uses the JSS style it generates correct clickable link,
## (see Details section) 
print(u, style = "latex")

## here the journal field contains percent encoding
fn_other <- system.file("examples", "journal_with_percents.bib", package = "Rdpack") 
j <- get_bibentries(bibfile = fn_url)
print(j, style = "html")
print(j, style = "bibtex")
print(j, style = "R")
print(j, style = "text")
print(j, style = "citation")
      
print(j, style = "latex")

GeoBosh/Rdpack documentation built on Oct. 29, 2018, 8:22 p.m.