1. What is the issue? Please be detailed.
I am using ruODK and odata_submission_get in R.
All the images appear to get downloaded but the associated filenames in the datasets are sometimes present or missing.
I can't figure out why sometimes the filename eg "1709121722411.jpg" is present and other times is it absent in column "x_g8_x_g10_x_user_approval_photo" below. The problem comes to renaming the images. I use a loop to rename images based on other collected data using the filename, but is unable to when the filename is missing in the dataset but is present on the downloaded image file.
I know the image is downloaded for a given instance ID because when I open the image the contents of the image have an ID number. Which I can then search against a column in the downloaded dataset and find the corresponding instance ID. Also I can convert the downloaded image's filename to a date time to find the associated row in the dataset.
Any help would be great.
Thank you,
Charlie.
2. What steps can we take to reproduce this issue?
ODK Central v2024.2.1
data <- ruODK::odata_submission_get(table = frm_tbl$url[1], download = TRUE, local_dir = dwn_dir)
data_sub1 <- ruODK::odata_submission_get(table = frm_tbl$url[2], download = TRUE, local_dir = dwn_dir)
sub_data <- ruODK::odata_submission_get(table = frm_tbl$url[1], download = TRUE, local_dir = dwn_dir, parse = FALSE) %>%
ruODK::odata_submission_rectangle()
sub_data %>%
filter(x_user_approval == "active" & is.na(x_g8_x_g10_x_active_consent_image)) %>%
select(system_attachments_present, system_attachments_expected, meta_instance_id, x_g8_x_g10_x_active_consent_image)
r$> sub_data %>%
filter(x_user_approval == "active" & is.na(x_g8_x_g10_x_user_approval_photo)) %>%
select(system_attachments_present, system_attachments_expected, meta_instance_id, x_g8_x_g10_x_user_approval_photo)
filter: removed 8,006 rows (96%), 369 rows remaining
select: dropped 47 variables (x_start, x_end, x_today, x_deviceid, x_date, …)
A tibble: 369 × 4
system_attachments_present system_attachments_expected meta_instance_id x_g8_x_g10_x_user_approval_photo
<int> <int> <chr> <chr>
1 0 0 uuid:be28d31f-c224-4f90-8a1d-8b233cea8997 NA
2 1 1 uuid:8031f4b3-d4ae-4a45-958f-73015faacab3 NA
3 1 1 uuid:0b54c64c-ad02-4f4f-83c7-e28ccff323f2 NA
4 1 1 uuid:f5dde949-7c51-4685-8501-d74acaa88ccb NA
5 1 1 uuid:12612ced-1867-4f57-9006-fb0a703b6abd NA
6 1 1 uuid:9441a954-cbf5-4e83-aacf-e3f8c9b07238 NA
7 1 1 uuid:37556a60-f186-41a3-8453-b711790c8db9 NA
8 1 1 uuid:c3fd6e7d-f948-4a25-aff4-a7b637e68e51 NA
9 1 1 uuid:98d03c75-03db-4a54-9e0f-607a3dd1e36d NA
10 1 1 uuid:bdcbaf11-a5d2-4082-8148-ebe1ff375169 NA
r$> sub_data %>%
filter(x_user_approval == "active" & !is.na(x_g8_x_g10_x_user_approval_photo)) %>%
select(system_attachments_present, system_attachments_expected, meta_instance_id, x_g8_x_g10_x_user_approval_photo)
filter: removed 6,644 rows (79%), 1,731 rows remaining
select: dropped 47 variables (x_start, x_end, x_today, x_deviceid, x_date, …)
# A tibble: 1,731 × 4
system_attachments_present system_attachments_expected meta_instance_id x_g8_x_g10_x_user_approval_photo
<int> <int> <chr> <chr>
1 2 2 uuid:142e62aa-f1af-4e27-9c52-3cc618f7f64e 1726484487534.jpg
2 2 2 uuid:192969fc-c116-43d2-a9b5-5da1d82ee3cc 1726499896667.jpg
3 2 2 uuid:9a17ad87-073c-4494-9bf5-55a7e0f97add 1726499828637.jpg
4 2 2 uuid:100af8d7-3fb8-44d6-8279-d0e1a41b0d33 1726496007451.jpg
5 2 2 uuid:69c0c168-23ed-493c-a1bd-7779563e2de6 1726495871159.jpg
6 2 2 uuid:a8b72892-875a-4584-8b86-83d964704f36 1726408408018.jpg
7 2 2 uuid:5cb8c312-0fc2-404a-8688-9a4eff89e621 1726404226906.jpg
8 2 2 uuid:6046ed21-7eaf-4679-a443-913c9f13229d 1726320700107.jpg
9 2 2 uuid:b9ba2e67-393c-4f6f-8f2e-dd736b3023b5 1726320618011.jpg
10 2 2 uuid:720c5246-94bf-4941-ad6e-4e8619a904cc 1726320556408.jpg
sub_data_1 <- sub_data %>%
filter(meta_instance_id == "uuid:a6e1a0b0-6744-469c-8d9f-890c6879275f")
r$> sub_data_1 <- sub_data_1 %>%
ruODK::handle_ru_attachments(
form_schema = data_form_schema,
local_dir = dwn_dir
)
Warning message:
There were 3 warnings in `mutate()`.
The first warning was:
ℹ In argument: `x_g2_x_g3_x_g5_x_hh_consent_image = (structure(function (..., .x = ..1, .y = ..2, . = ..1) ...`.
Caused by warning in `httr::RETRY("GET", src, httr::authenticate(un, pw), httr::write_disk(pth, overwrite = TRUE), times = retries, terminate_on = c(404)) %>%
httr::warn_for_status(task = glue::glue("download media attachment {fn}.\n", "Troubleshooting tips:\n",
"* Does the file resource {fn} exist? Run in a Terminal:\n", " curl -ipu {un} {src} | cat\n",
"* Is {fn} an expected attachment of this submission? Run:\n", " curl -ipu {un} {stringr::str_replace(src, fn, \"\")}\n", ))`:
! Not Found (HTTP 404). Failed to download media attachment NA.
Troubleshooting tips:
* Does the file resource NA exist? Run in a Terminal:
curl -ipu xxxx
* Is NA an expected attachment of this submission? Run:
curl -ipu xxxx
ℹ Run `dplyr::last_dplyr_warnings()` to see the 2 remaining warnings.
r$> sessionInfo()
R version 4.3.1 (2023-06-16)
Platform: x86_64-apple-darwin20 (64-bit)
Running under: macOS Big Sur ... 10.16
Matrix products: default
BLAS: /Library/Frameworks/R.framework/Versions/4.3-x86_64/Resources/lib/libRblas.0.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.3-x86_64/Resources/lib/libRlapack.dylib; LAPACK version 3.11.0
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
time zone: Europe/London
tzcode source: internal
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] tidylog_1.1.0 lubridate_1.9.3 forcats_1.0.0 stringr_1.5.1 dplyr_1.1.4 purrr_1.0.2 readr_2.1.4 tidyr_1.3.1
[9] tibble_3.2.1 ggplot2_3.4.4 tidyverse_2.0.0
loaded via a namespace (and not attached):
[1] gtable_0.3.4 jsonlite_1.8.8 crayon_1.5.2 compiler_4.3.1 Rcpp_1.0.11 tidyselect_1.2.1 assertthat_0.2.1
[8] snakecase_0.11.1 scales_1.3.0 semver_0.2.0 R6_2.5.1 generics_0.1.3 curl_5.2.0 ruODK_1.5.0
[15] janitor_2.2.0 munsell_0.5.0 pillar_1.9.0 tzdb_0.4.0 rlang_1.1.2 utf8_1.2.4 stringi_1.8.3
[22] fs_1.6.3 timechange_0.2.0 cli_3.6.2 withr_2.5.2 magrittr_2.0.3 grid_4.3.1 hms_1.1.3
[29] clisymbols_1.2.0 lifecycle_1.0.4 vctrs_0.6.5 glue_1.6.2 fansi_1.0.6 colorspace_2.1-0 httr_1.4.7
[36] tools_4.3.1 pkgconfig_2.0.3