ropensci / qualtRics

Download ⬇️ Qualtrics survey data directly into R!
https://docs.ropensci.org/qualtRics
Other
215 stars 70 forks source link

fetch_survey parsing and mutate warnings #196

Closed stijndelaat closed 3 years ago

stijndelaat commented 3 years ago

One of my surveys is currently giving out parsing and mutate warnings for three or four columns. The warnings look like this:

Warning: Problem with `mutate()` input `Q56`.
i 36 parsing failures.
row col           expected                            actual
 21  -- value in level set Niet elke week. 3 dagen in totaal
 35  -- value in level set 1 keer 1 dag                     
 53  -- value in level set 1 

or this:

Input `Q56` is `readr::parse_factor(Q56, levels = ln, ordered = TRUE)`.
Warning: 36 parsing failures.
row col           expected                            actual
 21  -- value in level set Niet elke week. 3 dagen in totaal
 35  -- value in level set 1 keer 1 dag 

As a result, these columns remain empty (only NA's) even though several of them need to be filled. To be precise, exact those rows that are reported in the warnings.

I have identified the questions as being open ended questions (single line text entry questions). Note: other open ended questions seem to work fine.

I've tried specifying the column as.character:

fetch_survey(surveyID = surveys$id[surveys$name == XXX],
               label = TRUE,
               force_request = TRUE,
               col_types = readr::cols(Q56 = readr::col_character()))

However, this seemed not to be the problem.

Hopefully you are able to help me out. Thank you in advance!

juliasilge commented 3 years ago

Hmmmmm, it looks like for some reason R is trying to convert your free text field to a factor, which mean that it thinks the question is one of the kinds that should be a factor, like multiple choice. What kind of question does it say you have, if you try this?

library(qualtRics)
library(tidyverse)

md <- tibble::enframe(metadata("SV_xxx",
                               get = list(
                                 "questions" = TRUE,
                                 "metadata" = FALSE,
                                 "responsecounts" = FALSE
                               ))[[1]])

md_parsed <- dplyr::mutate(md,
                           question_type = map(value, "questionType"),
                           question_name = map_chr(value, "questionName"),
                           type_supp = map_chr(question_type, "type"),
                           selector_supp = map_chr(question_type, "selector"),
                           type_supp = type_supp %in% c("MC"),
                           selector_supp = selector_supp %in% c("SAVR"),
                           name_in_survey = question_name %in% names(data),
                           supported = type_supp & selector_supp & name_in_survey)

md_parsed %>% filter(name == "QID37") %>% pull(question_type)
#> [[1]]
#> [[1]]$type
#> [1] "MC"
#> 
#> [[1]]$selector
#> [1] "SAVR"
#> 
#> [[1]]$subSelector
#> [1] "TX"

Created on 2020-11-15 by the reprex package (v0.3.0.9001)

This one is a multiple choice ("MC").

Have you tried using fetch_survey() with convert = FALSE, to avoid trying to force this conversion to factors?

stijndelaat commented 3 years ago

The output for question name == "QID56" (the one in my example) gives the following outcome:

[[1]]
[[1]]$type
[1] "MC"

[[1]]$selector
[1] "SAVR"

[[1]]$subSelector
[1] "TX"

So it seems to be forced into a MC type as you said. I have dubbelchecked the survey in Qualtrics and the type is 'single line - text entry'.

When using the convert = FALSE option, the warnings are not present. I quite liked the automatic conversion though :).

juliasilge commented 3 years ago

A text question in Qualtrics should have a question type that looks something like this:

[[1]]
[[1]]$type
[1] "TE"

[[1]]$selector
[1] "ESTB"

[[1]]$subSelector
NULL

I believe that something has gone awry with your Qualtrics survey question type, perhaps it was originally set as multiple choice and then later changed or similar? We are getting this information about the questions from the Qualtrics API itself, not anything that the R package is detecting.

juliasilge commented 3 years ago

Let us know if you have further problems or questions! 🙌