| Title: | Access the 'data.europa.eu' European Open Data Portal |
|---|---|
| Description: | Search, retrieve and download open data from the European data portal <https://data.europa.eu> through its Search API, Registry API and SPARQL endpoint. Returns data frames of datasets, distributions and facets. |
| Authors: | Nigel Randsley [aut, cre] |
| Maintainer: | Nigel Randsley <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.1 |
| Built: | 2026-11-28 01:22:26 UTC |
| Source: | https://github.com/randsley/dataeuropa |
Cached: dataset records (de_get_dataset(), de_distributions()), the catalogue list
(de_catalogues()), and searches with limit = 0 (de_facet_values(), de_count()). Other
searches, SPARQL and file downloads are never cached.
de_cache_on(dir = NULL, ttl = NULL) de_cache_off() de_clear_cache()de_cache_on(dir = NULL, ttl = NULL) de_cache_off() de_clear_cache()
dir |
Cache folder. Defaults to |
ttl |
How long a response stays valid, in seconds. Defaults to |
The cache is off unless de_cache_on() is called or the environment variable
DATAEUROPA_CACHE=1 is set. de_cache_off() turns it off for the session; cached files stay
until de_clear_cache().
de_cache_on(): the cache folder, invisibly. de_cache_off(): NULL, invisibly.
de_clear_cache(): the number of responses deleted.
de_cache_on(dir = file.path(tempdir(), "dataeuropa-cache"), ttl = 3600) de_clear_cache() de_cache_off()de_cache_on(dir = file.path(tempdir(), "dataeuropa-cache"), ttl = 3600) de_clear_cache() de_cache_off()
Ids of all harvested catalogues
de_catalogues()de_catalogues()
A character vector of catalogue ids.
head(de_catalogues())head(de_catalogues())
Number of hits for a query (no records transferred)
de_count(q = NULL, ...)de_count(q = NULL, ...)
q |
Free-text query. |
... |
Passed to |
An integer.
de_count(country = "pt") de_count("water", format = "CSV")de_count(country = "pt") de_count("water", format = "CSV")
One row per distribution. The url column is the download URL if present, otherwise the
access URL. The kind column says what each one is: "file", "service" (WMS, WFS, APIs,
feeds), "page" (a web page), "none" (no usable URL, e.g. a localhost placeholder) or
"unknown".
de_distributions(id, lang = "en", files_only = FALSE)de_distributions(id, lang = "en", files_only = FALSE)
id |
Dataset id as shown in search results. |
lang |
Preferred language. |
files_only |
Keep only distributions whose |
A data frame with one row per distribution: id, title, format, media_type,
byte_size, checksum, checksum_algorithm, license, modified, download_url,
access_url, url and kind. An empty data frame when the dataset has none.
files <- de_distributions("6689f1686e4bd9bc98ed011b", files_only = TRUE) files[, c("title", "format", "kind")]files <- de_distributions("6689f1686e4bd9bc98ed011b", files_only = TRUE) files[, c("title", "format", "kind")]
If the row has a checksum (checksum and checksum_algorithm; MD5, SHA-1 or SHA-256), the
file is checked against it. On a mismatch the file is deleted and an error is raised;
verify = FALSE skips the check. byte_size is not checked: on the portal it is often a
placeholder (0, 1, 1024).
de_download(x, dest, verify = TRUE, resume = TRUE, max_bytes = NULL)de_download(x, dest, verify = TRUE, resume = TRUE, max_bytes = NULL)
x |
A URL, or a one-row data frame from |
dest |
A file path, or an existing directory to save the file in under its own name.
Required: nothing is written to the working directory unless you pass it (e.g. |
verify |
Check the file against the row's checksum, if it has one. |
resume |
Continue an interrupted download of the same URL to the same place. |
max_bytes |
Stop a download that is (or is announced as) larger than this, delete the partial file and raise an error. Default: no limit. |
The file is written as <file>.part and renamed when complete. If a download is interrupted,
calling de_download() again for the same URL and destination continues where it stopped, when
the server supports ranges and identifies the file (ETag or Last-Modified); a file that changed
meanwhile is downloaded again from the start. resume = FALSE always starts from the start.
The local path, invisibly.
files <- de_distributions("6689f1686e4bd9bc98ed011b", files_only = TRUE) path <- de_download(files[files$title == "QA_2024_Q1", ], tempdir()) file.size(path)files <- de_distributions("6689f1686e4bd9bc98ed011b", files_only = TRUE) path <- de_download(files[files$title == "QA_2024_Q1", ], tempdir()) file.size(path)
Values and counts of a facet
de_facet_values(facet, q = NULL, top = 50, ...)de_facet_values(facet, q = NULL, top = 50, ...)
facet |
e.g. "country", "format", "categories", "catalog", "publisher". |
q |
Free-text query. |
top |
Keep the |
... |
Passed to |
A data frame with columns id, label and count, most frequent first.
de_facet_values("format", country = "pt", top = 10)de_facet_values("format", country = "pt", top = 10)
Fetch many datasets with the scroll API
de_fetch_datasets( q = NULL, ..., max_results = 1000, page_size = 500, lang = "en", raw = FALSE )de_fetch_datasets( q = NULL, ..., max_results = 1000, page_size = 500, lang = "en", raw = FALSE )
q |
Free-text query. |
... |
Passed to |
max_results |
Stop after this many records. |
page_size |
Records per request (max 1000). |
lang |
Language for titles/descriptions. |
raw |
Return the raw list of records instead of a data frame. |
A data frame with the columns of de_search_datasets(), one row per dataset, or with
raw = TRUE a list of the raw records. At most max_results either way.
ds <- de_fetch_datasets(country = "pt", max_results = 2500, page_size = 1000) # three requests nrow(ds)ds <- de_fetch_datasets(country = "pt", max_results = 2500, page_size = 1000) # three requests nrow(ds)
Full metadata for one dataset
de_get_dataset(id, raw = FALSE, lang = "en")de_get_dataset(id, raw = FALSE, lang = "en")
id |
Dataset id as shown in search results. |
raw |
If |
lang |
Preferred language. |
A list with summary (a one-row data frame with the columns of
de_search_datasets()), keywords (a character vector) and raw (the record as a nested
list). With raw = TRUE, the record alone.
d <- de_get_dataset("6689f1686e4bd9bc98ed011b") d$summary$title d$summary[, c("publisher", "modified", "formats")]d <- de_get_dataset("6689f1686e4bd9bc98ed011b") d$summary$title d$summary[, c("publisher", "modified", "formats")]
Dataset metadata as RDF text
de_get_rdf(id, fmt = c("ttl", "jsonld"))de_get_rdf(id, fmt = c("ttl", "jsonld"))
id |
Dataset id. |
fmt |
"ttl" (Turtle) or "jsonld". |
The RDF document as a single string.
ttl <- de_get_rdf("6689f1686e4bd9bc98ed011b") cat(substr(ttl, 1, 500))ttl <- de_get_rdf("6689f1686e4bd9bc98ed011b") cat(substr(ttl, 1, 500))
Reads CSV and JSON; XLSX with the readxl package and Parquet with the arrow package (both
optional). The format comes from format if given ("csv", "json", "xlsx", "parquet"),
else from the row's format id, its media type, then the URL's file extension.
de_load_distribution(x, format = NULL, sheet = NULL)de_load_distribution(x, format = NULL, sheet = NULL)
x |
A URL, or a one-row data frame from |
format |
Override the detected format: "csv", "json", "xlsx" or "parquet". |
sheet |
XLSX sheet name or 1-based index (default: the first sheet). |
CSV: the delimiter (, ; tab |) is taken from the header line, text is read as UTF-8 with
a Latin-1 fallback, only empty cells count as missing, and dates stay text. JSON: an array of
objects, or an object holding exactly one such array; keys become columns.
Stops with an error for services (WMS, WFS, APIs), compressed archives, HTML pages served
instead of data, formats it cannot tell or read, and files that fail their checksum (see
de_download()).
A data frame.
files <- de_distributions("6689f1686e4bd9bc98ed011b", files_only = TRUE) qa <- de_load_distribution(files[files$title == "QA_2024_Q1", ]) head(qa)files <- de_distributions("6689f1686e4bd9bc98ed011b", files_only = TRUE) qa <- de_load_distribution(files[files$title == "QA_2024_Q1", ]) head(qa)
Needs the sf package. GDAL does the reading, so any vector format it knows works: GeoJSON,
Shapefile, GeoPackage, KML/KMZ, GML, GPX, MapInfo TAB, FlatGeobuf, file geodatabase. The
geometry column is always called geometry.
de_load_geodata( x, layer = NULL, crs = NULL, max_mb = 200, max_features = 10000 )de_load_geodata( x, layer = NULL, crs = NULL, max_mb = 200, max_features = 10000 )
x |
A URL, or a one-row data frame from |
layer |
A layer by name or 1-based position, in files with several (GeoPackage, file geodatabase). Default: the first, with a message if there are more. |
crs |
Reproject to this coordinate reference system, e.g. |
max_mb |
Do not download files larger than this many megabytes; |
max_features |
Read at most this many features from a service, with a warning when there
are more; |
ZIP archives (how shapefiles are published) are opened in place. Inside, the one geodata file is
read (a .shp with its .dbf/.shx/.prj, .gpkg, .geojson, .kml, .gml, .gpx, .tab, .fgb, or a .gdb
folder); if there are several, layer picks one by file name (without extension), otherwise an
error lists them. Archives inside archives are not opened.
The source coordinate reference system is kept; a file without one (a shapefile without .prj) is read as stored, with a warning.
Feature services are read too: WFS (service=WFS URLs, WFS format ids) and OGC API Features
(collection or landing-page URLs, OGCFEAT format ids). GDAL pages through the results. Each
collection or feature type is a layer.
Raises an error for other services (WMS, ...), web pages, HTML served instead of data, files or services GDAL cannot read, and checksum mismatches.
An sf data frame.
dists <- de_distributions("eac1e504-9d63-4670-95b3-3ef04e22aa6e~~1") districts <- de_load_geodata(dists[dists$format == "OGCFEAT", ]) sf::st_crs(districts)$epsgdists <- de_distributions("eac1e504-9d63-4670-95b3-3ef04e22aa6e~~1") districts <- de_load_geodata(dists[dists$format == "OGCFEAT", ]) sf::st_crs(districts)$epsg
{lang: text} list to one stringCollapse a multilingual {lang: text} list to one string
de_pick_lang(x, lang = "en")de_pick_lang(x, lang = "en")
x |
A named list of translations (or a string). |
lang |
Preferred language code; falls back to English, then any. |
A character scalar, or NA_character_.
de_pick_lang(list(de = "Wasser", en = "Water"), lang = "de") de_pick_lang(list(de = "Wasser", en = "Water"), lang = "fr") # falls back to English de_pick_lang(list(pt = "Qualidade do ar")) # else any languagede_pick_lang(list(de = "Wasser", en = "Water"), lang = "de") de_pick_lang(list(de = "Wasser", en = "Water"), lang = "fr") # falls back to English de_pick_lang(list(pt = "Qualidade do ar")) # else any language
Returns the result object of the Search API as a nested list
(count, results, facets, ...).
de_search( q = NULL, filters = "dataset", facets = NULL, limit = 10, page = 0, sort = NULL, country = NULL, catalog = NULL, format = NULL, license = NULL, category = NULL, publisher = NULL, keywords = NULL, hvd = NULL, min_date = NULL, max_date = NULL, date_type = NULL, bbox = NULL, aggregation = FALSE, extra = list() )de_search( q = NULL, filters = "dataset", facets = NULL, limit = 10, page = 0, sort = NULL, country = NULL, catalog = NULL, format = NULL, license = NULL, category = NULL, publisher = NULL, keywords = NULL, hvd = NULL, min_date = NULL, max_date = NULL, date_type = NULL, bbox = NULL, aggregation = FALSE, extra = list() )
q |
Free-text query. |
filters |
Document type: "dataset" (default), "catalogue", "dataservice", "resource"... |
facets |
Named list of facet filters, e.g. |
limit |
Results per page (0-1000). |
page |
Zero-based page. |
sort |
e.g. |
country, catalog, format, license, category, publisher, keywords, hvd
|
Convenience facet filters.
|
min_date, max_date, date_type
|
Date range; |
bbox |
Numeric |
aggregation |
Return facet counts? |
extra |
Named list of additional raw query parameters. |
With limit = 0 the result can come from the response cache (see de_cache_on()).
The result object of the response, a nested list with count, results (the
records), facets when aggregation = TRUE, and scrollId in scroll mode.
res <- de_search("air quality", country = "pt", limit = 5) res$count de_pick_lang(res$results[[1]]$title)res <- de_search("air quality", country = "pt", limit = 5) res$count de_pick_lang(res$results[[1]]$title)
Accepts all arguments of de_search(). Total hits are in attr(x, "count").
de_search_datasets(q = NULL, ..., lang = "en")de_search_datasets(q = NULL, ..., lang = "en")
q |
Free-text query. |
... |
Passed to |
lang |
Language for titles/descriptions. |
A data frame with one row per dataset: id, title, description, country,
catalog, publisher, issued, modified, formats, n_distributions, is_hvd,
quality_score, landing_page and portal_url. The total number of hits is in
attr(x, "count").
ds <- de_search_datasets("air quality", country = "pt", format = "CSV", limit = 5) ds[, c("id", "title", "formats")] attr(ds, "count")ds <- de_search_datasets("air quality", country = "pt", format = "CSV", limit = 5) ds[, c("id", "title", "formats")] attr(ds, "count")
Run a SPARQL query against data.europa.eu
de_sparql(query)de_sparql(query)
query |
SPARQL SELECT or ASK text. |
A data frame of plain string values (SELECT) or a logical (ASK).
de_sparql("SELECT ?d WHERE { ?d a <http://www.w3.org/ns/dcat#Dataset> } LIMIT 3")de_sparql("SELECT ?d WHERE { ?d a <http://www.w3.org/ns/dcat#Dataset> } LIMIT 3")