ropensci / ruODK

ruODK: An R Client for the ODK Central API
https://docs.ropensci.org/ruODK/
GNU General Public License v3.0
42 stars 13 forks source link

Image fields and Audit are parsed as a list type #40

Closed OdiljonQurbon closed 4 years ago

OdiljonQurbon commented 5 years ago

Problem

Image field and audit field have the type in the dataframe generated using "odata_submission_get" function. This creates problem for saving the dataset as csv file.

Reproducible example

library(ruODK)
    library(tidyverse)
    ruODK::ru_setup(
        svc = "https://sandbox.central.opendatakit.org/v1/projects/12/forms/simple_hh_question.svc",
        un = "tarqataman@gmail.com",
        pw = "Test-central06"
    )
    srv <- ruODK::odata_service_get()

    data <- ruODK::odata_submission_get(parse=TRUE, wkt=TRUE, table = srv$name[1], verbose = TRUE, local_dir = '.', tz = "Australia/Perth")
    write.csv(data, "mydata.csv", row.names = TRUE, fileEncoding = "UTF-8")
Session Info ```{r} # utils::sessionInfo() R version 3.6.1 (2019-07-05) Platform: i386-w64-mingw32/i386 (32-bit) Running under: Windows 10 x64 (build 18362) Matrix products: default locale: [1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 LC_MONETARY=English_United States.1252 LC_NUMERIC=C [5] LC_TIME=English_United States.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] gapminder_0.3.0 magrittr_1.5 forcats_0.4.0 stringr_1.4.0 purrr_0.3.3 readr_1.3.1 tidyr_1.0.0 tibble_2.1.3 ggplot2_3.2.1 [10] tidyverse_1.2.1 dplyr_0.8.3 glue_1.3.1 ruODK_0.6.6.9001 loaded via a namespace (and not attached): [1] withr_2.1.2 rvest_0.3.4 tidyselect_0.2.5 lattice_0.20-38 pkgconfig_2.0.3 utf8_1.1.4 xml2_1.2.2 [8] compiler_3.6.1 htmlwidgets_1.5.1 fs_1.3.1 readxl_1.3.1 Rcpp_1.0.2 cli_1.1.0 cellranger_1.1.0 [15] httr_1.4.1 tools_3.6.1 nlme_3.1-140 broom_0.5.2 R6_2.4.0 scales_1.0.0 assertthat_0.2.1 [22] curl_4.2 digest_0.6.22 gtable_0.3.0 fansi_0.4.0 stringi_1.4.3 rstudioapi_0.10 janitor_1.2.0 [29] hms_0.5.1 backports_1.1.5 htmltools_0.4.0 munsell_0.5.0 grid_3.6.1 lifecycle_0.1.0.9000 colorspace_1.4-1 [36] data.table_1.12.6 lubridate_1.7.4 rlang_0.4.1.9000 ellipsis_0.3.0 generics_0.0.2 vctrs_0.2.0 lazyeval_0.2.2 [43] zeallot_0.1.0 snakecase_0.11.0 haven_2.1.1 crayon_1.3.4 modelr_0.1.5 pillar_1.4.2 remotes_2.1.0 [50] DT_0.9 rlist_0.4.6.1 jsonlite_1.6 ```
florianm commented 4 years ago

Good catch, cheers! The problem seems to be between throwing mutate_at and attachment_get when parsing attachments odata_submission_get resulting in a list column.

This problem doesn't appear where I'm using for() loops (e.g. parsing dates or splitting coordinates). However, the automated unnesting of the audit.csv (which I'm not treating specially in any way - yet - see #40) also causes that list column.

florianm commented 4 years ago

Found a fix. purrr::pmap generates a list, which needed to be cast into its type - as.character did the trick.