Skip to contents

Split a character string into a vector, removing quotation marks

Usage

unpaste_unquote(x, collapse = c(", ", "; "), quotemarks = c("'", "\""))

Arguments

x

a character string.

collapse

character vector with elements that were used to collapse values when x was created, and are now used to split x on. Can be character(0) to leave x as a character string.

quotemarks

character vector with quotation marks to be removed from x. Can be character(0) to not remove any quotation marks.

Value

x without the quotation marks in quotemarks, split into a vector on the string in collapse.

Details

unpaste_unquote() does not restore NAs or zero-length elements to their original values after removing the quotation marks, such that unpaste_unquote() is not the exact reverse of paste_quoted(). For example, "'NA_character_'" becomes "NA_character_" instead of NA_character_, "'NULL'" becomes "NULL" instead of NULL, and "'character(0)'" becomes "character(0)" instead of character(0).

See also

paste_quoted() for the approximate opposite of unpaste_unquote().

Other functions to modify character vectors: as.numeric_safe(), reexports, replace_vals(), signal_text(), vect_to_char(), wrap_text()

Examples

x <- paste_quoted(c("ff", "gG", "HH"))
x
#> [1] "'ff', 'gG', 'HH'"
unpaste_unquote(x = x, collapse = ", ", quotemarks = "'")
#> [1] "ff" "gG" "HH"
unpaste_unquote(x = x, collapse = ", ", quotemarks = "\"")
#> [1] "'ff'" "'gG'" "'HH'"
unpaste_unquote(x = x, collapse = character(0), quotemarks = c("'", "\""))
#> [1] "ff, gG, HH"
unpaste_unquote(x = x, collapse = character(0), quotemarks = character(0))
#> [1] "'ff', 'gG', 'HH'"