Convert vector to a character string
stm_vector_to_char.Rdstm_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.
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_stopisTRUE, the function will stop iffind_charis not invec.- is_stop
A logical value. If
TRUE, an error is raised if thefind_charis not found invec.- 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"