Skip to contents

Quote elements of a a vector and concatenate the result to a single character string.

Usage

paste_quoted(x)

Arguments

x

Dimensionless atomic object to be converted to a single character string.

Value

A character string consisting of the elements of x surrounded by single quotes, separated by commas. See Details on the handling of some special values.

Details

Some values are handled specially to print clearer:

  • NULL is returned as "'NULL'"

  • non-NULL zero-length objects are returned as "'<class>(0)'" (e.g., "'logical(0)'")

  • "" is returned as '""'

  • logical NA is returned as "'NA'"

  • non-logical NA is returned as "'NA_<class>_'" (e.g., "'NA_real_'"; for factors this is "'NA_character_'").

Notes

An error is thrown if multiple arguments are provided because then x probably was accidentally not combined. For example, the call paste_quoted("a", "b") will return the error unused argument ("b"). The probably intended call is paste_quoted(c("a", "b")), returning "'a', 'b'".

paste_quoted() drops names of x, which is pointed out in a warning if x has names. Use unname() on named x to prevent these warnings.

See also

toString() which is shorthand for paste(x, collapse = ", "); Quotes and sQuote() for documentation on quotes; paste0(); progutils::unpaste_unquote() for the approximate reverse of paste_quoted(); progutils::vect_to_char() to preserve names of numeric x

Examples

paste_quoted(c(3, 4)) # "'3', '4'"
#> [1] "'3', '4'"
paste_quoted(NULL) # "'NULL'"
#> [1] "'NULL'"
paste_quoted(c(a = 3, b = 4)) # "'3', '4'" # Warns about dropping names.
#> Warning: 'x' has names, these will be discarded.
#> Use progutils::vect_to_char() instead of paste_quoted() to preserve names of numeric 'x'.
#> [1] "'3', '4'"