Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

chr_unserialise_unicode

Translate unicode points to UTF-8


Description

Experimental lifecycle

For historical reasons, R translates strings to the native encoding when they are converted to symbols. This string-to-symbol conversion is not a rare occurrence and happens for instance to the names of a list of arguments converted to a call by do.call().

If the string contains unicode characters that cannot be represented in the native encoding, R serialises those as an ASCII sequence representing the unicode point. This is why Windows users with western locales often see strings looking like <U+xxxx>. To alleviate some of the pain, rlang parses strings and looks for serialised unicode points to translate them back to the proper UTF-8 representation. This transformation occurs automatically in functions like env_names() and can be manually triggered with as_utf8_character() and chr_unserialise_unicode().

Usage

chr_unserialise_unicode(chr)

Arguments

chr

A character vector.

Life cycle

This function is experimental.

Examples

ascii <- "<U+5E78>"
chr_unserialise_unicode(ascii)

identical(chr_unserialise_unicode(ascii), "\u5e78")

rlang

Functions for Base Types and Core R and 'Tidyverse' Features

v0.4.11
MIT + file LICENSE
Authors
Lionel Henry [aut, cre], Hadley Wickham [aut], mikefc [cph] (Hash implementation based on Mike's xxhashlite), Yann Collet [cph] (Author of the embedded xxHash library), RStudio [cph]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.