get_label function

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

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

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

Returns

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

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 (since 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)) #cyl is NA get_label(list(foo=xx$cyl, bar=xx$mpg)) #default to names get_label(list(foo=xx$cyl, bar=xx$mpg), default="Default value")

See Also

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

Author(s)

Dan Chaltiel