Skip to contents

Translates names between different lexicons (naming schema).

Usage

rename_vector(
  input,
  lexin = c("original", "original_phase2", "sequential", "gsed", "gsed2"),
  lexout = c("gsed2", "original", "original_phase2", "sequential", "gsed"),
  notfound = "copy",
  contains = c("", "Ma_SF_", "Ma_LF_", "bsid_"),
  underscore = TRUE,
  trim = "Ma_",
  lowercase = TRUE,
  force_subjid_agedays = FALSE
)

Arguments

input

A character vector with names to be translated

lexin

A string indicating the input lexicon. One of "original", "original_phase2", "sequential", "gsed" or "gsed2". Default is "original".

lexout

A string indicating the output lexicon. One of "original", "original_phase2", "sequential", "gsed" or "gsed2". Default is "gsed2".

notfound

A string indicating what to do some input value is not found

contains

A string to filter the translation table prior to matching. Needed to prevent double matches. The default ("") does not filter.

underscore

Replaces space (" ") and dash ("-") by underscore ("_")

trim

A substring to be removed from `input`. Defaults to "Ma_".

lowercase

Sets all variables in lower case. in `lexin`? The default `notfound = "copy"` copies the input values into the output value. In other cases (e.g. `""` or `NA_character_`), the function uses the string specified in `notfound` as a replacement value.

force_subjid_agedays

If `TRUE`, forces the output to have `"subjid"` and `"agedays"` as names for the `"ID"` and `"age"`, respectively.

Value

A character vector of the same length as `input` with processed names.

Examples

input <- c("file", "GSED_ID", "Ma_SF_Parent ID", "Ma_SF_C01", "Ma_SF_C02")
rename_vector(input)
#> [1] "file"         "gsed_id"      "sf_parent_id" "gpalac001"    "gpacgc002"   
rename_vector(input, lexout = "sequential", lowercase = FALSE)
#> [1] "file"         "GSED_ID"      "SF_Parent_ID" "C01"          "C02"         
rename_vector(input, lexout = "gsed", trim = "Ma_SF_")
#> [1] "file"      "gsed_id"   "parent_id" "gsdlac001" "gsdcgc002"

# SF/LF phase 2 names to default names
input <- c("file", "GSED_ID", "Ma_SF_Parent ID", paste0("Ma_SF_C00", 1:9))
rename_vector(input, lexin = "original_phase2", lowercase = TRUE)
#>  [1] "file"         "gsed_id"      "sf_parent_id" "sf_c001"      "sf_c002"     
#>  [6] "sf_c003"      "sf_c004"      "sf_c005"      "sf_c006"      "sf_c007"     
#> [11] "sf_c008"      "sf_c009"