Skip to content

Commit 5cfc10c

Browse files
committed
Add kjv_bible standalone function
1 parent bf0cb39 commit 5cfc10c

File tree

5 files changed

+157
-2
lines changed

5 files changed

+157
-2
lines changed

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
# Generated by roxygen2: do not edit by hand
22

3+
export(kjv_bible)
34
export(lds_scriptures)

R/kjv_bible.R

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#' Tidy data frame of the King James Version of the Bible
2+
#'
3+
#' Returns a tidy data frame of the King James Version of the Bible, with one
4+
#' verse for every row. There are several columns, including: \code{text}, which
5+
#' contains the text of each verse, \code{book_title}, the book of scripture,
6+
#' \code{chapter_number}, the chapter, and \code{verse_number}, the verse
7+
#' number. There are a dozen other columns as well: see "Details" for complete
8+
#' descriptions.
9+
#'
10+
#' Importantly, none of the title columns are ordered factors. It is the
11+
#' responsibility of the user to create ordered factors of book and volume
12+
#' titles when plotting results.
13+
#'
14+
#' @details Every row in the dataset is a verse, and there are 19 columns of
15+
#' metadata:
16+
#' \describe{
17+
#' \item{\code{volume_id}}{Unique id number for the volume (1 = Old Testament, 2 = New Testament, etc.)}
18+
#' \item{\code{book_id}}{Unique id number for the book (1 = Genesis, 2 = Exodus, etc.)}
19+
#' \item{\code{chapter_id}}{Unique id number for the chapter (50 = Genesis 50, 51 = Exodus 1, etc.)}
20+
#' \item{\code{verse_id}}{Unique id number for the verse (31 = Genesis 1:31, 32 = Genesis 2:1)}
21+
#' \item{\code{volume_title}}{Name of the volume}
22+
#' \item{\code{book_title}}{Name of the book}
23+
#' \item{\code{volume_long_title}}{Full name of the volume}
24+
#' \item{\code{book_long_title}}{Full name of the book}
25+
#' \item{\code{volume_subtitle}}{Subtitle of the volume}
26+
#' \item{\code{book_subtitle}}{Subtitle of the book}
27+
#' \item{\code{volume_short_title}}{Volume abbreviation}
28+
#' \item{\code{book_short_title}}{Book abbreviation}
29+
#' \item{\code{volume_lds_url}}{Volume abbreviation used at scriptures.lds.org}
30+
#' \item{\code{book_lds_url}}{Book abbreviation used at scriptures.lds.org}
31+
#' \item{\code{chapter_number}}{Chapter (not unique; Genesis 50 = 50, Exodus 1 = 1, etc.)}
32+
#' \item{\code{verse_number}}{Verse (not unique; Genesis 1:31 = 31, Genesis 2:1 = 1)}
33+
#' \item{\code{text}}{Scripture text}
34+
#' \item{\code{verse_title}}{Combined book, chapter, and verse (e.g. Genesis 1:1)}
35+
#' \item{\code{verse_short_title}}{Abbreviated combined book, chapter, and verse (e.g. Gen. 1:1)}
36+
#' }
37+
#'
38+
#' @return A data frame with 31102 rows and 19 columns
39+
#'
40+
#' @name kjv_bible
41+
#'
42+
#' @examples
43+
#' library(dplyr)
44+
#'
45+
#' kjv_bible() %>%
46+
#' group_by(volume_title, book_title) %>%
47+
#' summarise(total_verses = n())
48+
#'
49+
#' @export
50+
kjv_bible <- function() {
51+
ret <- rbind(scriptuRs::old_testament,
52+
scriptuRs::new_testament)
53+
54+
structure(ret, class = c("tbl_df", "tbl", "data.frame"))
55+
}

README.md

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ This package provides access to the full text of the Standard Works for The Chur
1010
- `doctrine_and_covenants`: The Doctrine and Covenants
1111
- `pearl_of_great_price`: The Pearl of Great Price
1212

13-
There is also a function `lds_scriptures()` that returns a tidy data frame of all 5 volumes of scripture.
13+
There is also a function `lds_scriptures()` that returns a tidy data frame of all 5 volumes of scripture, as well as a `kjv_bible()` function that returns a tidy data frame of just the Old and New Testaments.
1414

1515
Unlike other packages like [**janeaustenr**](https://github.com/juliasilge/janeaustenr), this package does not provide ordered factors for book or volume names. It is up to the user to put books and/or volumes in the needed order when analyzing or plotting the data.
1616

@@ -38,7 +38,7 @@ scriptures <- lds_scriptures()
3838

3939
scriptures %>%
4040
group_by(volume_title, book_title) %>%
41-
summarise(total_verses = n())
41+
summarize(total_verses = n())
4242
#> # A tibble: 87 x 3
4343
#> # Groups: volume_title [?]
4444
#> volume_title book_title total_verses
@@ -56,6 +56,30 @@ scriptures %>%
5656
#> # ... with 77 more rows
5757
```
5858

59+
And here's how to use `kvj_bible()`:
60+
61+
```r
62+
bible <- kjv_bible()
63+
64+
bible %>%
65+
group_by(volume_title, book_title) %>%
66+
summarize(total_verses = n())
67+
#> # A tibble: 66 x 3
68+
#> # Groups: volume_title [?]
69+
#> volume_title book_title total_verses
70+
#> <chr> <chr> <int>
71+
#> 1 New Testament 1 Corinthians 437
72+
#> 2 New Testament 1 John 105
73+
#> 3 New Testament 1 Peter 105
74+
#> 4 New Testament 1 Thessalonians 89
75+
#> 5 New Testament 1 Timothy 113
76+
#> 6 New Testament 2 Corinthians 257
77+
#> 7 New Testament 2 John 13
78+
#> 8 New Testament 2 Peter 61
79+
#> 9 New Testament 2 Thessalonians 47
80+
#> 10 New Testament 2 Timothy 83
81+
#> # ... with 56 more rows
82+
```
5983

6084
## Code of Conduct
6185

man/kjv_bible.Rd

Lines changed: 56 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/test_kjv_bible.R

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# tests for kjv_bible function
2+
3+
context("Tidy dataframe with King James bible")
4+
5+
suppressPackageStartupMessages(library(dplyr))
6+
7+
test_that("tidy frame for KJV bible is right", {
8+
# Does this have the right number of lines?
9+
bible <- kjv_bible()
10+
expect_equal(nrow(bible), 31102)
11+
expect_equal(ncol(bible), 19)
12+
13+
# Are the lines spread across each volume correctly?
14+
bible_test <- bible %>%
15+
group_by(volume_title) %>%
16+
summarise(total_verses = n())
17+
expect_equal(nrow(bible_test), 2)
18+
expect_equal(ncol(bible_test), 2)
19+
})

0 commit comments

Comments
 (0)