as_utf8_character {rlang}R Documentation

Coerce to a character vector and attempt encoding conversion

Description

Unlike specifying the encoding argument in as_string() and as_character(), which is only declarative, these functions actually attempt to convert the encoding of their input. There are two possible cases:

When translating to UTF-8, the strings are parsed for serialised unicode points (e.g. strings looking like "U+xxxx") with chr_unserialise_unicode(). This helps to alleviate the effects of character-to-symbol-to-character roundtrips on systems with non-UTF-8 native encoding.

Usage

as_utf8_character(x)

as_native_character(x)

as_utf8_string(x)

as_native_string(x)

Arguments

x

An object to coerce.

Examples

# Let's create a string marked as UTF-8 (which is guaranteed by the
# Unicode escaping in the string):
utf8 <- "caf\uE9"
str_encoding(utf8)
as_bytes(utf8)

# It can then be converted to a native encoding, that is, the
# encoding specified in the current locale:
## Not run: 
mut_latin1_locale()
latin1 <- as_native_string(utf8)
str_encoding(latin1)
as_bytes(latin1)

## End(Not run)

[Package rlang version 0.2.2 Index]