Skip to contents

stm_vector_to_char() takes a vector and converts it into a character string. Optionally, if is_stop is TRUE, it checks if the specified character is in the vector and raises an error if not.

Usage

stm_vector_to_char(vec, find_char, is_stop = FALSE, par_name = "vec")

Arguments

vec

A vector of values to be converted to a character string. The vector is assumed to contain non-numeric values.

find_char

A character to check against the vector. If is_stop is TRUE, the function will stop if find_char is not in vec.

is_stop

A logical value. If TRUE, an error is raised if the find_char is not found in vec.

par_name

A string used in error and warning messages to refer to the parameter. Defaults to "vec".

Value

The function returns the vector as a single concatenated character string, or stops if is_stop is TRUE and the character is not found in the vector.

Details

The function first checks whether the input vector is valid and then concatenates it into a single string. If is_stop is TRUE, the function checks whether find_char is in the vector and stops execution if it is not.

Examples

fruits <- c("apple", "banana", "cherry")
print(fruits)
#> [1] "apple"  "banana" "cherry"
stm_vector_to_char(fruits, find_char = "apple")
#> [1] "apple', 'banana', 'cherry"
colors <- c("red", "blue", "green")
print(colors)
#> [1] "red"   "blue"  "green"
stm_vector_to_char(colors, find_char = "Blue")
#> [1] "red', 'blue', 'green"