get_label {crosstable}R Documentation

Get label if wanted and available, or default (name) otherwise

Description

Get label if wanted and available, or default (name) otherwise

Usage

get_label(x, default = names(x), object = FALSE, simplify = TRUE)

Arguments

x

labelled object. If x is a list/data.frame, get_label() will return the labels of all children recursively

default

value returned if there is no label. Default to names(x).

object

if x is a list/data.frame, object=TRUE will force getting the labels of the object instead of the children

simplify

if x is a list and object=FALSE, simplify the result to a vector

Value

A character vector if simplify==TRUE, a list otherwise

Author(s)

Dan Chaltiel

See Also

set_label(), import_labels(), remove_label(), Hmisc::label(), expss::var_lab()

Examples

xx=mtcars2 %>%
  set_label("The mtcars2 dataset", object=TRUE)
xx$cyl=remove_label(xx$cyl)

#vectors
get_label(xx$mpg) #label="Miles/(US) gallon"
get_label(xx$cyl) #default to NULL (as names(xx$cyl)==NULL)
get_label(xx$cyl, default="Default value")

#data.frames
get_label(xx)
get_label(xx, object=TRUE)
data.frame(name=names(xx), label=get_label(xx, default=NA)) #cyl is NA

#lists
get_label(list(xx$cyl, xx$mpg))
get_label(list(foo=xx$cyl, bar=xx$mpg))
get_label(list(foo=xx$cyl, bar=xx$mpg), default="Default value")

[Package crosstable version 0.7.0 Index]