3  ruODK Setup and basic functions

3.1 Background

ruODK is a great package for interacting with ODK Central via R. Full details of how to use it are here.

To connect your ODK Central account to R, you’ll need to set up your passwords in the r.environ file so they’re not exposed in scripts. Your passwords will be stored in plain text on your r.environ so be cautious about which machines you work with this way. There’s also options to add you password manually each time, but we’ll assume you’re on a secure machine when you do this.

3.2 Add your credentials to r.environ

Run this command to open the r.environ file

usethis::edit_r_environ(scope = “user”)

Inside renviron file, be careful not to delete anything, but add these lines (substituting your ODK central URL and email address in the appropriate places.

ODKC_URL=“https://central.xxx.com”

ODKC_UN=“mustafa.orbach@xxx.com”

On a new line, add the password you use to log in to the system. Substitute xxx for your password

ODKC_PW=“xxx”

On a new line, add your password for decryption (if you use project level encryption). Substitute xxx for your password

ODKC_PP=“xxx”

Finally, save the r.environ file and restart R to load it in to R.

3.3 Using ruODK to download a data set

3.3.1 Libraries

library(ruODK)
library(tidyverse)
── Attaching packages ─────────────────────────────────────── tidyverse 1.3.2 ──
✔ ggplot2 3.4.1     ✔ purrr   1.0.1
✔ tibble  3.2.1     ✔ dplyr   1.1.0
✔ tidyr   1.3.0     ✔ stringr 1.5.0
✔ readr   2.1.4     ✔ forcats 1.0.0
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
library(knitr)

3.3.2 Connect to server

My servers are at central.lshtm.ac.uk. You need to change this to yours. Sys.getenv() pulls the passwords from the r.environ file in a way that is more secure than just adding to the script.

#connect to server
ruODK::ru_setup(
  url = "https://central.lshtm.ac.uk",
  un = Sys.getenv("ODKC_UN"),
  pw = Sys.getenv("ODKC_PW"),
  tz = "Europe/London",
  verbose = TRUE
)
<ruODK settings>
  Default ODK Central Project ID:  
  Default ODK Central Form ID:  
  Default ODK Central URL: https://central.lshtm.ac.uk 
  Default ODK Central Username: chrissy.roberts@lshtm.ac.uk 
  Default ODK Central Password: run ruODK::get_default_pw() to show 
  Default ODK Central Passphrase: run ruODK::get_default_pp() to show 
  Default Time Zone: Europe/London 
  Default ODK Central Version: 1.1 
  Default HTTP GET retries: 3 
  Verbose messages: TRUE 
  Test ODK Central Project ID:  
  Test ODK Central Form ID:  
  Test ODK Central Form ID (ZIP tests):  
  Test ODK Central Form ID (Attachment tests):  
  Test ODK Central Form ID (Parsing tests):  
  Test ODK Central Form ID (WKT tests):  
  Test ODK Central URL:  
  Test ODK Central Username:  
  Test ODK Central Password: run ruODK::get_test_pw() to show 
  Test ODK Central Passphrase: run ruODK::get_test_pp() to show 
  Test ODK Central Version: 1.1 

3.3.3 Show a list of projects

You’ll want to know the pid number, given here as id

kable(ruODK::project_list()[1:2,-9])
id name description archived key_id created_at updated_at deleted_at forms app_users datasets last_submission
37 000_Scratch_Project__Chrissy NA FALSE NA 2021-06-10 12:43:13 2022-10-21 11:38:39 NA 10 1 0 2022-10-21 11:48:21
18 000_Scratch_project__Chrissy_Sham NA FALSE 466 2021-01-27 19:27:38 2022-05-02 12:21:00 NA 19 2 0 2022-09-24 13:18:49

3.3.4 Show a list of forms that are included in the project

kable(ruODK::form_list(pid = 37))
Warning: Automatic coercion from integer to character was deprecated in purrr 1.0.0.
ℹ Please use an explicit call to `as.character()` within `map_chr()` instead.
ℹ The deprecated feature was likely used in the ruODK package.
  Please report the issue at <https://github.com/ropensci/ruODK/issues>.
name fid version state submissions created_at created_by_id created_by updated_at published_at last_submission hash
Eureka Study Consent_Online 1 open 2 2022-10-21 11:25:43 19 Chrissy h. Roberts (SA) 2022-10-21 11:58:58 2022-10-21 11:58:58 2022-10-21 11:48:21 cf910d1d93c659fe238c0a5d51d0e695
geopoint_map geopoint_map open 3 2022-07-21 11:00:49 19 Chrissy h. Roberts (SA) 2022-10-21 11:38:39 2022-07-21 13:09:42 2022-07-21 13:13:51 f0b34efc38940a990396576f4643a008
geopoint_test geopoint_test open 0 2022-06-16 12:19:45 19 Chrissy h. Roberts (SA) 2022-10-21 11:38:39 2022-06-16 12:20:55 NA dacea051c12f44b2241eb51b83157c4c
Guinée questionnaire sur l’implémentation 22 Septembre 2022 V5 Guinée questionnaire sur l’implémentation 22 Septembre 2022 V5 open 0 2022-09-22 11:42:24 19 Chrissy h. Roberts (SA) 2022-10-21 11:38:39 NA NA 15bfaa3400d9aefe5cc72171abe2a035
indexed_repeat_with_internal_cascading_select indexed_repeat_with_internal_cascading_select open 3 2022-06-09 08:35:34 19 Chrissy h. Roberts (SA) 2022-10-21 11:38:39 2022-06-09 08:36:48 2022-06-09 08:38:12 e61dbda049489bcff50d5d21603a34f0
period.diary period.diary open 0 2022-06-14 22:40:55 19 Chrissy h. Roberts (SA) 2022-10-21 11:38:39 NA NA d4ce754877a34b1ab1c66f4c0ece4f03
prepopulate.example prepopulate.example 1 open 13 2021-06-10 13:26:35 19 Chrissy h. Roberts (SA) 2022-10-21 11:38:39 2021-06-10 13:27:20 2021-06-10 13:53:25 9518e5bc127b144b11fd469684b3ac80
Social_Contact_Survey socialcontact 20192310 open 0 2022-07-20 11:36:55 19 Chrissy h. Roberts (SA) 2022-10-21 11:38:39 NA NA 0a4bc27525b822f379a5522423107270
V2_02_Test_de_grossesse V2_02_Test_de_grossesse 1907081903 open 0 2022-09-07 11:41:10 19 Chrissy h. Roberts (SA) 2022-10-21 11:38:39 NA NA 25d707ef9c7a4ea257bec37627426f60
Zim_Photos Zim_Photos open 0 2022-09-09 10:48:36 19 Chrissy h. Roberts (SA) 2022-10-21 11:38:39 2022-09-09 10:48:54 NA 118c629659e9e59d18bcbdf248019d16

3.3.5 Show details about a specific form

kable(ruODK::form_detail(pid = 37,fid = "geopoint_map"))
name fid version state submissions created_at created_by_id created_by updated_at published_at last_submission hash
geopoint_map geopoint_map open 3 2022-07-21T10:00:49.605Z 19 Chrissy h. Roberts (SA) 2022-10-21T10:38:39.291Z 2022-07-21T12:09:42.248Z 2022-07-21T12:13:51.306Z f0b34efc38940a990396576f4643a008

3.3.6 Show a list of submissions to a specific form

kable(ruODK::submission_list(pid = 37,fid = "geopoint_map"))
instance_id submitter_id device_id created_at updated_at review_state submitter_id_2 submitter_type submitter_display_name submitter_created_at submitter_updated_at submitter_deleted_at
uuid:0a671884-27ed-4eb8-9102-310149899678 1094 collect:v2m4bt3bE9ZfeMfi 2022-07-21 13:13:51 2022-09-15 11:08:57 NA 1094 field_key chrissy 2021-11-03 12:44:28 NA NA
uuid:9f6a1fd4-3394-4e5a-b013-e344272cdf70 1094 collect:v2m4bt3bE9ZfeMfi 2022-07-21 13:13:24 NA NA 1094 field_key chrissy 2021-11-03 12:44:28 NA NA
uuid:0a65e09e-18e5-4fd3-bbe8-4c57529ccc89 1094 collect:v2m4bt3bE9ZfeMfi 2022-07-21 13:11:19 NA NA 1094 field_key chrissy 2021-11-03 12:44:28 NA NA

3.3.7 Pull submissions

ruODK is very powerful and can get quite complicated. The most basic thing you need is a dataframe with your submissions. Here’s how to get one.

df<-ruODK::odata_submission_get(pid = "37",fid="geopoint_map")

3.3.8 Show data

kable(df[,1:4])
geopoint_longitude geopoint_latitude geopoint_altitude geopoint_accuracy
-0.054687 52.07809 0 0
152.504487 -32.18187 0 0
152.526883 -32.20085 0 0