Add literal item text or clean scale names as attributes to data frame columns for the HiTOP Brief Report (HiTOP-BR), making them readable by data viewers and reporting packages.
Usage
label_hitopbr(data, target = c("items", "scales"), prefix = "hbr_")Arguments
- data
A data frame containing HiTOP-BR items or scales.
- target
A string specifying what to label:
"items"to label raw item columns with questionnaire text, or"scales"to label computed scale columns.- prefix
A string specifying the prefix used on the column names. Item columns are expected as the prefix followed by the item number zero-padded to two digits (
hbr_01tohbr_45under the default, the pattern the shipped datasets and the package's REDCap export use; the Qualtrics export writesHBR_01, matched byprefix = "HBR_"). Columns that carry the prefix and a number that is not one of those expected names are not labelled, and a warning of classhitop_unpadded_itemsnames them, in a sentence per kind: a number without that padding is reported as not zero-padded to two digits, and a number outside 1 to 45 is reported as out of range, whatever its padding. That warning is raised whether or not any other column matched. Scale columns are expected as the prefix followed by the scale'scamelCasename, which is whatscore_hitopbr()writes under its own defaultprefix. (default ="hbr_")
Value
A data frame with labeled columns. If no column matched the expected
names at all, data is returned unchanged and a warning of class
hitop_no_columns_matched says so; the hitop_unpadded_items report
still names every prefixed item column it found. Both classes may be
caught or suppressed by callers.
Examples
# Attach item text as a `label` attribute to the raw item columns
labeled <- label_hitopbr(sim_hitopbr, target = "items")
attr(labeled$hbr_01, "label")
#> [1] "I found it easy to deceive others."
