Learn R Programming

rapport (version 0.3)

rp.label: Get Variable Label

Description

This function returns character value previously stored in variable's label attribute. If none found, the function defaults to object's name (retrieved by deparse(substitute(x))).

Usage

rp.label(x, fallback = TRUE)

Arguments

x
an R object to extract labels from
fallback
a logical value indicating if labels should fallback to object name(s)

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)  # fails with error message

rp.label(mtcars$hp) <- "Horsepower"
rp.label(mtcars)         # returns "Horsepower" instead of "hp"
rp.label(mtcars, FALSE)  # returns NA where no labels are found

Run the code above in your browser using DataLab