str_comma: Collapse a vector of character strings into one readable...

View source: R/str_comma.R

str_commaR Documentation

Collapse a vector of character strings into one readable string, separated by commas and by "and"

Description

str_comma combines multiple character strings into one and makes them more readable by separating those strings with commas and "and" as appropriate. The place I had in mind for using this is in RMarkdown documents where you want to insert a comment in the text that calls on a character vector. For example, say you want to note in a text chunk which subjects in a study have some measurement that is two standard deviations above the mean. Rather than using only, e.g., stringr::str_c(StudyOutliers, collapse = ", "), you could have it include the "and" in the appropriate location and make your final document more polished, readable, and professional.

Usage

str_comma(x, oxford = TRUE)

Arguments

x

values to be concatenated

oxford

TRUE or FALSE for whether to use the Oxford comma

Value

Returns a single, collapsed character string

Examples

str_comma(LETTERS[1:2])
str_comma(LETTERS[1:4])
str_comma(LETTERS[1:4], oxford = FALSE)



shirewoman2/LaurasHelpers documentation built on Oct. 22, 2023, 2:07 p.m.