Skip to contents

[Stable]

Usage

get_labels(data, fill = TRUE)

Arguments

data

(data.frame) table to extract the labels from

fill

(logical(1)) if TRUE, the function will return variable names for columns with non-existent labels; otherwise will return NA for them

Value

list with two keys: dataset_labels and column_labels

Examples

iris_with_labels <- iris
attr(iris_with_labels, "label") <- "Custom iris dataset with labels"
attr(iris_with_labels["Sepal.Length"], "label") <- c(`Sepal.Length` = "Sepal Length")
get_labels(iris_with_labels, fill = TRUE)
#> $dataset_label
#> [1] "Custom iris dataset with labels"
#> 
#> $column_labels
#>   Sepal.Length    Sepal.Width   Petal.Length    Petal.Width        Species 
#> "Sepal.Length"  "Sepal.Width" "Petal.Length"  "Petal.Width"      "Species" 
#> 
get_labels(iris_with_labels, fill = FALSE)
#> $dataset_label
#> [1] "Custom iris dataset with labels"
#> 
#> $column_labels
#> Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species 
#>           NA           NA           NA           NA           NA 
#>