PDE_pdfs2table_searchandfilter: Extracting tables from a PDF (Portable Document Format) file

Description Usage Arguments Value See Also Examples

View source: R/PDE.R

Description

PDE_pdfs2table_searchandfilter extracts tables from a single PDF file according to filter and search words and writes output in the corresponding folder.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
PDE_pdfs2table_searchandfilter(
  pdfs,
  out = ".",
  filter.words = "",
  ignore.case.fw = FALSE,
  filter.word.times = 20,
  table.heading.words = "",
  ignore.case.th = FALSE,
  search.words,
  ignore.case.sw = FALSE,
  eval.abbrevs = TRUE,
  out.table.format = ".csv (WINDOWS-1252)",
  dev = 20,
  write.table.locations = FALSE,
  exp.nondetc.tabs = FALSE,
  write.tab.doc.file = FALSE,
  delete = TRUE,
  verbose = TRUE
)

Arguments

pdfs

String. A list of paths to the PDF files to be analyzed.

out

String. Directory chosen to save analysis results in. Default: ".".

filter.words

List of strings. The list of filter words. If not NA or "" a hit will be counted every time a word from the list is detected in the article. Regex rules apply (see also https://rstudio.com/wp-content/uploads/2016/09/RegExCheatsheet.pdf). Default: "".

ignore.case.fw

Logical. Are the filter words case-sensitive (does capitalization matter)? Default: FALSE.

filter.word.times

Numeric. The minimum number of hits described for filter.words for a paper to be further analyzed. Default: 20.

table.heading.words

List of strings. Different than standard (TABLE, TAB or table plus number) headings to be detected. Regex rules apply (see also https://rstudio.com/wp-content/uploads/2016/09/RegExCheatsheet.pdf). Default = "".

ignore.case.th

Logical. Are the additional table headings (see table.heading.words) case-sensitive (does capitalization matter)? Default = FALSE.

search.words

List of strings. List of search words. To extract all tables from the PDF file leave search.words = "". Regex rules apply (see also https://rstudio.com/wp-content/uploads/2016/09/RegExCheatsheet.pdf).

ignore.case.sw

Logical. Are the search words case-sensitive (does capitalization matter)? Default: FALSE.

eval.abbrevs

Logical. Should abbreviations for the search words be automatically detected and then replaced with the search word + "$*"? Default: TRUE.

out.table.format

String. Output file format. Either comma separated file .csv or tab separated file .tsv. The encoding indicated in parantheses should be selected according to the operational system exported tables are opened in, i.e., Windows: "(WINDOWS-1252)"; Mac: (macintosh); Linux: (UTF-8). Default: ".csv" and encoding depending on the operational system.

dev

Numeric. For a table the size of indention which would be considered the same column. Default: 20.

write.table.locations

Logical. If TRUE, a separate file with the headings of all tables, their relative location in the generated html and txt files, as well as information if search words were found will be generated. Default: FALSE.

exp.nondetc.tabs

Logical. If TRUE, if a table was detected in a PDF file but is an image or cannot be read, the page with the table with be exported as a png. Default: FALSE.

write.tab.doc.file

Logical. If TRUE, if search words are used for table detection and no search words were found in the tables of a PDF file, a no.table.w.search.words. Default: FALSE.

delete

Logical. If TRUE, the intermediate txt, keeplayouttxt and html copies of the PDF file will be deleted. Default: TRUE.

verbose

Logical. Indicates whether messages will be printed in the console. Default: TRUE.

Value

If tables were extracted from the PDF file the function returns a list of following tables/items: 1) htmltablelines, 2) txttablelines, 3) keeplayouttxttablelines, 4) id, 5) out_msg. The tablelines are tables that provide the heading and position of the detected tables. The id provide the name of the PDF file. The out_msg includes all messages printed to the console or the suppressed messages if verbose=FALSE.

See Also

PDE_extr_data_from_pdfs, PDE_pdfs2table

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
## Running a simple analysis with filter and search words to extract tables
if(PDE_check_Xpdf_install() == TRUE){
 outputtables <- PDE_pdfs2table_searchandfilter(pdf = paste0(PDE_path(),
                                   "examples/Methotrexate/29973177_!.pdf"),
 out = paste0(PDE_path(),"examples/29973177_tables/"),
 filter.words = strsplit("cohort;case-control;group;study population;study participants", ";")[[1]],
 ignore.case.fw = TRUE,
 search.words = strsplit("(M|m)ethotrexate;(T|t)rexal;(R|r)heumatrex;(O|o)trexup", ";")[[1]],
 ignore.case.sw = FALSE)
}

## Running an advanced analysis with filter and search words to
## extract tables and obtain documentation files
if(PDE_check_Xpdf_install() == TRUE){
 outputtables <- PDE_pdfs2table_searchandfilter(pdf = paste0(PDE_path(),
                                   "examples/Methotrexate/29973177_!.pdf"),
 out = paste0(PDE_path(),"examples/29973177_tables/"),
 dev = 20,
 filter.words = strsplit("cohort;case-control;group;study population;study participants", ";")[[1]],
 ignore.case.fw = TRUE,
 filter.word.times = 20,
 table.heading.words = "",
 ignore.case.th = FALSE,
 search.words = strsplit("(M|m)ethotrexate;(T|t)rexal;(R|r)heumatrex;(O|o)trexup", ";")[[1]],
 ignore.case.sw = FALSE,
 eval.abbrevs = TRUE,
 out.table.format = ".csv (WINDOWS-1252)",
 write.table.locations = TRUE,
 write.tab.doc.file = TRUE,
 exp.nondetc.tabs = TRUE,
 delete = TRUE)
}

erikstricker/PDE documentation built on Jan. 1, 2021, 1:08 a.m.