df <- dataset_df(
id = defined(1:3, label = "Observation ID"),
temp = defined(c(22.5, 23.0, 21.8), label = "Temperature (°C)"),
site = defined(c("A", "B", "A"))
)
# Get all variable labels
var_labels(df)
# Set multiple labels at once
var_labels(df) <- list(site = "Site code")
# Return as a named vector with empty string for unlabeled vars
var_labels(df, unlist = TRUE, null_action = "empty")
Run the code above in your browser using DataLab