Skip to main content

Module encoding

Module encoding 

Source
Expand description

Encoding / locale probing utilities.

This module exists mainly for debugging + experiments around R’s string encodings. R’s runtime has both:

  • per-CHARSXP encoding tags (UTF-8 / Latin-1 / bytes / native)
  • global/locale-level settings (native encoding, UTF-8 locale flags)

§Availability

The global signals are non-API (from Defn.h) and require the nonapi feature. Only the locale flags R’s shared library exports are read (utf8locale, mbcslocale, known_to_be_latin1); the hidden ones (known_to_be_utf8, latin1locale, R_nativeEncoding) must not even be referenced — an eager data relocation against a hidden symbol aborts dyn.load of the whole package (see sys::nonapi_encoding).

miniextendr_encoding_init() is not called by package_init; it exists for debugging and for standalone Rust applications embedding R.

A package loads in any locale. String conversions read each CHARSXP’s encoding mark and translate when needed; in a session whose locale isn’t UTF-8, the first translation of a native non-ASCII string raises one warning (NATIVE_TRANSLATION_CLASS).

Re-exports§

use std::sync::OnceLock; 🔒

Structs§

REncodingInfo
Cached snapshot of R’s encoding / locale state at init time.

Constants§

NATIVE_TRANSLATION_CLASS
The class of the warning a package raises the first time it translates a native string to UTF-8.

Statics§

ENCODING_INFO 🔒

Functions§

encoding_info
Return the cached encoding info (if miniextendr_encoding_init() has run).
miniextendr_encoding_init
Initialize / snapshot R’s encoding state.
warn_native_translation 🔒
Queue a warning, once per session for each package, the first time a native (unmarked) non-ASCII string is translated to UTF-8: the session’s locale isn’t UTF-8, and bytes its encoding can’t represent came out as <xx> escapes.