get_and_or_list: Returns a one element character string with correct...

View source: R/get_and_or_list.R

get_and_or_listR Documentation

Returns a one element character string with correct punctuation for a list made up of the elements of the character vector argument.

Description

Returns a one element character string with correct punctuation for a list made up of the elements of the character vector argument.

Usage

get_and_or_list(c_vector, conjunction = "and", punct = TRUE)

Arguments

c_vector

Character vector containing the list of words to be put in a list.

conjunction

The conjunction to be used as the connector. This is usually ‘and’ or ‘or’ with ‘and’ being the default.

punct

logical varialble when TRUE results in a comma "," being place before the conjunction and when FALSE no punctuation is inserted when the list has three or more elements. Defualt value is TRUE.

Value

a character vector of length one containing the a single correctly punctuated character string that list each element in the first arguments vector with commas between if there are more than two elements with the last two elements joined by the selected conjunction. A comma, ",", preceeds the conjuction unless the punct parameter is set to FALSE.

Examples


get_and_or_list(c("Bob", "John")) # "Bob and John"
get_and_or_list(c("Bob", "John"), "or") # "Bob or John"
get_and_or_list(c("Bob", "John", "Sam", "Bill"), "or")
# "Bob, John, Sam, or Bill"
get_and_or_list(c("Bob", "John", "Sam", "Bill"), punct = FALSE)
# "Bob, John, Sam and Bill"



rmsharp/rmsutilityr documentation built on Feb. 13, 2024, 6:01 p.m.