lbl: Make a label placeholder object

View source: R/lbl_helpers.R

lblR Documentation

Make a label placeholder object


Define a new label/value pair. For use in functions like lbl_relabel() and lbl_add().





Either one or two arguments specifying the label (.lbl) and value (.val) to use in the new label pair.

If arguments are named, they must be named .val and/or .lbl.

If a single unnamed value is passed, it is used as the .lbl for the new label. If two unnamed values are passed, they are used as the .val and .lbl, respectively.


Several ⁠lbl_*()⁠ functions include arguments that can be passed a function of .val and/or .lbl. These refer to the existing values and labels in the input vector, respectively.

Use .val to refer to the values in the vector's value labels. Use .lbl to refer to the label names in the vector's value labels.

Note that not all ⁠lbl_*()⁠ functions support both of these arguments.


A label_placeholder object

See Also

Other lbl_helpers: lbl_add(), lbl_clean(), lbl_define(), lbl_na_if(), lbl_relabel(), zap_ipums_attributes()


# Label placeholder with no associated value
lbl("New label")

# Label placeholder with a value/label pair
lbl(10, "New label")

# Use placeholders as inputs to other label handlers
x <- haven::labelled(
  c(100, 200, 105, 990, 999, 230),
  c(`Unknown` = 990, NIU = 999)

x <- lbl_add(
  lbl(100, "$100"),
  lbl(105, "$105"),
  lbl(200, "$200"),
  lbl(230, "$230")

lbl_relabel(x, lbl(9999, "Missing") ~ .val > 900)

ipumsr documentation built on Oct. 20, 2023, 5:10 p.m.