# rOpenSci: The gutenbergr package

output: github_document

gutenbergr: R package to search and download public domain texts from Project Gutenberg

Authors: David Robinson
License: GPL-2

Download and process public domain works from the Project Gutenberg collection. Includes

  • A function gutenberg_download() that downloads one or more works from Project Gutenberg by ID: e.g., gutenberg_download(84) downloads the text of Frankenstein.
  • Metadata for all Project Gutenberg works as R datasets, so that they can be searched and filtered:
    • gutenberg_metadata contains information about each work, pairing Gutenberg ID with title, author, language, etc
    • gutenberg_authors contains information about each author, such as aliases and birth/death year
    • gutenberg_subjects contains pairings of works with Library of Congress subjects and topics

Installation

Install the package with:

install.packages("gutenbergr")

Or install the development version using devtools with:

devtools::install_github("ropensci/gutenbergr")

Examples

The gutenberg_works() function retrieves, by default, a table of metadata for all unique English-language Project Gutenberg works that have text associated with them. (The gutenberg_metadata dataset has all Gutenberg works, unfiltered).

Suppose we wanted to download Emily Bronte’s “Wuthering Heights.” We could find the book’s ID by filtering:

Since we see that it has gutenberg_id 768, we can download it with the gutenberg_download() function:

gutenberg_download can download multiple books when given multiple IDs. It also takes a meta_fields argument that will add variables from the metadata.

It can also take the output of gutenberg_works directly. For example, we could get the text of all Aristotle’s works, each annotated with both gutenberg_id and title, using:

FAQ

What do I do with the text once I have it?

  • The Natural Language Processing CRAN View suggests many R packages related to text mining, especially around the tm package.
  • The tidytext package is useful for tokenization and analysis, especially since gutenbergr downloads books as a data frame already.
  • You could match the wikipedia column in gutenberg_author to Wikipedia content with the WikipediR package or to pageview statistics with the wikipediatrend package.
  • If you’re considering an analysis based on author name, you may find the humaniformat (for extraction of first names) and gender (prediction of gender from first names) packages useful. (Note that humaniformat has a format_reverse function for reversing “Last, First” names).

How were the metadata R files generated?

See the data-raw directory for the scripts that generate these datasets. As of now, these were generated from the Project Gutenberg catalog on 05 May 2016.

Do you respect the rules regarding robot access to Project Gutenberg?

Yes! The package respects these rules and complies to the best of our ability. Namely:

  • Project Gutenberg allows wget to harvest Project Gutenberg using this list of links. The gutenbergr package visits that page once to find the recommended mirror for the user’s location.
  • We retrieve the book text directly from that mirror using links in the same format. For example, Frankenstein (book 84) is retrieved from http://www.gutenberg.lib.md.us/8/84/84.zip.
  • We retrieve the .zip file rather than txt to minimize bandwidth on the mirror.

Still, this package is not the right way to download the entire Project Gutenberg corpus (or all from a particular language). For that, follow their recommendation to use wget or set up a mirror. This package is recommended for downloading a single work, or works for a particular author or topic.

Code of Conduct

This project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.

ropensci_footer