ys_add_labels: Add label attribute to data set columns

View source: R/class-yspec.R

ys_add_labelsR Documentation

Add label attribute to data set columns

Description

This is commonly done prior to saving data to SASxport or other formats that will track label metadata for a data column.

Usage

ys_add_labels(data, spec, fun = label.ycol, strict = TRUE)

Arguments

data

a data.frame to label.

spec

yspec object for data.

fun

the function to use for forming label.

strict

if TRUE, generate an error when data names are not identical to spec names (including order); otherwise, only data items in common between data and spec (in any order) will be labeled.

Details

By default, an error is generated when the column names of the data set are not identical to the column names in the spec. Set strict = FALSE to bypass this error and label only columns that are in common between data and spec.

If the user passes fun to generate a custom label, the function must take a single argument, the column ycol object, and must return the label for that column as a character vector of length one.

Examples

spec <- ys_help$spec()

data <- ys_help$data()

data <- ys_add_labels(data, spec)

sapply(data, attr, "label")

str(data[,1:5])


metrumresearchgroup/yspec documentation built on March 4, 2025, 11:20 p.m.