Skip to contents

This function takes a dataframe and adds labels to columns that have registered nicknames. The labels are stored as the "label" attribute for each matching column and are visible in e.g. the Rstudio data viewer.

Usage

nn_add_labels(df, dict = "default")

Arguments

df

A dataframe to add labels to

dict

The dictionary name to use for nickname lookups (defaults to "default")

Value

The dataframe with label attributes added to matching columns

Examples

# Register some nickname mappings
nn_register(c(
  "mpg" = "Miles per Gallon",
  "hp" = "Horsepower",
  "cyl" = "Number of Cylinders"
))

# Add labels to mtcars dataframe
labeled_mtcars <- nn_add_labels(mtcars)

# If you're using Rstudio, run View(labeled_mtcars)
# or check the labels manually:
attr(labeled_mtcars$mpg, "label") # "Miles per Gallon"
#> [1] "Miles per Gallon"
attr(labeled_mtcars$hp, "label") # "Horsepower"
#> [1] "Horsepower"