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.
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 serverruODK::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