Variable labels can be stored as a label attribute for each variable.
This functions returns a named character vector with the variable labels
(empty sting if not specified)
var_labels(x, fill = FALSE)a data.frame object
boolean in case the label attribute does not exist if
TRUE the variable names is returned, otherwise NA
a named character vector with the variable labels, the names correspond to the variable names
x <- iris
var_labels(x)
#> Sepal.Length Sepal.Width Petal.Length Petal.Width Species
#> NA NA NA NA NA
var_labels(x) <- paste("label for", names(iris))
var_labels(x)
#> Sepal.Length Sepal.Width Petal.Length
#> "label for Sepal.Length" "label for Sepal.Width" "label for Petal.Length"
#> Petal.Width Species
#> "label for Petal.Width" "label for Species"