range_text: Find a range of numbers for text

View source: R/NMFSReports.R

range_textR Documentation

Find a range of numbers for text

Description

This function outputs the range of values (broken or continuous) as you would want to display it in text.

Usage

range_text(x, dash = "-", oxford = TRUE, sep = ", ", sep_last = "and ")

Arguments

x

A numeric vector of any length. Any duplicates will be removed.

dash

A string that will go between consecutive values in the string output.

oxford

Default = TRUE. Will only be used if the vector x provided is not continuous. Inherited from NMFSReports::text_list().

sep

Default = ", ". Will only be used if the vector x provided is not continuous. Inherited from NMFSReports::text_list().

sep_last

Default = "and ". Will only be used if the vector x provided is not continuous. Inherited from NMFSReports::text_list().

Value

A string with the range of those values as might be included in a sentence ("1-3, 5, and 7-8").

Examples

# a typical example
x <- c(2003:2005, 2007, 2010:2012)
range_text(x)
# example has duplicate values out of order and specifies for a different dash and no oxford comma
x <- c(1,2,11,3,4,7,NA,8,3)
range_text(x, dash = "--", oxford = FALSE)

EmilyMarkowitz-NOAA/NMFSReports documentation built on March 26, 2023, 1:08 a.m.