jst_get_total_pages: Calculate total pages

Description Usage Arguments Details Value Examples

View source: R/augmentations.R

Description

This function is a simple helper to calculate the total number of pages of an article.

Usage

1
jst_get_total_pages(first_page, last_page, page_range, quietly = FALSE)

Arguments

first_page

The first page of an article (numeric).

last_page

The last page of an article (numeric).

page_range

The page range of an article (character).

quietly

Sometimes page ranges contain roman numerals like xiv. These are not recognized, return NA and raise a warning. If set to TRUE, this warning not raised.

Details

This function deals with four cases:

The algorithm to parse page ranges works as follows: A typical page range is 1-10, 200 where the article starts at page 1, ends at page 10, and has an erratum at page 200. For this case, the range is calculated as range + single_page, as in(10 - 1 + 1) + 1 = 11. Sometimes multiple ranges are given: 1-10, 11-20. For those cases all ranges are summed: (10 - 1 + 1) + (20 - 11 + 1) = 20. Another specification for multiple ranges is 1-10+11-20, which is treated similarly.

Value

A vector with the calculated total pages.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
# calculate pages from first and last page
first_pages <- sample(30:50, 10)
last_pages <- first_pages + sample(5:20, 10)
page_ranges <- rep(NA_character_, 10)

jst_get_total_pages(first_pages, last_pages, page_ranges)

# get pages from page range
jst_get_total_pages(NA_real_, NA_real_, "51 - 70")
jst_get_total_pages(NA_real_, NA_real_, "51 - 70, 350")
jst_get_total_pages(NA_real_, NA_real_, "350, 51 - 70")
jst_get_total_pages(NA_real_, NA_real_, "51 - 70, 80-100")
jst_get_total_pages(NA_real_, NA_real_, "51-70+350")

jstor documentation built on Dec. 11, 2021, 9:56 a.m.