read_bib: Read Bib file

View source: R/bib.R

read_bibR Documentation

Read Bib file

Description

Read a bib file into a data.frame

Usage

read_bib(file, skip = 0L, max_lines = NULL, encoding = "UTF-8")

Arguments

file

File or connection

skip

The lines to skip

max_lines

The maximum number of lines to read

encoding

Assumed encoding of file (passed to readLines()

Details

Inspired and partially credited to bib2df::bib2df() although this has no dependencies outside of base functions and much quicker. This speed seems to come from removing stringr functions and simplifying a few *apply functions. This will also include as many categories as possible from the entry.

Value

A data.frame with each row as a bib entry and each column as a field

See Also

?bib2df::bib2df

Examples

file <- "https://raw.githubusercontent.com/jmbarbone/bib-references/master/references.bib"
bibdf <- read_bib(file, max_lines = 51L)

if (package_available("tibble")) {
  tibble::as_tibble(bibdf)
} else {
  head(bibdf)
}

if (package_available("bib2df") & package_available("bench")) {
  file <- system.file("extdata", "bib2df_testfile_3.bib", package = "bib2df")

  # Doesn't include the 'tidying' up
  foo <- function(file) {
    bib <- ("bib2df" %colons% "bib2df_read")(file)
    ("bib2df" %colons% "bib2df_gather")(bib)
  }


  bench::mark(
    read_bib = read_bib(file),
    bib2df = bib2df::bib2df(file),
    foo = foo(file),
    check = FALSE
  )[1:9]

}

jmbarbone/jordan documentation built on April 1, 2024, 7:46 p.m.