bib2bib: Load .bib, Process .bib and Output .bib File.

View source: R/bib2bib.R

bib2bibR Documentation

Load .bib, Process .bib and Output .bib File.

Description

The bib2bib function reads a BibTeX file, replaces the journal field using a custom or system-provided abbreviation table, optionally applies a function to the author field, and writes the result back to a new BibTeX file.

Usage

bib2bib(
  file,
  out.file,
  user_table = NULL,
  use_sys_table = TRUE,
  fun = NULL,
  ...
)

Arguments

file

A string representing the path to the input .bib file to be processed.

out.file

A string representing the path where the output .bib file should be saved.

user_table

A user-provided abbreviation table. It can be a file path (string), a data.frame, or a data.table. The table must contain columns journal_lower and journal_abbr. Default is NULL.

use_sys_table

Logical. Whether to include the system abbreviation table (abbrtable_sys) in the merged result. Default is TRUE.

fun

A function (optional) to apply to the "author" field in the .bib file. If provided, this function will be applied to the "author" field

...

Additional arguments passed to the custom function fun, if provided.

Details

The function works in the following steps:

  1. Reads a custom journal abbreviation table from a CSV file (if provided).

  2. Reads the input BibTeX file and converts it into a data.table.

  3. Replaces the JOURNAL field with abbreviations from the provided or system abbreviation table.

  4. Optionally applies the provided function to the AUTHOR field.

  5. Writes the modified data back to a new BibTeX file.

Value

None. The function writes the processed data to the specified output file.

Examples

bib_file <- system.file("extdata", "testfile_2.bib", package = "journalabbr", mustWork = TRUE)
csv_file <- system.file("extdata", "myabbr.csv", package = "journalabbr", mustWork = TRUE)
output_file <- tempfile(fileext = ".bib")

dt <- bib2bib(file = bib_file,
        out.file = output_file,
        user_table = csv_file,
        use_sys_table = TRUE,
        fun = function(x) {
          gsub(" and ", " & ", x, perl = TRUE, ignore.case = TRUE)
        })

zoushucai/journalabbr documentation built on Dec. 6, 2024, 4:41 p.m.