Skip to contents

Convert a vector into a comma separated text

Usage

vector2text(vector, sep = ", ", quotes = TRUE, force_single = FALSE, and = "")

v2t(vector, sep = ", ", quotes = TRUE, force_single = FALSE, and = "")

Arguments

vector

Vector. Vector with more than 1 observation.

sep

Character. String text wished to insert between values.

quotes

Boolean. Bring simple quotes for each observation.

force_single

Boolean. Force single quotes by replacing \".

and

Character. Add 'and' or something before last observation. Not boolean variable so it can be used on other languages. Note that the last comma will be suppressed if Sys.getenv("LARES_NUMFORMAT") is set to 1 and you have less than 3 values.

Value

Vector pasting vector values into a single string

Examples

vector2text(LETTERS[1:5])
#> [1] "'A', 'B', 'C', 'D', 'E'"
vector2text(c(1:5), quotes = FALSE)
#> [1] "1, 2, 3, 4, 5"
vector2text(c(1:5), quotes = FALSE, sep = "-")
#> [1] "1-2-3-4-5"
vector2text(c(1:5), and = "and also")
#> [1] "1, 2, 3, 4, and also 5"
vector2text(c("Text", "R's"), force_single = TRUE)
#> [1] "'Text', 'R's'"
# Shorter function with same purpose
v2t(LETTERS[1:5])
#> [1] "'A', 'B', 'C', 'D', 'E'"