Register a document extractor
Arguments
- name
Short name for the extractor.
- extensions
Character vector of file extensions it claims.
- fn
Function of
(path, opts)returning a data frame with columnstext, and optionallypage,section,kind. Pages it could not turn into text can be listed inattr(result, "gr_unread_pages"); an answer drawn from the document is then marked partial, as it is for a PDF page that needed OCR and did not get it.- description
One-line description shown by
gr_extractors().
See also
gr_extractors(), gr_ingest(), gr_register_cleaner()
Other ingest functions:
gr_clean(),
gr_cleaners(),
gr_document,
gr_extractors(),
gr_ingest(),
gr_ingest_spec(),
gr_register_cleaner()
Examples
# A minimal extractor for tab-separated files: one block per row.
gr_register_extractor("tsv", "tsv", description = "TSV, one block per row",
fn = function(path, opts) {
d <- utils::read.delim(path, stringsAsFactors = FALSE)
data.frame(text = apply(d, 1, paste, collapse = " | "), kind = "table")
})
subset(gr_extractors(), name == "tsv")
#> name extensions description needs available
#> tsv tsv tsv TSV, one block per row TRUE