Skip to contents

Encode a Vector of Character

Usage

encode(x, level = 1, chars = printable_chars(level))

Arguments

x

vector of character

level

one of 1, 2, or 3 defining which character set to use for encoding, see printable_chars.

chars

vector of characters to be used for encoding

Value

vector of character as long as x with each element containing the encoded version of the corresponding element in x. The returned vector has an attribute codes being a named vector. This vector contains the unique values in x as elements. Each element is named by the code that was used to encode the corresponding element.

Examples

x <- c("very-long-word", "very-long-word", "very-very-long-word")
encoded <- encode(x)
encoded
#> [1] "1" "1" "2"
#> attr(,"codes")
#>                     1                     2 
#>      "very-long-word" "very-very-long-word" 
decode(encoded)
#> [1] "very-long-word"      "very-long-word"      "very-very-long-word"