Note: necessary packages are: tidyverse, ruODK, leaflet, Hmisc, lubridate

Setting up the ruODK connection

Note: obviously you need to de-comment the pw = "your_password_here" field. I am not showing it for obvious reasons.

ruODK::ru_setup(
    url = "https://odk.idradata.org",
    svc = "https://odk.idradata.org/v1/projects/1/forms/odk_training_lesson_BR.svc",
    un = "mfilipski@uga.edu",
    # pw = "your_password_here",
    tz = "America/New_York",
    pid = "1", # Default project
    fid = "Nepal_filters", # Make Nepal the default
    verbose = TRUE # Shows all the params, no need here
)

Extract the data

Tou can extract metadata about the project or the forms:

proj <- project_list()
proj_detail <- project_detail()
form_list <- form_list()
#knitr::kable(form_list)
form_detail <- form_detail()
knitr::kable(form_detail)
name fid version state submissions created_at created_by_id created_by updated_at last_submission hash
Nepal_filters Nepal_filters 2020043001 open 5 2020-05-01T00:59:14.182Z 17 Edward Whitney 2020-05-01T00:59:39.920Z 2020-05-01T01:04:35.972Z 3407bbe9d7e502801cad9433cc039b81

The name of our form is Nepal_filters

You can also extract specific tables (or what is called “repeats” in ODK). There is only one table right now - there will be more later.

form_tables <- odata_service_get()  # This is for default from only
#knitr::kable(form_tables)

Here’s code to extract the actual data:

# ruODK::ru_setup(fid = "Nepal_filters") # in case changed default
data_nepal <- odata_submission_get()

# Make some data conversions and some new variables
# Note: all filters are "character" vectors right now - maybe not preferred
df_nepal <- as.data.frame(data_nepal, stringAsFactor=TRUE)
df_nepal <- mutate(df_nepal, 
                   longitude = loc_coordinates_14,
                   latitude = loc_coordinates_15)

Map of the submissions

Note that you can click on a submission to see some information about it. We can customize that.

leaflet(df_nepal) %>% addTiles() %>% 
    addMarkers(popup=paste(df_nepal$system_submitter_name, as.Date(df_nepal$start), sep="; "))

Percent responses on Filter questions

nepal_means <- df_nepal %>%
    select(starts_with("filter")) %>%
    mutate_if(is.character,as.numeric) %>%
    summarise_all(list(mean), na.rm=TRUE) 
colnames(nepal_means) <- c("Grew crops",
                "Raised livestock",
                "Farmed fish",
                "Worked for pay",
                "Owned a business", 
                "Engaged in fishing")

Percent in the sample who:

Grew crops Raised livestock Farmed fish Worked for pay Owned a business Engaged in fishing
0.4 0.4 0.4 0.4 0.6 0.2