Skip to contents

Applies notes stored in a data frame object as attributes to corresponding variables in AmericasBarometer dataset. This is particularly useful for setting variable labels, question wording, or other metadata from extracted notes.

Usage

lpr_set_attr(data, notes, noteid = character(), attribute_name = character())

Arguments

data

A data frame whose variables will receive new attributes

notes

A data frame containing notes information, typically produced by lpr_extract_notes. Must contain columns: variable_name, note_id, and note_value.

noteid

Character string specifying which note ID to extract from the notes data frame (e.g., "label" for variable labels, "qtext" for question text).

attribute_name

Character string specifying the attribute name to set (e.g., "label", "qwording", "roslabel").

Value

The input data frame with specified attributes added to relevant variables

Details

This function:

  • Filters the notes data frame to only include rows matching the specified `noteid`

  • Loops through each matching note and applies it as an attribute to the corresponding variable in the data frame

  • Issues warnings for variables in the notes that don't exist in the data

The function is designed to work in tandem with lpr_extract_notes, creating a workflow for managing variable metadata in AmericasBarometer data.

See also

lpr_extract_notes for extracting notes from AmericasBarometer dataset attributes

Examples

# First extract notes from dataset attributes
if (FALSE) { # \dontrun{
notes <- lpr_extract_notes(data)
} # }

# Set variable question wording
if (FALSE) { # \dontrun{
data <- lpr_set_attr(data, notes, noteid = "note4", attribute_name = "question_wording")
attr(data$ing4, "question_wording")
} # }