deleteField: Delete all occurrences of a specified field in a bibtex file

Description Usage Arguments Value Note Author(s) Examples

Description

Deletes all occurrences of a specified field in a bibtex file and writes a new processed version in the same directory.

Usage

1
deleteField(filename, fieldname, verbose = FALSE, addCustomField = NULL)

Arguments

filename

string denoting the filename "name.bib"

fieldname

string denoting the bibtex field that should be removed from all entries in the input file. This function might automatically remove non-standard field types as well.

verbose

logical indicating whether in addition to the deletion success indicator (TRUE/FALSE) a vector containing indices of deleted lines and the processed file content is also returned. This is mostly useful for debugging purposes. Defaults to FALSE.

addCustomField

character string/ vector of character strings denoting a custom bibtex field type(s) that should never be automatically removed. This option is not needed for a standard bibtex file.

Value

Returns a logical indicating whether or not the field fieldname was removed from file filename. If it was removed (TRUE), then an output file 'filename_pr.bib' (filename_processed) with the field in question removed is written to disk into the current working directory.

If input argument verbose was set to TRUE, then a list is returned that also contains the indices of deleted lines of the input file, as well as the content of the processed input file.

Note

The underlying parser function does not rely on predefined field names but uses the bibtex syntax elements "," and "{" and "" (empty lines) to infer where a given input field name of interest starts and where it ends, even if it consists of multiple lines and no matter where its position in a bib entry block is situated. That's nice.

An empty last line is appended automatically to the input bib file if it misses such an empty line at its end. A copy of the original file is stored just in case it is needed.

Author(s)

Christoph Schmidt <schmidtchristoph@users.noreply.github.com>

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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# test.bib contains one single-line annotation
filePath <- system.file("testdata/test.bib", package = "bibDelete")
file.copy(filePath, "test.bib")
deleteField("test.bib", "annote")
deleteField("test.bib", "annote", TRUE)
deleteField("test.bib", "month")
deleteField("test.bib", "month", TRUE)
file.remove(c("test.bib", "test_pr.bib"))



filePath <- system.file("testdata/test.bib", package = "bibDelete")
file.copy(filePath, "test.bib")
deleteField("test.bib", "annote") # returns TRUE
deleteField("test_pr.bib", "annote") # returns FALSE

# file 'test_pr_pr.bib' will contain neither 'annote' nor 'month' fields
deleteField("test_pr.bib", "month") # returns TRUE
file.remove(c("test.bib", "test_pr.bib", "test_pr_pr.bib"))



# test2.bib contains multi-line annotations
filePath <- system.file("testdata/test2.bib", package = "bibDelete")
file.copy(filePath, "test2.bib")
deleteField("test2.bib", "annote")
deleteField("test2.bib", "author")
deleteField("test2.bib", "Journal") # FALSE: wrong fieldname
deleteField("test2.bib", "journal") # TRUE: correct fieldname
deleteField("test2.bib", "month")
deleteField("test2_pr.bib", "annote") # month and annote removed
file.remove(c("test2.bib", "test2_pr.bib", "test2_pr_pr.bib"))



# test3.bib contains non-standard fields and non-standard empty lines
filePath <- system.file("testdata/test3.bib", package = "bibDelete")
file.copy(filePath, "test3.bib")
deleteField("test3.bib", "annote")
deleteField("test3.bib", "month")
deleteField("test3_pr.bib", "annote") # month and annote removed
file.remove(c("test3.bib", "test3_pr.bib", "test3_pr_pr.bib"))



# test4.bib contains non-standard annote fields with non-standard field
# delimiters
filePath <- system.file("testdata/test4.bib", package = "bibDelete")
file.copy(filePath, "test4.bib")
deleteField("test4.bib", "annote")
deleteField("test4.bib", "title")
deleteField("test4_pr.bib", "annote") # title and annote removed
file.remove(c("test4.bib", "test4_pr.bib", "test4_pr_pr.bib"))

schmidtchristoph/bibDelete documentation built on May 26, 2019, 4:30 a.m.