Skip to contents

Translates a vector of IDs using a named vector (dictionary). If an ID is not found in the named vector (resulting in NA), the original ID is kept.

Usage

safe_translate_ids(named_vector, vector_to_translate)

Arguments

named_vector

A named vector where names are the original IDs and values are the translated IDs.

vector_to_translate

A character vector of IDs to translate.

Value

A character vector with translated IDs, preserving original IDs where translation was not possible.

Examples

translation_map <- c("ID1" = "NewID1", "ID2" = "NewID2")
ids_to_translate <- c("ID1", "ID3", "ID2")
safe_translate_ids(translation_map, ids_to_translate)
#>      ID1     <NA>      ID2 
#> "NewID1"    "ID3" "NewID2" 
# Should return: c("NewID1", "ID3", "NewID2")