These functions work with an attribute label. Which has been introduced by other packages (e.g. haven) and is implemented into the R-Studiio environment.

add_label(x, value)

rename_from_labels(
  data,
  keep = FALSE,
  pattern = "{name}: {label}",
  max_char = NULL
)

get_labels(data, keep = FALSE, pattern = "{name}: {label}", max_char = NULL)

Arguments

x

A data frame or a vector.

value

Either a single character string when x is a vector or a named list (columnname = label) with character strings when x is a data.frame.

data

A data.frame.

keep

If TRUE, new names are a combination of var names and label names.

pattern

Pattern for gleu function when keep = TRUE.

max_char

Maximum number of characters for the label.

Value

For add_label: A vector or a data.frame with added label attribute(s).

For rename_from_labels: A data.frame with renamed labels or for get_labels a character vector with label names.

For get_labels: A names character vector with labels (and columnnames as names).

Examples

mtcars_labeled |> get_labels()
#>                       mpg                       cyl                      disp 
#>       "Miles/(US) gallon"     "Number of cylinders"   "Displacement (cu.in.)" 
#>                        hp                      drat                        wt 
#>        "Gross horsepower"         "Rear axle ratio"       "Weight (1000 lbs)" 
#>                      qsec                        vs                        am 
#>           "1/4 mile time"             "Engine Type"       "Transmission Type" 
#>                      gear                      carb 
#> "Number of forward gears"   "Number of carburetors"