Skip to contents

Retrieve labels from labelled data

Usage

retrieve_labels(data, wide = TRUE)

Arguments

data

labelled data frame

wide

format of return: wide (default) returns a tibble with a single row that contains the variable labels; otherwise, the full data dictionary is returned

Value

a tibble

Examples


dat_labelled <- tibble::tibble(
  var_1 = 1:3,
  var_2 = LETTERS[1:3],
  var_3 = Sys.Date() - 0:2
  ) %>%
  labelled::set_variable_labels(
    var_1 = "Variable 1 (numbers)",
    var_2 = "Variable 2 (letters)",
    var_3 = "Variable 3 (date)"
  )

retrieve_labels(dat_labelled)
#> # A tibble: 1 × 3
#>   var_1                var_2                var_3            
#>   <chr>                <chr>                <chr>            
#> 1 Variable 1 (numbers) Variable 2 (letters) Variable 3 (date)
retrieve_labels(dat_labelled, wide = FALSE)
#> # A tibble: 3 × 7
#>     pos variable label                col_type missing levels       value_labels
#>   <int> <chr>    <chr>                <chr>      <int> <named list> <named list>
#> 1     1 var_1    Variable 1 (numbers) int            0 <NULL>       <NULL>      
#> 2     2 var_2    Variable 2 (letters) chr            0 <NULL>       <NULL>      
#> 3     3 var_3    Variable 3 (date)    date           0 <NULL>       <NULL>