keyLookup.RdUse 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.
keyLookup(x, key, get = "name_old")A vector or list of matches between x and either name_new or name_old elements in the key.
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.
mydf.key.path <- system.file("extdata", "mydf.key.csv", package = "kutils")
mydf.key <- keyImport(mydf.key.path)
#> keyImport guessed that is a wide format key.
mydf.key$name_new <- paste0("new_", mydf.key$name_new)
keyLookup("new_x5", mydf.key, get = "name_old")
#> [1] "new_x5"
keyLookup(c("new_x6", "new_x1"), mydf.key, get = "name_old")
#> [1] "new_x6" "new_x1"
keyLookup(c("x6", "x1"), mydf.key, get = "name_new")
#> x6 x1
#> "new_x6" "new_x1"
keyLookup(c("asdf", "new_x1"), mydf.key, get = "name_old")
#> [1] NA "new_x1"
mydf.key <- rbind(mydf.key,
c("x3", "x3f", "ordered", "factor", "","","",""))
keyLookup(c("x3"), mydf.key, get = "name_new")
#> x3
#> [1,] "new_x3"
#> [2,] "x3f"
keyLookup(c("x1", "x3", "x5"), mydf.key, get = "name_new")
#> [1] "Note: name_old 'x3' matches several values in name_new: new_x3, x3f"
#> $x1
#> [1] "new_x1"
#>
#> $x3
#> [1] "new_x3" "x3f"
#>
#> $x5
#> [1] "new_x5"
#>