Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/galalH/riddle

Minimal Client for the UNHCR RIDL Platform
https://github.com/galalH/riddle

Last synced: 9 days ago
JSON representation

Minimal Client for the UNHCR RIDL Platform

Awesome Lists containing this project

README

        

---
title: "riddle"
output: github_document
---

This is a minimal package for programatically interacting with the [UNHCR Raw Internal Data Library (RIDL)](https://ridl.unhcr.org). 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`](https://stat.ethz.ch/R-manual/R-devel/library/datasets/html/mtcars.html) toy dataset that comes with `readr`.

```{r}
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.

```{r}
p
```

Creating a resource and attaching it to the dataset follows a similar pattern.

```{r}
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}
r
```

But so far we've only created the metadata for the resource. The next step is to upload the data.

```{r}
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.

```{r}
package_search("tests")
```

Or search for the specific file that you've uploaded:

```{r}
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.

```{r}
package_delete(p$id)
```