Skip to contents

Map names from one software to another. The function replaces elements in the input vector x with their corresponding values in the mapping if a match is found. If an element in x does not have a corresponding mapping, it is returned unchanged with a warning.

Usage

translate(
  x = character(),
  mapping = NULL,
  nomatch = "original",
  warning = TRUE
)

Arguments

x

character vector of names to be translated.

mapping

A named character vector that defines the mapping for translation. The names of the vector should be the original names and the values should be the translated names.

nomatch

character(1) defining the value to be returned if a value in x can not be translated. The default nomatch = "original" returns the original value in x, while any other value for nomatch would report that value instead (e.g. nomatch = NA_character_ would return an NA for each value that can not be translated).

warning

logical(1) whether a warning should be reported if values in x can not be translated.

Value

A character vector with the translated names.

See also

Author

Gabriele Tomè

Examples


## MS-Dial names
x <- c("Average Rt(min)", "Alignment ID", "Average Mz")
map_vec <- nameMapping(from = "MS-Dial", to = "mzTab-M")
translate(x, mapping = map_vec)
#>             Average Rt(min)                Alignment ID 
#> "retention_time_in_seconds"                    "SMF_ID" 
#>                  Average Mz 
#>        "exp_mass_to_charge"