Skip to contents
  • find_ref_to_df() finds the references in PDF or text documents (find_ref()), then parses them.

  • parse_ref_to_df() parses references you already have, one per element of a character vector or one per line of text files (parse_ref()).

Both return one row per reference, with the reference as printed (full_ref) and the fields found by anystyle, cleaned by clean_ref() unless clean = FALSE.

Usage

find_ref_to_df(
  input,
  layout = TRUE,
  solo = FALSE,
  clean = TRUE,
  finder_model = NULL,
  parser_model = NULL
)

parse_ref_to_df(
  input,
  doc = NULL,
  split = FALSE,
  clean = TRUE,
  parser_model = NULL
)

Arguments

input

For find_ref_to_df(), paths of PDF or text documents. For parse_ref_to_df(), a character vector of references, or paths of text files with one reference per line.

layout

Logical. If TRUE (the default), the text of PDFs is extracted with its layout (pdftotext -layout). Set it to FALSE for documents in several columns, whose lines are otherwise interleaved.

solo

Logical. If TRUE, anystyle also returns references found outside reference sections (e.g. in footnotes). Default FALSE.

clean

Logical. If TRUE (the default), the data frame is cleaned with clean_ref(). If FALSE, the raw anystyle fields are returned (see Value).

finder_model, parser_model

Paths to custom anystyle models (.mod files created with anystyle train), or NULL for the models shipped with anystyle.

doc

For parse_ref_to_df() with a vector of references: an optional vector of the same length giving the document each reference comes from (e.g. the identifier of the citing article). References are numbered within documents, and the cleaning rules that use neighbouring references (ditto marks) stay within a document. Ignored for files (the document is the file).

split

Logical. If TRUE, each element of input (or each text file) is a block of text holding a whole bibliography without line breaks, which split_ref() cuts into references first. Default FALSE.

Value

A tibble with one row per reference and the columns:

  • id_doc (integer), doc (file name, or doc), ref_order (position in the document), id_ref ("<id_doc>_<ref_order>"), full_ref (the reference as given to anystyle);

  • with clean = TRUE, the cleaned fields documented in clean_ref();

  • with clean = FALSE, type and one list-column per field found by anystyle (CSL names, e.g. container-title): name fields (author, editor...) hold a tibble of name parts, other fields a character vector (anystyle may find several titles or dates in one reference).

Details

[Experimental]

All the references of a call are parsed in one run of anystyle, which is much faster than one run per document (starting anystyle takes about half a second; parsing takes a few milliseconds per reference). Because anystyle resolves ditto marks ("———", "—–") with the authors of the previous line, a ditto mark opening a document would inherit the authors of the previous document: its authors are removed (and the reference flagged by clean_ref()).

See also

clean_ref() for the cleaning rules.

Examples

if (FALSE) { # \dontrun{
pdfs <- system.file("extdata", c("example_doc_1.pdf", "example_doc_2.pdf"),
  package = "anystyleR")
refs <- find_ref_to_df(pdfs)

parse_ref_to_df(c(
  "Barro, R. J. (1983). Rules, discretion and reputation. J. Monet. Econ., 12, 101-121.",
  "Friedman, M. (1968). The role of monetary policy. American Economic Review, 58(1), 1-17."
))
} # }