keyLookup: Look for old (or new) names in variable key

View source: R/variableKey.R

keyLookupR Documentation

Look for old (or new) names in variable key

Description

Use the key to find the original name of a variable that has been renamed, or find the new name of an original variable. The get argument indicates if the name_old or name_new is desired.

Usage

keyLookup(x, key, get = "name_old")

Arguments

x

A variable name. If get = "name_old", then x is a value for name_new. If get = "name_new", x should be a value for name_old.

key

Which key should be used

get

Either "name_old" (to retrieve the original name) or "name_new" (to get the new name)

Details

If get = "name_old", the return is a character vector, with one element per value of x. If there is no match for a value of x, the value NA is returned for that value. However, if get = "name_new", the return might be either a vector (one element per value of x) or a list with one element for each value of x. The list is returned when a value of x corresponds to more than one element in name_old.

Value

A vector or list of matches between x and either name_new or name_old elements in the key.

Author(s)

Paul Johnson

Examples

mydf.key.path <- system.file("extdata", "mydf.key.csv", package = "kutils")
mydf.key <-  keyImport(mydf.key.path)
mydf.key$name_new <- paste0("new_", mydf.key$name_new)
keyLookup("new_x5", mydf.key, get = "name_old")
keyLookup(c("new_x6", "new_x1"), mydf.key, get = "name_old")
keyLookup(c("x6", "x1"), mydf.key, get = "name_new")
keyLookup(c("asdf", "new_x1"), mydf.key, get = "name_old")

mydf.key <- rbind(mydf.key,
                 c("x3", "x3f",  "ordered", "factor", "","","",""))
keyLookup(c("x3"), mydf.key, get = "name_new")
keyLookup(c("x1", "x3", "x5"), mydf.key, get = "name_new")

kutils documentation built on Sept. 17, 2023, 5:06 p.m.