apply_labs_haven: Apply haven value labels to a vector

View source: R/utils.R

apply_labs_havenR Documentation

Apply haven value labels to a vector

Description

Apply haven value labels to a vector

Usage

apply_labs_haven(x, labels, ptype, ...)

Arguments

x

a vector to label

labels

a named vector of labels in the format c(value = label)

ptype

vector to serve as prototype for label values

...

unused, needed to ignore extra arguments that may be passed

Details

Assumes a check_installed() has been run for labelled. Since haven preserves the underlying data values we need to make sure the data type of the value options in the metadata matches the data type of the values in the actual data. This function accepts a prototype, usually a column from db_data, and uses force_cast() to do a best-effort casting of the value options in the metadata to the same data type as ptype. The fallback is to convert x and the value labels to character.

Value

haven_labelled vector


REDCapTidieR documentation built on April 3, 2025, 10:50 p.m.