as_character.prelabelled: Coerce prelabelled vectors to semantic character workspace

View source: R/prelabel.R

as_character.prelabelledR Documentation

Coerce prelabelled vectors to semantic character workspace

Description

Convert a prelabelled vector into a semantic character workspace suitable for iterative refinement and inference workflows.

Usage

## S3 method for class 'prelabelled'
as_character(x, ...)

Arguments

x

A prelabelled vector.

...

Unused.

Details

Unlike base as.character(), this method preserves:

  • original observational values;

  • semantic label mappings;

  • refinement metadata;

  • additional custom attributes.

The method operationalises provisional semantic labels into working character values while retaining the original observed vector for reversibility and provenance-aware workflows.

This allows workflows such as:

  • prelabel() %>% as.character() %>% refine()

  • prelabel() %>% as.character() %>% infer()

  • iterative semantic harmonisation;

  • contextual semantic derivation.

The original observational values are preserved in the "original_values" attribute.

The method intentionally separates:

  • observational evidence;

  • semantic operationalisation.

This distinction is important for provenance-aware semantic refinement workflows where semantic interpretations may evolve while original observations remain stable.

The coercion is therefore semantically reversible.

Value

A character vector where:

  • values are derived from the semantic labels;

  • original observations are preserved as attributes;

  • refinement metadata is retained;

  • the "prelabelled" class is removed.

Examples


x <- prelabel(
  c(
    "r",
    "pdf",
    "qmd"
  ),
  labels = c(
    r = "software development",
    pdf = "publication",
    qmd = "documentation"
  )
)

x

y <- as_character(x)

y

attributes(y)

attr(
  y,
  "original_values"
)


dataset documentation built on June 3, 2026, 5:07 p.m.