word_count: Word Count a PDF

Description Usage Arguments Details Value Author(s) Examples

View source: R/word_count.R

Description

Obtain a Word Count from a PDF

Usage

1
2
3
4
word_count(document, pages = NULL, count_numbers = TRUE,
  count_captions = FALSE, count_equations = FALSE,
  split_hyphenated = FALSE, split_urls = FALSE,
  verbose = getOption("verbose", FALSE))

Arguments

document

A file path specifying a PDF document.

pages

Optionally, an integer vector specifying a subset of pages to count from. Negative values serve as negative subsets.

count_numbers

A logical specifying whether to count numbers as words.

count_captions

A logical specifying whether to count lines beginning with “Table” or “Figure” in word count.

count_equations

A logical specifying whether to count lines ending with “([Number])” in word count.

split_hyphenated

A logical specifying whether to split hyphenated words or expressions as separate words.

split_urls

A logical specifying whether to split URLs into multiple words when counting.

verbose

A logical specifying whether to be verbose. If TRUE, the page and word counts are printed to the console and the result is is returned invisibly. If FALSE, the result is visible.

Details

This is useful for obtaining a word count for a LaTeX-compiled PDF. Counting words in the tex source is a likely undercount (due to missing citations, cross-references, and parenthetical citations). Counting words from the PDF is likely over count (due to hyphenation issues, URLs, ligatures, tables and figures, and various other things). This function tries to obtain a word from the PDF while accounting for some of the sources of overcounting.

It is often desirable to have word counts excluding tables and figures. A solution on TeX StackExchange (https://tex.stackexchange.com/a/352394/30039) provides guidance on how to exclude tables and figures (or any arbitrary LaTeX environment) from a compiled document, which may be useful before attempting to word count the PDF.

Value

A data frame with two columns, one specifying page and the other specifying word count for that page.

Author(s)

Thomas J. Leeper <thosjleeper@gmail.com>

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
## Not run: 
# "R-intro.pdf" manual
rintro <- file.path(Sys.getenv("R_HOME"), "doc", "manual", "R-intro.pdf")

# Online service at http://www.montereylanguages.com/pdf-word-count-online-free-tool.html
# claims the word count to be 36,530 words

# Microsoft Word (PDF conversion) word count is 36,869 words

word_count(rintro)      # all pages (105 pages, 37870 words)
word_count(rintro, 1:3) # pages 1-3
word_count(rintro, -1)  # skip first page

## End(Not run)

leeper/pdfcount documentation built on May 6, 2019, 11:44 a.m.