Skip to content

Instantly share code, notes, and snippets.

@PietrH
Created February 12, 2024 14:56
Show Gist options
  • Save PietrH/c2c5be775a54da21e8b09c947b279fb5 to your computer and use it in GitHub Desktop.
Save PietrH/c2c5be775a54da21e8b09c947b279fb5 to your computer and use it in GitHub Desktop.
frictionless datapackage.json to tibble (or csv)
datapackage_json <-
jsonlite::read_json("https://raw.githubusercontent.com/inbo/etn/main/inst/assets/datapackage.json")
datapackage_tbl <-
datapackage_json |>
purrr::chuck("resources") |>
purrr::map(
\(resource) purrr::set_names(
purrr::chuck(resource, "schema", "fields"),
purrr::chuck(resource, "name")
)
) |>
purrr::map(
\(resource) purrr::map(
resource,
~ dplyr::tibble(
name = purrr::pluck(.x, "name"),
type = purrr::pluck(.x, "type"),
resource_name = unique(names(resource))
)
)
) |>
purrr::map(purrr::list_rbind) |>
purrr::list_rbind()
@PietrH
Copy link
Author

PietrH commented Feb 12, 2024

Used for inbo/etn#290

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment