extract_tables: extract_tables

Description Usage Arguments Details Value Author(s) References See Also Examples

View source: R/extract_tables.R

Description

Extract tables from a file

Usage

1
2
3
extract_tables(file, pages = NULL, area = NULL, columns = NULL,
  guess = TRUE, spreadsheet = NULL, method = "matrix", password = NULL,
  encoding = NULL, ...)

Arguments

file

A character string specifying the path or URL to a PDF file.

pages

An optional integer vector specifying pages to extract from.

area

An optional list, of length equal to the number of pages specified, where each entry contains a four-element numeric vector of coordinates (top,left,bottom,right) containing the table for the corresponding page. As a convenience, a list of length 1 can be used to extract the same area from all (specified) pages. Only specify area xor columns.

columns

An optional list, of length equal to the number of pages specified, where each entry contains a numeric vector of horizontal (x) coordinates separating columns of data for the corresponding page. As a convenience, a list of length 1 can be used to specify the same columns for all (specified) pages. Only specify area xor columns.

guess

A logical indicating whether to guess the locations of tables on each page. If FALSE, area or columns must be specified; if TRUE, columns is ignored.

spreadsheet

A logical indicating whether to use Tabula's spreadsheet extraction algorithm. If NULL (the default), an automated assessment is made about whether it is appropriate.

method

A function to coerce the Java response object (a Java ArrayList of Tabula Tables) to some output format. The default method, “matrices”, returns a list of character matrices. See Details for other options.

password

Optionally, a character string containing a user password to access a secured PDF.

encoding

Optionally, a character string specifying an encoding for the text, to be passed to the assignment method of Encoding.

...

These are additional arguments passed to the internal functions dispatched by method.

Details

This function mimics the behavior of the Tabula command line utility. It returns a list of R character matrices containing tables extracted from a file by default. This response behavior can be changed by using the following options.

extract_areas implements this functionality in an interactive mode allowing the user to specify extraction areas for each page.

Value

By default, a list of character matrices. This can be changed by specifying an alternative value of method (see Details).

Author(s)

Thomas J. Leeper <[email protected]>

References

Tabula

See Also

extract_areas, get_page_dims, make_thumbnails, split_pdf

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
## Not run: 
# simple demo file
f <- system.file("examples", "data.pdf", package = "tabulizer")

# extract all tables
extract_tables(f)

# extract tables from only second page
extract_tables(f, pages = 2)

# extract areas from a page
## full table
extract_tables(f, pages = 2, area = list(c(126, 149, 212, 462)))
## part of the table
extract_tables(f, pages = 2, area = list(c(126, 284, 174, 417)))

# return data.frames
extract_tables(f, pages = 2, method = "data.frame")

## End(Not run)

Logiwo/tabulizer documentation built on Aug. 18, 2017, 12:08 a.m.