| Title: | Tools to Download and Explore Datasets from Data.gouv.fr |
| Version: | 0.1.0 |
| Description: | Provides a client for the public API of data.gouv.fr, the French government's open data platform. It helps you find a dataset that matches your interests, judge whether it is usable, download it, and re-fetch the exact same table later in a reproducible way. You can search the catalog and filter by producer or theme (dg_find_datasets(), dg_find_organization(), dg_find_topics()), pull a dataset's tabular resources into tidy tibbles (dg_pull_dataset()), inspect the documented variables of its data schema (dg_schema()), and compute summary metrics such as size, number of columns and missing-value rate (dg_summary(), dg_summarise()). Each returned table carries a stable identifier (dg_table_id(), dg_refetch()) so it can be re-fetched later. Requests are built on top of 'httr2'. |
| License: | MIT + file LICENSE |
| URL: | https://astamm.github.io/rdatagouv/, https://github.com/astamm/rdatagouv |
| BugReports: | https://github.com/astamm/rdatagouv/issues |
| Encoding: | UTF-8 |
| VignetteBuilder: | quarto |
| Config/Quarto/version: | >= 1.4 |
| Imports: | cli, httr2, jsonlite, nanoparquet, readxl, tibble, vroom |
| Suggests: | dplyr, gt, knitr, pkgdown, quarto, testthat (≥ 3.0.0), withr, writexl |
| Config/testthat/edition: | 3 |
| Config/roxygen2/version: | 8.1.0 |
| NeedsCompilation: | no |
| Packaged: | 2026-09-03 11:05:38 UTC; stamm-a |
| Author: | Magali Berland [aut],
Pierre Gloaguen [aut],
Arthur Leroy [aut],
Mahendra Mariadassou [aut],
Cédric Midoux [aut],
Jean-François Rey [aut],
Aymeric Stamm |
| Maintainer: | Aymeric Stamm <aymeric.stamm@cnrs.fr> |
| Repository: | CRAN |
| Date/Publication: | 2026-09-12 14:20:02 UTC |
rdatagouv: Tools to download and explore datasets from the French open data platform
Description
This package provides a small client for the public API of
data.gouv.fr, the French government's open data
platform. It lets you list the published datasets, download their tabular
resources and compute summary metrics (file weight, number of columns,
missing-value rates, ...). Requests are built on top of the httr2 package.
Author(s)
Maintainer: Aymeric Stamm aymeric.stamm@cnrs.fr (ORCID)
Authors:
Aymeric Stamm aymeric.stamm@cnrs.fr (ORCID)
Magali Berland magali.berland@inrae.fr
Pierre Gloaguen pierre.gloaguen@univ-ubs.fr
Arthur Leroy arthur.leroy@inrae.fr
Mahendra Mariadassou mahendra.mariadassou@inrae.fr
Cédric Midoux cedric.midoux@inrae.fr
Jean-François Rey jean-francois.rey@inrae.fr
See Also
Useful links:
Report bugs at https://github.com/astamm/rdatagouv/issues
Find datasets available on data.gouv.fr
Description
Collects the datasets published on the data.gouv.fr platform, searching the
catalog via the v2 datasets/search endpoint (the same one the web
interface uses). By default it returns the first n datasets; use q to
search titles and descriptions server-side instead of enumerating the whole
catalog.
Usage
dg_find_datasets(
q = NULL,
n = 1000,
format = catalog_formats(),
schema_only = FALSE,
organization = NULL,
geozone = NULL,
access_type = NULL,
license = NULL,
tag = NULL,
topic = NULL,
granularity = NULL,
last_update = NULL,
producer_type = NULL,
resources = FALSE
)
Arguments
q |
Optional full-text search query. When given, only datasets
matching |
n |
Maximum number of datasets to return. Defaults to |
format |
Optional character vector of resource formats to keep. Only
datasets that have at least one resource in one of these formats are
returned. The v2 API matches multiple values when passed as repeated
parameters (a server-side union). Defaults to the full set of officially
tabular formats ( |
schema_only |
Whether to keep only datasets that declare a data schema
(see |
organization |
Optional data producer, matched server-side. Pass either
the producer's 24-hex |
geozone |
Optional territorial filter, passed as a territory code of
the form |
access_type |
Optional access filter. One of |
license |
Optional license filter, one of the exhaustive license slugs
|
tag |
Optional tag filter. Tags form an open vocabulary (dynamic
facets), so any free-form tag such as |
topic |
Optional topic filter, the 24-hex |
granularity |
Optional spatial granularity filter, one of the
exhaustive values |
last_update |
Optional update-recency filter, one of |
producer_type |
Optional producer-type filter, one of the exhaustive
values |
resources |
Whether to fetch each dataset's resources subsection
(one extra request per dataset) so the exact |
Details
Fetching every dataset on the platform means paging through many thousands
of records in many HTTP requests and is both slow and fragile, so the
default is deliberately bounded. Set n = Inf to return as many matches as
the API allows. Note that data.gouv caps a search at 10,000 matches, so an
un-narrowed n = Inf crawl stops at that cap even though the platform holds
more. For large or infinite n the crawl scales its page size up (to ~250)
so a full 10,000-row crawl takes ~40 requests, not hundreds.
Because v2 search embeds rich per-dataset metadata inline, the returned
tibble includes columns such as license, quality_score, views,
access_type, frequency, temporal_start/temporal_end, archived and
featured that help judge whether a dataset is worth pulling.
v2 search does NOT inline each dataset's resources (they are subsection
pointers), so the exact resource-based columns n_resources, formats,
has_table and has_schema can no longer be computed without one extra
request per dataset (an N+1 crawl). By default these are NA; set
resources = TRUE to opt into the per-dataset resource fetch and fill them
exactly.
Value
A tibble::tibble() with one row per matching dataset. The
title and id columns are always non-NA; the id column holds the
stable, unique dataset identifier used to address a dataset with
dg_pull_dataset(). When resources = TRUE, the columns also include
n_resources (number of files/resources), formats (a list-column
whose elements are the distinct file formats found among them), has_table
(whether at least one resource is
in a format this package can parse) and has_schema (whether at least one
resource carries a pointer to a declared data schema, whose per-variable
documentation is exposed by dg_schema()); these are NA when
resources = FALSE (the default) unless schema_only = TRUE, which forces
the fetch so has_schema is filled and the filter can run.
Examples
datasets <- dg_find_datasets(n = 20)
head(datasets)
# Search server-side instead of downloading the whole catalog.
cycle <- dg_find_datasets(q = "vélo", n = 10)
# Only datasets that carry at least one parquet resource; the v2 API matches
# multiple formats as a server-side union.
compact <- dg_find_datasets(format = "parquet", n = 10)
# Only datasets with a declared schema (documented variables). `schema_only`
# forces the per-dataset resource fetch itself (~30s for n = 1000), so
# `resources = TRUE` is optional here.
documented <- dg_find_datasets(schema_only = TRUE, n = 10)
# Narrow by producer and territory. A producer may be given by its 24-hex
# id or by its exact slug/name (resolved for you), and by geozone.
fr <- dg_find_datasets(organization = "sncf",
geozone = "country:fr", n = 10)
# Only datasets grouped under one topic (find its id with dg_find_topics()).
mob <- dg_find_topics(q = "mobilité")
dg_find_datasets(topic = mob$id[1], n = 10)
Search for organizations (data producers) on data.gouv.fr
Description
Searches the platform's producers via the v2 organizations/search endpoint
and returns a tibble with one row per matching organization, including its
stable 24-hex id. That id is exactly what you pass to the organization
argument of dg_find_datasets() to restrict a catalog search to one
producer — or, more conveniently, you can pass a producer's exact name or
slug to dg_find_datasets() directly and it is resolved for you (see
dg_find_datasets()).
Usage
dg_find_organization(q = NULL, n = 20)
Arguments
q |
Optional full-text query matched against organization names,
descriptions, etc. (server-side). Defaults to |
n |
Maximum number of organizations to return. Defaults to |
Details
Useful when you want to discover which producers exist, how a producer's name is spelled, or how many datasets it publishes — before narrowing a search.
Value
A tibble::tibble() with one row per matching organization and
columns:
-
id— the stable, unique 24-hex producer id (passable to theorganizationargument ofdg_find_datasets()). Always non-NA. -
name— the producer's display name. -
slug— the URL-friendly slug. -
acronym— the acronym, orNA. -
description— the producer's description. -
datasets— number of datasets the producer currently publishes. -
badges— comma-joined badge kinds (e.g."public-service, certified"), orNA. -
business_number_id— the French SIREN identifier when known, elseNA.
Examples
# Who publishes rail/mobility data? (server-side ranked search)
orgs <- dg_find_organization(q = "SNCF")
orgs[, c("id", "name", "datasets")]
# Use the resolved id to narrow a catalog search to one producer.
data_gouv <- dg_find_organization(q = "data.gouv")
open_data <- dg_find_datasets(organization = data_gouv$id[1], n = 5)
Find topics (themes) on data.gouv.fr
Description
Searches the platform's themes via the v2 topics/search endpoint and
returns a tibble with one row per matching topic, including its stable
24-hex id. That id is what you pass to the topic argument of
dg_find_datasets() to restrict a catalog search to one theme. (data.gouv
does not resolve topic names/slugs to ids inside dg_find_datasets(), so
this finder is the way to discover a theme and get its id.)
Usage
dg_find_topics(q = NULL, n = 20, elements = FALSE)
Arguments
q |
Optional full-text query matched against topic names/descriptions
(server-side). Defaults to |
n |
Maximum number of topics to return. Defaults to |
elements |
Whether to fetch each topic's |
Details
Useful when you want to discover which curated themes exist and how many elements (datasets, reuses, dataservices...) they group, before narrowing a search — e.g. browse "Mobilité", "Environnement", "Énergie".
Value
A tibble::tibble() with one row per matching topic and columns:
-
id— the stable, unique 24-hex topic id (passable to thetopicargument ofdg_find_datasets()). Always non-NA. -
name— the topic's display name. -
slug— the URL-friendly slug. -
description— the topic's description. -
tags— comma-joined tags, orNA. -
featured— whether the platform features this topic. -
n_elements— number of elements (datasets, reuses, dataservices, ...) grouped under the topic, from the API. -
n_datasets,n_dataservices,n_reuses— per-kind counts, only whenelements = TRUE(elseNA).
Examples
# Browse the curated themes.
dg_find_topics(n = 5)[, c("id", "name", "n_elements")]
# Narrow a catalog search to one theme once you have its id.
mob <- dg_find_topics(q = "mobilité")
dg_find_datasets(topic = mob$id[1], n = 10)
Glimpse the metadata of a dataset on data.gouv.fr
Description
Surfaces the dataset-level health and engagement metadata that the v2 API
embeds inline but the v1 fetch path does not expose — the bridge between
discover (dg_find_datasets()) and judge (dg_schema()'s column
documentation). It reports the dataset's quality score and flags, its
metrics (views, downloads, followers, ...) and its context
(organization, license, frequency, temporal/spatial coverage, access type),
helping a user decide whether a dataset is worth pulling.
Usage
dg_glimpse(id, table = NULL)
Arguments
id |
A dataset identifier (24-hex), a composed table id, or a table
returned by |
table |
Whether to also include the dataset's list of resources (from
the v2 resources subsection, one extra request per dataset). |
Details
id composes naturally with the rest of the package: it may be a dataset id
(24-hex), a composed table id or a pulled table (whose id attribute is
read), so a dataset discovered or pulled elsewhere can be glimpsed directly.
Value
A list with the v2-inline metadata:
-
quality: a list withscore(0-1) and boolean flags (license,temporal_coverage,spatial,update_frequency,dataset_description_quality). -
metrics: views, resources_downloads, followers, discussions, reuses, dataservices. -
context: organization (name/slug/id), license, frequency, temporal_coverage, spatial/granularity, access_type, archived, featured. -
resources(only whentable = TRUE): the list of resource objects.
Examples
g <- dg_glimpse("6a6be5976a05df136d48fb7a")
g$quality
g$metrics
Return the parsing problems of a downloaded table
Description
Returns the data frame of parsing issues that vroom
encountered while reading a table downloaded with dg_pull_dataset() or
dg_refetch(). These are vroom's "parsing issues" (rows that could not be
converted to the inferred column type, e.g. a mostly-padded ISO date column
holding a few non-padded values like 2021-7-01).
Usage
dg_problems(x)
Arguments
x |
A table returned by |
Details
The noisy per-cell warnings themselves are suppressed by default during a
pull; use this accessor to inspect what happened. The problems live in the
rdatagouv_problems attribute of the table. Returns NULL when the table
carries no recorded problems (or when x is an ordinary data frame).
Value
A data frame with columns row, col, expected and actual
(one row per parsing issue), or NULL if there were none.
Examples
dg_problems(iris)
Download a dataset from data.gouv.fr
Description
Downloads the first tabular resource of a dataset and parses it into a
tibble::tibble() with format_tibble(). The dataset is identified by its
id, which is the stable, unique identifier returned in the id column of
dg_find_datasets(). For backwards compatibility, an exact title is also
accepted and is resolved by searching the platform.
Usage
dg_pull_dataset(
id,
all_files = FALSE,
remove_na = FALSE,
col_types = NULL,
use_tabular_types = TRUE
)
Arguments
id |
The identifier of the dataset to download (or, as a fallback, its exact title). Identifiers are unique and stable, so they are the recommended way to address a dataset; titles can collide or change over time. |
all_files |
Whether to return one table per parseable file as a named
list instead of a single tibble. Defaults to |
remove_na |
Whether to drop rows containing any |
col_types |
Optional named vector of column types to force on specific
columns instead of letting vroom infer them, e.g.
|
use_tabular_types |
Whether to seed column types from data.gouv's
tabular API profile ( |
Details
By default a single tibble is returned: the first resource that can actually
be parsed as a table (for a multi-file ZIP, the first parseable file). The
table's stable, unique address is attached as an id attribute, readable
with dg_table_id() and accepted directly by dg_refetch() and
dg_schema(). Set all_files = TRUE to instead receive one table per
parseable file as a named list (useful for a ZIP holding several files).
Value
A tibble::tibble() (default) or, when all_files = TRUE and the
resource is a multi-file ZIP, a named list of tibbles (one element per
parseable file, named after it). Every table carries its stable, unique
address as an id attribute — a URI of the form
https://www.data.gouv.fr/datasets/<dataset_id>#<resource_id> (plus
/<file> for a file inside a ZIP) — re-fetchable with dg_refetch()
and readable with dg_table_id(). Any parsing issues vroom encountered are
attached as an rdatagouv_problems attribute (a data frame), readable with
dg_problems().
Examples
id <- "6397c0ff56d3963118a18345"
tbl <- dg_pull_dataset(id)
head(tbl)
dg_table_id(tbl)
Re-fetch a single parsed table by its stable address
Description
Downloads again the exact table addressed by a table URI, stored as an id
attribute on the tables returned by dg_pull_dataset() and readable with
dg_table_id(). The URI is built from the platform's own stable identifiers
(dataset id + resource id, plus the file name inside a ZIP) and opens the
dataset page in a browser, so this reproducibly returns the same table,
independent of the human-readable list keys.
Usage
dg_refetch(x, remove_na = FALSE, col_types = NULL, use_tabular_types = TRUE)
Arguments
x |
Either a table returned by |
remove_na |
Whether to drop rows containing any |
col_types |
Optional named vector of column types to force on specific
columns instead of letting vroom infer them, e.g.
|
use_tabular_types |
Whether to seed column types from data.gouv's
tabular API profile, as in |
Value
A tibble::tibble() — the single re-fetched table (the id addresses
one table, not a multi-file ZIP as a whole). The table's id is attached as
an id attribute; parsing issues are attached as an rdatagouv_problems
attribute, readable with dg_problems().
Examples
tbl <- dg_pull_dataset("6397c0ff56d3963118a18345")
again <- dg_refetch(tbl)
Documented schema of a parsed table's columns
Description
Returns the declared data schema of a table's columns: the per-variable
fields recorded by the dataset producer. Because data.gouv attaches a schema
only as a pointer (schema$name / schema$url), this resolves that pointer
against schema.data.gouv.fr and returns the
human-readable column documentation (name, title, description, type)
that the schema carries — the information needed to judge whether a variable
really means what a statistical exploration assumes.
Usage
dg_schema(x)
Arguments
x |
Either a table returned by |
Details
This is a supplement to dg_pull_dataset(): the table itself comes from the
main API; the schema is read from the producer's declared data specification.
Only resources that carry a schema pointer have documentation; resources
without one return NULL with a message. Use dg_find_datasets() (column
has_schema, or the schema_only argument) to target schema-documented
tables in the first place.
Value
A tibble::tibble() with one row per column and the columns name,
title, description, type and example (where the schema provides
them; absent entries are NA), or NULL (with a message) if the resource
has no declared schema. The schema's own title and name are attached as
the attributes schema_title and schema_name.
Examples
tbl <- dg_pull_dataset("62c5961ff0013fb71d7278e3")
dg_schema(tbl)
Summarise several datasets
Description
Applies dg_summary() to a collection of tables and combines the resulting
metrics into a single tibble. If datasets is NULL, the first n datasets
returned by dg_find_datasets() are downloaded and summarised.
Usage
dg_summarise(datasets = NULL, n = 100)
Arguments
datasets |
Either a named list of tibbles (each element is a single
table, named after it), a named list of such lists (as returned by
|
n |
Number of datasets to summarise when |
Value
A tibble::tibble() with one row per table and the columns
described in dg_summary().
Examples
# Summarise in-memory tables (no network needed).
dg_summarise(datasets = list(iris = iris, mtcars = mtcars))
# Download and summarise the first datasets of the catalog.
dg_summarise()
Compute summary metrics for a dataset
Description
Computes key metrics describing a parsed dataset: its in-memory weight in kilobytes, the number of variables, the number of numeric and non-numeric variables, the number of rows and the proportion of missing values.
Usage
dg_summary(x, name = NULL)
Arguments
x |
A data frame or tibble (a single table, e.g. one element of the
list returned by |
name |
An optional label attached to the result (e.g. the dataset
title). When |
Value
A tibble::tibble() with a single row and the following columns:
dataset, size_kb, n_vars, n_numeric, n_non_numeric, n_rows
and prop_missing.
Examples
dg_summary(iris, name = "iris")
Read a table's stable address
Description
Returns the stable, unique address of a table downloaded with
dg_pull_dataset() or dg_refetch(), which is stored as an id attribute
on the table. The address is a URI of the form
https://www.data.gouv.fr/datasets/<dataset_id>#<resource_id> (plus
/<file> for a file inside a ZIP) and uniquely identifies a table on
the platform, independent of the human-readable catalog titles. It can be
passed directly to dg_refetch() or dg_schema() to re-fetch or document
that exact table.
Usage
dg_table_id(x)
Arguments
x |
A table returned by |
Value
The composed table id, a string, or NULL if x carries no id
attribute (e.g. an ordinary data frame).
Examples
tbl <- dg_table_id(iris)