I have uploaded a first version of an R package to use the REST API to github.
Work on this package came to a halt because of higher priority COVID-related stuff, so sorry for the lack of documentation.
Overview
This is an almost complete implementation of the ODK Central REST API for R. I currently cannot continue work on it because of other priorities, so I make it available at an early alpha stage.
Features
- Uses R6 classes to implement token-controlled access to the API
- Always returns data frames
- For a slim footprint, it does not use any function of the tidyverse , but only a the absolute necessary subset
jsonlite, httr, R6, glue
. I like tidyverse function for short-lived reports, but have been bitten very often its frequent depreciations when maintaining a package on CRAN that uses the tidyverse functions. The tidyverse has well-tested functions to unnest data used in ruODK; for odkapi, it is planned to use XSLT for nested data, but these functions are not yet complete because my XSLT is rusty. - Naming is close to the function names of the online API which has excellent documentation that should be used at the current state.
- I have tried to make the functions orthogonal to those in Florian Mayer's ruODK ; this package is a lower-level complement to ruODK - see below for a comparison.
-
odkapi
has a full sets of tests against the online API, and against a mock version of the API usinghttptest
, and against a live server. Thetestlive
functions require a working server; random projects namedtestXXX
and users will be generated and deleted, so these should not interfere with your working project, but better use a dedicated test installation - there is no guarantee that nothing goes wild, and removed projects do accumulate because deleting projects is not supported in the API. - It can generate QR codes; you could steal the code for your own use.
When to use and not to use
- When you want to batch-retrieve and analyze data, use the higher-level implementation of ruODK. Most importantly, it is well tested with geo-data and images - this package was tested with text/numeric fields only. I also do not have tested
odkapi
for deeply nested data, and the XSLT-base transformation of is not yet working - XSLT specialists are welcome to work on the stubs. - ODK is very limited when you want to retrieve subsets of data, it was build mainly for batch processing; see this discussion. I have written this package as an interface to mirror the data in a local warehouse database, so that retrieving individual records with searches can be implemented.
- My application is a system for managing forms and data entry in a clinic. Since the web interface is very nerdy - even after using it for several months I need half a dozen of mis-clicks to find the place where the QR code is generated - I use the REST API to create a simplified GUI with Shiny that follows the end-user workflow.
- In theory, for small chunks of data
odkapi
might be a bit faster thanruODK
because it uses tokens instead of passwords to connect to the API server. I have not tested this, though, because it was of minor importance for me.
Missing
- Documentation and Examples. Use the ODK documentation in the API. The test code in
tests/testlive
shows usage examples and has almost complete coverage. While the API documentation is good, the returned mock data are sometimes incorrect; the live tests are more reliable. - Data returned via XSLT transformations (
test-FormsApi_Apiary.R
). Tests of these functions fail currently.
Thanks to
A first draft of the API was generated by converting the Apiary docu the swagger-codegen project. This gave a basic framework for the interface, but the generated output was unusable and had to be reworked extensively.
@florianm for his great work on ruODK; I use it heavily for batch reporting.