Setup
This section describes the setup procedure.
Authentication
The data are stored in an account on https://kf.kobotoolbox.org.
The login credentials for that account are shared among the PLAY Project staff.
To access the site’s API programmatically, an API key was downloaded and added to the local ~/.Renviron
file.
The KoBoToolBox API key is not synched to GitHub.
Set-up
To test whether the local system has the API key installed, we run the command Sys.getenv("KOBO_API_KEY")
.
Check KoBo API Key
kb_api <- Sys.getenv("KOBO_API_KEY")
if ((length(kb_api) != 1) || (!is.character(kb_api))) {
stop("'KOBO_API_KEY' not installed in .Renviron")
} else {
message("'KOBO_API_KEY' installed.")
}
## 'KOBO_API_KEY' installed.
Check Databrary credentials
The databraryr
package handles authenticating to Databrary.
For scripting access to Databrary that require authentication, it is useful to store the user’s Databrary login (email) in .Renviron
using the R command Sys.setenv(DATABRARY_LOGIN = "<email@provider.com>")
where you substitute your Databrary login (email) for <email@provider.com>
.
When this has been accomplished the following code can be run to check the status of the saved variable.
db_logon <- Sys.getenv("DATABRARY_LOGIN")
if ((length(db_logon) != 1) || (!is.character(db_logon)) || (db_logon == "")) {
stop("'DATABRARY_LOGIN' not installed in .Renviron")
} else {
message("'DATABRARY_LOGIN' installed.")
}
## 'DATABRARY_LOGIN' installed.
Install dependencies
We now use the renv
package to manage package dependencies.
Load/source helper functions
Most of the work is contained in R/functions.R
.
This is sourced when we run tar_make()
from the targets package.
We run targets::tar_make()
manually for the time being.
None of the outputs are synced to GitHub.
0.1 Approach
To make the workflow more robust and reproducible, much of the work is embedded in functions and extensive use is made of the {targets}
package.
This document describes the workflow, but none of these code chunks are executed.
We leave execution to the targets::tar_make()
function which updates components as needed.