txt_recode_fast: Fast text recoding (Rcpp version)

View source: R/txt_recode_fast.R

txt_recode_fastR Documentation

Fast text recoding (Rcpp version)

Description

Efficiently recodes text values using C++ hash tables. This is a drop-in replacement for txt_recode but significantly faster for large vectors.

Usage

txt_recode_fast(x, from = c(), to = c(), na.rm = FALSE)

Arguments

x

A character vector to recode

from

A character vector with values of x which you want to recode

to

A character vector with values you want to use to recode to

na.rm

Logical, if set to TRUE, will put all values of x which have no matching value in from to NA. Defaults to FALSE

Details

This function uses C++ hash tables for O(1) lookup time, making it much faster than the pure R implementation, especially for large datasets.

Performance improvement: ~50-100x faster than base R txt_recode for vectors with 100K+ elements.

Value

A character vector of the same length as x where values matching from are replaced by corresponding values in to

Examples

x <- c("NOUN", "VERB", "NOUN", "ADV")
txt_recode_fast(x,
  from = c("VERB", "ADV"),
  to = c("conjugated verb", "adverb")
)


tall documentation built on Dec. 12, 2025, 5:07 p.m.