Open Edouard-Legoupil opened 6 years ago
@Edouard-Legoupil thanks for the suggestion and I would be happy to make a PR to add this functionality. As suggested on option is to wrap the Python API, see below:
library(reticulate)
library(tidyverse)
### Example from the github page https://github.com/OCHA-DAP/hdx-python-api#getting-started
hdx <- import("hdx")
conf <- hdx$hdx_configuration$Configuration
conf$create(hdx_site = "demo", hdx_read_only = FALSE) ### demo
### You need to follow for your CKAN API Key https://github.com/OCHA-DAP/hdx-python-api#obtaining-your-api-key
config <- conf$read()
key <- config$get_api_key()
### Function to create dataset and resource
dataset <- hdx$data$dataset$Dataset
resource <- hdx$data$resource$Resource
### Create a dataset
meta <- list(name = "iris_flower",
title = "Iris flower data set",
notes = "Typical test case for classification algorithm",
methodology = "Other",
methodology_other = "Collected by Ronald Fisher",
dataset_source = "Gondwana",
subnational = 1,
license_id = "hdx_other",
private = FALSE,
url = "http://dickoa.gitlab.io")
### We create the dataset from the dict
df <- dataset(r_to_py(meta))
### Need to add a maintainer, set org and other metadata
df$set_maintainer(key)
df$set_organization('5a63012e-6c41-420c-8c33-e84b277fdc90') ## Innago
df$set_dataset_date(as.character(Sys.Date()))
df$set_expected_update_frequency("Every two weeks")
df$add_country_location("MLI")
df$add_tags(r_to_py(list("Rstats", "test")))
### Create a resource and add it to the dataset
tmp_file <- tempfile(fileext = ".csv")
write_csv(iris, path = tmp_file)
res <- list(name = "iris.csv", format = "csv", description = "iris data csv")
res <- resource(r_to_py(res))
res$set_file_to_upload(tmp_file)
### add to the dataset
df$add_update_resource(r_to_py(res))
### Push
df$create_in_hdx()
If indicators is not classified as sensitive, the value should be pushed to an on line repository (CKAN based) such as http://data.humdata.org/
This probably requires to: