Learn R Programming

rapport (version 0.51)

rp.label: Get Variable Label

Description

This function returns character value previously stored in variable's label attribute. If none found, and fallback argument is set to TRUE (default), the function returns object's name (retrieved by deparse(substitute(x))), otherwise NA is returned with a warning notice.

Usage

rp.label(x, fallback = TRUE, simplify = TRUE)

Arguments

x
an R object to extract labels from
fallback
a logical value indicating if labels should fallback to object name(s)
simplify
coerce results to a vector (TRUE by default), otherwise, a list is returned

Value

  • a character vector with variable's label(s)

Examples

Run this code
x <- rnorm(100)
rp.label(x)         # returns "x"
rp.label(x, FALSE)  # returns NA and issues a warning

rp.label(mtcars$hp) <- "Horsepower"
rp.label(mtcars)         # returns "Horsepower" instead of "hp"
rp.label(mtcars, FALSE)  # returns NA where no labels are found
rp.label(sleep, FALSE)   # returns NA for each variable and issues a warning

Run the code above in your browser using DataLab