qualtRics icon indicating copy to clipboard operation
qualtRics copied to clipboard

`all_surveys` Error When Survey Name is Blank

Open Scott123456 opened this issue 3 years ago • 2 comments

When running the all_surveys function, I get an error due to a NULL survey name. The error occurs when the function tries to bind_rows(master) at the end. It cannot complete the bind_rows if there is a null value in any of the elements. :/

I was able to work around it by changing the survey name in Qualtrics online. However, it took me a couple hours to figure out the issue. It's kind of crazy that Qualtrics returns an element with a null value (or even allows a survey to have no name), but it does and it breaks the expected behavior of the function.

One proposed solution is to check all elements for null values before appending or binding and replacing them with NA. Though I haven't been able to test this solution yet.

Scott123456 avatar Apr 07 '21 19:04 Scott123456

Oh, that sounds super frustrating, wow! 🥴 Your proposed solution sounds like a good thing to try here in the R package to get around the behavior in the API.

juliasilge avatar Apr 09 '21 14:04 juliasilge

We had to deal with NULL values frequently when working with mailing lists and distribution data. Our solution was to avoid using dplyr::bind_rows due to the issue stated above, that null values will throw errors when binding is attempted.

Our solution was to explicitly call the list values using purrr:map_* and allow the .default argument to coerce nulls into NA values.

So rather than

  d <- bind_rows(master)

We would do something like

  x <- tibble::tibble(id = purrr::map_chr(master, "id", .default = NA_character_),
                      name = purrr::map_chr(master, "id", .default = NA_character_),
                      ownerId = purrr::map_chr(master, "id", .default = NA_character_),
                      lastModified = lubridate::ymd_hms(purrr::map_chr(master, "id", .default = NA_character_)),
                      creationDate = lubridate::ymd_hms(purrr::map_(master, "id", .default = NA_character_)),
                      isActive = purrr::map_lgl(master, "id", .default = NA_real_))

The code is definitely less elegant and less compact, but it's explicit and prevents issues with NULL values.

dsen6644 avatar Jun 16 '21 00:06 dsen6644