21.6 Word Documents

A simple open source tool to convert Microsoft Word documents into text is antiword. The separate antiword application needs to be installed, but once it is available it is used by to convert Word documents into text for loading into R.

To load a corpus of Word documents we use the tm::readDOC() reader function:

docs <- Corpus(DirSource(cname), readerControl=list(reader=readDOC))

Once we have loaded our corpus the remainder of the processing of the corpus within R is then as follows.

The antiword program takes some useful command line arguments. We can pass these through to the program from tm::readDOC() by specifying them as the character string argument:

docs <- Corpus(DirSource(cname), readerControl=list(reader=readDOC("-r -s")))

Here, -r requests that removed text be included in the output, and -s requests that text hidden by Word be included.



Your donation will support ongoing availability and give you access to the PDF version of this book. Desktop Survival Guides include Data Science, GNU/Linux, and MLHub. Books available on Amazon include Data Mining with Rattle and Essentials of Data Science. Popular open source software includes rattle, wajig, and mlhub. Hosted by Togaware, a pioneer of free and open source software since 1984. Copyright © 1995-2022 Graham.Williams@togaware.com Creative Commons Attribution-ShareAlike 4.0