Skip to content

Instantly share code, notes, and snippets.

@dickoa
Created February 10, 2023 15:52
Show Gist options
  • Save dickoa/b59235cfe1fb16ebb4cb17508343fd23 to your computer and use it in GitHub Desktop.
Save dickoa/b59235cfe1fb16ebb4cb17508343fd23 to your computer and use it in GitHub Desktop.
List of dataset per region in RIDL including year of creation of each dataset
library(tidyverse)
library(ridl)
library(lubridate)
### Targeted region
region <- "west-and-central-africa"
### List all containers
ct_nm <- rc_list()
### Get all containers with the region in his hierarchy
ct_hierarchy_nm <- lapply(ct_nm, ridl_container_hierarchy_list) ## super slow
### Filter for element with the region name in it
lgl <- vapply(ct_hierarchy_nm, \(l) region %in% l, TRUE)
### Get the list all containers from region and include region itself
wca_ct_nm <- c(ct_nm[lgl], region)
qry <- paste0("organization:",
"(", paste(wca_ct_nm,
collapse = " or "),
")")
all_datasets <- rd_search(qry, rows = 1000)
all_datasets <- all_datasets |>
as_tibble()
### Resource min year of creation
rd_resource_min_year <- function(x) {
min(vapply(rd_resource_get_all(x),
\(r) lubridate::year(r$data$created), numeric(1)))
}
all_datasets <- mutate(all_datasets,
resource_min_year = map_dbl(dataset, rd_resource_min_year))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment