import_labels: Import labels

View source: R/labels.R

import_labelsR Documentation

Import labels

Description

import_labels imports labels from a data.frame (data_label) to another one (.tbl). Works in synergy with save_labels().

save_labels saves the labels from a data.frame in a temporary variable that can be retrieve by import_labels.

Usage

import_labels(
  .tbl,
  data_label,
  name_from = "name",
  label_from = "label",
  warn_name = FALSE,
  warn_label = FALSE,
  verbose = deprecated()
)

save_labels(.tbl)

Arguments

.tbl

the data.frame to be labelled

data_label

a data.frame from which to import labels. If missing, the function will take the labels from the last dataframe on which save_labels() was called.

name_from

in data_label, which column to get the variable name (default to name)

label_from

in data_label, which column to get the variable label (default to label)

warn_name

if TRUE, displays a warning if a variable name is not found in data_label

warn_label

if TRUE, displays a warning if a label is not found in .tbl

verbose

deprecated

Value

A dataframe, as .tbl, with labels

.tbl invisibly. Used only for its side effects.

Author(s)

Dan Chaltiel

See Also

get_label(), set_label(), remove_label(), save_labels()

Examples

#import the labels from a data.frame to another
iris_label = data.frame(
  name=c("Sepal.Length", "Sepal.Width",
         "Petal.Length", "Petal.Width", "Species"),
  label=c("Length of Sepals", "Width of Sepals",
          "Length of Petals", "Width of Petals", "Specie name")
)
iris %>%
  import_labels(iris_label) %>%
  crosstable

#save the labels, use some dplyr label-removing function, then retrieve the labels
library(dplyr)
mtcars2 %>%
  save_labels() %>%
  transmute(disp=as.numeric(disp)+1) %>%
  import_labels(warn_label=FALSE) %>% #
  crosstable(disp)

crosstable documentation built on Nov. 13, 2023, 1:08 a.m.