This is a minimal package for programatically interacting with the UNHCR Raw Internal Data Library (RIDL). Its scope and API are deliberately kept minimal for ease of use. The main purpose served by this package really is to make the RIDL API documentation just a little bit more readily accessible.
To use the package, you'll need to store your RIDL API key in the RIDL_API_KEY
environment variable. The easiest way to do that is by calling usethis::edit_r_environ()
and adding the line RIDL_API_KEY=xxxxx
to the file before saving and restarting your R session.
The package works with both the production and UAT instances of RIDL. To use the UAT version, run Sys.setenv(USE_UAT=1)
before calling any functions from the package. To go back to the production instance, call Sys.unsetenv("USE_UAT")
.
Following is a brief illustration of how to use the package using the mtcars
toy dataset that comes with readr
.
library(riddle) Sys.setenv(USE_UAT=1) m <- package_metadata(title = "Motor Trend Car Road Tests", name = "mtcars", notes = "The data was extracted from the 1974 Motor Trend US magazine, and comprises fuel consumption and 10 aspects of automobile design and performance for 32 automobiles (1973–74 models).", owner_org = "exercise-container", visibility = "public", external_access_level = "open_access", data_collector = "Motor Trend", keywords = keywords[c("Environment", "Other")], unit_of_measurement = "car", data_collection_technique = "oth", archived = "False") p <- package_create(m)
The return value is a representation of the dataset we just created in RIDL that you could inspect like any other R object.
p
Creating a resource and attaching it to the dataset follows a similar pattern.
m <- resource_metadata(type = "data", url = "mtcars.csv", name = "mtcars.csv", format = "csv", file_type = "microdata", date_range_start = "1973-01-01", date_range_end = "1973-12-31", version = "1", process_status = "raw", identifiability = "anonymized_public") r <- resource_create(p$id, m)
Like before, the return value is a tibble representation of the resource.
r
But so far we've only created the metadata for the resource. The next step is to upload the data.
resource_upload(r$id, path = system.file("extdata/mtcars.csv", package = "readr"))
Et voila! You should be able to find your data on RIDL now.
You could also search for the dataset from the R console directly.
package_search("tests")
Or search for the specific file that you've uploaded:
resource_search("name:mtcars")
And once we're done experimenting with the API, we should take down our toy dataset since we don't really need it on RIDL.
package_delete(p$id)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.