Learn R Programming

projoint (version 1.0.6)

read_labels: Read and apply a reordered attribute/level mapping

Description

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)

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

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).

See Also

save_labels, reshape_projoint

Examples

Run this code
# \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)
# }

Run the code above in your browser using DataLab