count_words() takes a path to a .Rmd file and returns a word count
of its prose.
It does not count the YAML front matter, code chunks, inline R code,
or HTML comments.
count_words2() takes a path to a rendered PDF file and returns
a word count of all of the text in the PDF.
Usage
count_words(file)
count_words2(file)
Arguments
- file
A path to a .Rmd file (for count_words()) or to a .pdf file
(for count_words2()).
If missing and in RStudio, the file open in the source editor is used.
For count_words2(), the PDF with the same name as that file is used.
Value
A scalar representing the number of words in the document.
Details
A word is a sequence of letters, digits or underscores.
Apostrophes, periods and colons inside a word do not split the word,
so "don't", "e.g." and "3.14" are each one word.
Hyphens split words, so "long-form" is two words.
count_words2() needs the {pdftools} package.
Examples
rmarkdown::draft(file = "test", template = "html_vignette",
package = "rmarkdown", create_dir = TRUE, edit = FALSE)
iheiddown::count_words("test/test.Rmd")
#> [1] 220
unlink("test", recursive = TRUE)