Skip to contents

Reads a CSV containing a revised ordering of attributes and levels and applies it to an existing projoint_data object. Typical workflow: first save the current labels to CSV (e.g., with save_labels), manually reorder rows (and/or the attribute grouping) in the CSV, then call read_labels() to apply.

Usage

read_labels(.data, .filename)

Arguments

.data

A projoint_data object whose labels/data should be reordered.

.filename

Path to the revised labels CSV (originally produced from the package's labels).

Value

A projoint_data object with the same content as .data but with attributes and levels reordered to match the CSV. The returned object contains:

  • $labels: a tibble with new attribute_id and level_id reflecting the chosen order

  • $data: a tibble whose att* columns have been remapped to the new level_ids

Examples

# \donttest{
# Create a projoint_data object from the example dataset
data(exampleData1)
outcomes <- c(paste0("choice", 1:8), "choice1_repeated_flipped")
pj <- reshape_projoint(exampleData1, outcomes)

# Write current labels to a temporary CSV, adding an 'order' column
tmp <- tempfile(fileext = ".csv")
pj$labels |>
  dplyr::mutate(order = dplyr::row_number()) |>
  readr::write_csv(tmp)

# (User would reorder rows in 'tmp' manually; we just read it back)
pj_reordered <- read_labels(pj, tmp)

# Inspect the updated label order
head(pj_reordered$labels)
#> # A tibble: 6 × 4
#>   attribute                level                        attribute_id level_id   
#>   <chr>                    <chr>                        <chr>        <chr>      
#> 1 Housing Cost             15% of pre-tax income        att1         att1:level1
#> 2 Housing Cost             30% of pre-tax income        att1         att1:level2
#> 3 Housing Cost             40% of pre-tax income        att1         att1:level3
#> 4 Presidential Vote (2020) 30% Democrat, 70% Republican att2         att2:level1
#> 5 Presidential Vote (2020) 50% Democrat, 50% Republican att2         att2:level2
#> 6 Presidential Vote (2020) 70% Democrat, 30% Republican att2         att2:level3
# }