Learn R Programming

mark (version 0.8.2)

labels: Dataframe labels

Description

Assign labels to a vector or data.frame.

Usage

assign_labels(x, ...)

# S3 method for default assign_labels(x, label, ...)

# S3 method for data.frame assign_labels( x, ..., .missing = c("error", "warn", "skip"), .ls = rlang::list2(...) )

get_labels(x)

# S3 method for default get_labels(x)

# S3 method for data.frame get_labels(x)

view_labels(x, title)

remove_labels(x, ...)

# S3 method for default remove_labels(x, ...)

# S3 method for data.frame remove_labels(x, cols, ...)

Value

A labelled vector or data.frame

Arguments

x

A vector of data.frame

...

One or more unquoted expressed separated by commas. If assigning to a data.frame, ... can be replaced with a data.frame where the first column is the targeted colname and the second is the desired label.

label

A single length string of a label to be assigned

.missing

A control setting for dealing missing columns in a list; can be set to error to stop() the call, warn to provide a warning, or skip to silently skip those labels.

.ls

A named list of columns and labels to be set if ... is empty

title

Title for the viewer window -- if not supplemented will show as paste0(as.character(substitute(x)), " - Labels")

cols

A character vector of column names; if missing will remove the label attribute across all columns

Details

When labels are assigned to a data.frame they can make viewing the object (with View() inside Rstudio). The view_labels() has a call to View() inside and will retrieve the labels and show them in the viewer as a data.frame.

Examples

Run this code
labs <- assign_labels(
  iris,
  Sepal.Length = "cms",
  Sepal.Width  = "cms",
  Petal.Length = "cms",
  Petal.Width  = "cms",
  Species      = "Iris ..."
)

labs$dummy <- ""
get_labels(labs) # shows label as  for dummy column

labs0 <- remove_labels(labs, c("Sepal.Length", "Sepal.Width"))
get_labels(labs0) # No labels for Sepal.Length and Sepal.Width

Run the code above in your browser using DataLab