artoo_encodings: Encodings for clinical datasets, across R, SAS, and Python

View source: R/encoding.R

artoo_encodingsR Documentation

Encodings for clinical datasets, across R, SAS, and Python

Description

List the character encodings clinical data actually travels in, with the name each ecosystem uses for the same thing: the R name (the standard IANA name, which iconv() and the wider R ecosystem use), the SAS session-encoding name, and the Python codec. Any spelling from the r or sas column works as the encoding argument of every artoo reader and writer.

Usage

artoo_encodings()

Details

What an encoding is. Text is stored as bytes; an encoding is the rule that maps those bytes to characters. Plain A-Z digits and punctuation are the same bytes in every encoding listed here — the differences only show in accented letters (a-umlaut, e-acute), special symbols (micro, degree), and non-Latin scripts. Reading bytes with the wrong rule is what turns a degree sign into garbage.

Which one do I have? In SAS, run ⁠PROC OPTIONS OPTION=ENCODING; RUN;⁠ and look up the reported name in the sas column. Most US/EU Windows SAS installs report WLATIN1 — that is windows-1252 here.

Which one should I write? Usually none: write_*(encoding = NULL) (the default) inherits the encoding recorded when the data was read, so a round-trip is byte-faithful. The regulatory defaults artoo applies when nothing is recorded: SAS XPORT writes US-ASCII (the FDA Study Data Technical Conformance Guide expectation) and Dataset-JSON / NDJSON write UTF-8 (required by CDISC and RFC 8259). A value that cannot be represented in the target encoding aborts loudly — see on_invalid on the writers.

Note: in memory, artoo text is always UTF-8 (NFC-normalised) — encodings only matter at the file boundary, exactly as in Python 3.

Value

A ⁠<data.frame>⁠ with one row per encoding and columns r (the R name — the standard IANA name iconv() uses, and what artoo records in the metadata), sas (the SAS session-encoding name), python (the Python codec name), and description.

See Also

Use it: the encoding argument of read_xpt(), write_xpt(), read_json(), and the other readers/writers.

Formats: artoo_formats() for the codec registry.

Examples

# ---- Example 1: the full cross-ecosystem table ----
#
# One row per encoding; the same byte rule under each ecosystem's name.
artoo_encodings()

# ---- Example 2: look up a SAS session encoding ----
#
# PROC OPTIONS reported WLATIN1: find the R and Python names for the
# same bytes (the sas and r spellings both work as encoding=).
enc <- artoo_encodings()
enc[enc$sas == "WLATIN1", ]


artoo documentation built on July 23, 2026, 1:08 a.m.