dickoa / robotoolbox

An R Client for the KoBoToolbox API v2 - https://dickoa.gitlab.io/robotoolbox/
Other
14 stars 5 forks source link

error with kobo_form #1

Closed sebastiansteinmueller closed 2 years ago

sebastiansteinmueller commented 2 years ago

When trying

library("robotoolbox")

asset <- kobo_asset("ae5bvmJUXEsxk6G9xuSYyW") dat <- kobo_submissions(asset)

I get the following error (seems to come from kobo_form):

_Error in rbindlist(dropnulls(survey), fill = TRUE) : Column 1 of item 152 is length 2 inconsistent with column 5 which is length 3. Only length-1 columns are recycled.

sessionInfo()

R version 4.2.0 (2022-04-22 ucrt) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 10 x64 (build 19042)Matrix products: default

locale: [1] LC_COLLATE=English_United Kingdom.utf8 LC_CTYPE=English_United Kingdom.utf8
[3] LC_MONETARY=English_United Kingdom.utf8 LC_NUMERIC=C
[5] LC_TIME=English_United Kingdom.utf8

attached base packages: [1] stats graphics grDevices utils datasets methods base

other attached packages: [1] dipsaus_0.2.0 data.table_1.14.2 RcppSimdJson_0.1.7 usethis_2.1.5
[5] robotoolbox_0.4.9001 srvyr_1.1.1 readxl_1.4.0 forcats_0.5.1
[9] stringr_1.4.0 dplyr_1.0.9 purrr_0.3.4 readr_2.1.2
[13] tidyr_1.2.0 tibble_3.1.6 ggplot2_3.3.5 tidyverse_1.3.1
[17] haven_2.5.0

sebastiansteinmueller commented 2 years ago

moved issue to gitlab, see there

dickoa commented 2 years ago

Hi @sebastiansteinmueller Thanks for this, I think we had a similar issue with a form in the past. I'll contact you to to see how we can reproduce it and fix the error. Thanks for raising the issue. Best, Ahmadou

johannesnelson commented 1 year ago

Hey there! Glad I found this old issue, because I am having the same problem today. The same rbindlist() error is thrown up during kobo_submissions():

Error in rbindlist(drop_nulls(survey), fill = TRUE) : Column 7 of item 3 is length 3 inconsistent with column 1 which is length 5. Only length-1 columns are recycled.

During debugging, I can see that it occurs within the kobo_form() function. I also noticed that as it is looping through the form versions, it gets through a number of them successfully, but then gets hung up on one form version in particular, stopping the data extraction. The function works fine with another project.

Please let me know what I can do to resolve this! Thanks for your time, and for the great package!

Here is my session info if that helps:

R version 4.3.0 (2023-04-21 ucrt) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 11 x64 (build 22621)

Matrix products: default

locale: [1] LC_COLLATE=English_United States.utf8 LC_CTYPE=English_United States.utf8 LC_MONETARY=English_United States.utf8 [4] LC_NUMERIC=C LC_TIME=English_United States.utf8

time zone: America/New_York tzcode source: internal

attached base packages: [1] stats graphics grDevices utils datasets methods base

other attached packages: [1] dplyr_1.1.3 robotoolbox_1.3.2.9001

loaded via a namespace (and not attached): [1] utf8_1.2.3 generics_0.1.3 tidyr_1.3.0 stringi_1.7.12 httpcode_0.3.0 hms_1.1.3 digest_0.6.31
[8] magrittr_2.0.3 dm_1.0.6 fastmap_1.1.1 backports_1.4.1 DBI_1.1.3 crul_1.4.0 urltools_1.7.3
[15] promises_1.2.0.1 purrr_1.0.2 fansi_1.0.4 cli_3.6.1 shiny_1.7.4 labelled_2.12.0 rlang_1.1.1
[22] triebeard_0.4.1 ellipsis_0.3.2 withr_2.5.1 cachem_1.0.8 tools_4.3.0 tzdb_0.4.0 memoise_2.0.1
[29] httpuv_1.6.9 forcats_1.0.0 curl_5.1.0 vctrs_0.6.3 R6_2.5.1 mime_0.12 lifecycle_1.0.3
[36] stringr_1.5.0 pkgconfig_2.0.3 pillar_1.9.0 later_1.3.0 data.table_1.14.8 glue_1.6.2 Rcpp_1.0.11
[43] RcppSimdJson_0.1.10 haven_2.5.3 tibble_3.2.1 tidyselect_1.2.0 rstudioapi_0.14 xtable_1.8-4 htmltools_0.5.5
[50] igraph_1.5.1 readr_2.1.4 compiler_4.3.0

dickoa commented 1 year ago

Hi @johannesnelson,

Thanks for raising this issue. You're right, it's due to one version of the form not playing well with the rest. I will need to find a way to reproduce this error, I fixed a similar issue in the past, but it looks like the fix is not working with your project. Does it work with the latest version of the form i.e kobo_data(uid, all_versions = FALSE) ?

johannesnelson commented 1 year ago

Hi @dickoa, thanks for getting back. Yes, the latest version of the form works, so using all_versions = FALSE runs fine.

I was able to track down the problematic form version and examine the data just before it gets passed to the rbindlist() function. It appears that there is a mistake in how the form was set up, potentially leaving some white space where NULL was intended. Here is a screen shot with the two misaligned elements highlighted.

kobo_form_error

dickoa commented 1 year ago

Hi @johannesnelson Thanks for this screenshot, it's super useful. I pushed a tentative fix, not sure if I got it right, but can you install the latest version (1.3.3.9000) and try again ?

johannesnelson commented 1 year ago

@dickoa thank you so much! Made my life a lot easier by supplying this fix. Yes, it works for me. Again, very much appreciated.

dickoa commented 1 year ago

Thanks for the feedback @johannesnelson , I totally forgot about including images in the form, thanks to you, it's now fully supported. Thanks again, Ahmadou