Skip to content

Commit

Permalink
Handle ordered factor when multiple choice question uses recoded vari…
Browse files Browse the repository at this point in the history
…able names (#343)

* If variableNames are non-null, use them for factor levels, otherwise use the choiceText.

* Reformat this bit of code

* Update NEWS

---------

Co-authored-by: Julia Silge <julia.silge@gmail.com>
  • Loading branch information
Haunfelder and juliasilge authored Jun 10, 2024
1 parent 72bde4e commit 03f4b66
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# qualtRics (development version)

- Fixed bug when a survey question has *both* recoded values and variable naming thanks to @Haunfelder (#343)

# qualtRics 3.2.0

- Changed how multiple choice questions are mapped to an R factor with the `convert` argument to `fetch_survey()`, to now excluding `NA` as a factor level (#315)
Expand Down
16 changes: 12 additions & 4 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -358,10 +358,18 @@ wrapper_mc <- function(data, question_meta) {
meta <- tibble::enframe(question_meta$choices)

# Level names
ln <- dplyr::pull(dplyr::mutate(meta,
meta_levels = purrr::map_chr(value,
"choiceText")),
meta_levels)
ln <-
dplyr::pull(
dplyr::mutate(meta,
meta_levels = ifelse(
purrr::map(value, function(x) is.null(x$variableName)),
purrr::map_chr(value, "choiceText"),
purrr::map_chr(value, "variableName")
)
),
meta_levels
)

ln <- remove_html(ln)

# Convert
Expand Down

0 comments on commit 03f4b66

Please sign in to comment.