Skip to contents

Gives column names and labels

Usage

show_labels(df, ...)

Arguments

df

data frame

...

columns of interest. If none are specified then all columns will be used. Accepts:

  • unquoted column names (e.g., ID)

  • character column names (e.g., "ID")

  • numeric indices (e.g., 1:3)

  • tidyselect helpers (e.g., starts_with("A"))

  • vectors of any of the above

Value

A tibble with the names of df in the first column and the labels of df in the second column

Details

If a column has a vector of labels then the first label will be returned.

See also

Examples

id <- 1:4
age <- c(83, 29, 64, 40)
bwt <- c(71, 66, 70, 81)
attr(id, "label") <- "Subject ID"
attr(age, "label") <- "Age (years)"
attr(bwt, "label") <- "Weight (kg)"
df <- tibble::tibble(ID = id, AGE = age, BWT = bwt)
show_labels(df)
#> # A tibble: 3 × 2
#>   name  label      
#>   <chr> <chr>      
#> 1 ID    Subject ID 
#> 2 AGE   Age (years)
#> 3 BWT   Weight (kg)
show_labels(df, "AGE", BWT)
#> # A tibble: 2 × 2
#>   name  label      
#>   <chr> <chr>      
#> 1 AGE   Age (years)
#> 2 BWT   Weight (kg)
show_labels(df, 2)
#> # A tibble: 1 × 2
#>   name  label      
#>   <chr> <chr>      
#> 1 AGE   Age (years)
show_labels(df, c("BWT", "ID"))
#> # A tibble: 2 × 2
#>   name  label      
#>   <chr> <chr>      
#> 1 BWT   Weight (kg)
#> 2 ID    Subject ID 
show_labels(df, tidyselect::starts_with("A"))
#> # A tibble: 1 × 2
#>   name  label      
#>   <chr> <chr>      
#> 1 AGE   Age (years)