The Rpoet
package is a wrapper of the PoetryDB API, which enables developers and other users to extract a vast amount of English-language poetry from nearly 130 authors (as of this writing). The package provides a simple R interface for interacting and accessing the PoetryDB database. This vignette will introduce the basic functionality of Rpoet
and some example usages of the package.
If not done already, install Rpoet
using install.packages()
function.
The latest development version can also be installed using the devtools function install_github
.
After Rpoet
is installed, load it using the library()
function.
The get.poetry
function acts as the interface to the PoetryDB
API. The only required parameter in the function is the input_term
, which must be one or a combination of the following:
The search_term
parameter should correspond to the given input_term
. For example, if we are interested in finding the poems and sonnets of William Shakespeare, we would use the get.poetry
function like so:
In the case of searching for a particular poem or sonnet:
For users who know of a certain line in a poem and want the full poem:
In the samples given above, all of the data found by the API will be returned. The resulting data returned from the API can be specified by utilizing the output
parameter. Similar to the input_term
parameter, output
can be any one or a combination of ‘author’, ‘title’, ‘lines’ or ‘linecount’. For example, the following would return all of Shakespeare’s poem titles and linecounts rather than the full returned object.
If we only wanted to get the lines of John Milton’s Paradise Lost, the function would look similar to the following:
Multiple input and search terms can be passed in the input_term
and search_term
parameters. Each term passed in the input_term
parameter must be delimited by a comma, while the terms in the search_term
parameter should be delimited by a semi-colon. There must be a corresponding search term for each passed input term. For example, let’s say we want to find the full title name and the line count of John Milton’s poetry with Paradise Lost in the title.
As another example, let’s say we are interested in finding all of William Shakespeare’s poems and sonnets that are fourteen lines long (a sonnet is a poem of 14 equal length lines).