knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "man/figures/README-", out.width = "100%" )
fodr is an R package to access various French Open Data portals.
Many of those portals use the OpenDataSoft platform to make their data available and this platform can be accessed with the OpenDataSoft APIs.
fodr wraps this API to make it easier to retrieve data directly in R.
The devtools package is needed to install fodr:
devtools::install_github("tutuchan/fodr")
The following portals are currently available with fodr:
library(fodr) list_portals()
The portals have been identified from the Open Data Inception website. Many of these portals do not actually contain data and a large number of them are available via the ArcGIS Open platform. This API will be supported in a future release.
Use the fodr_portal function with the corresponding fodr slug to create a FODRPortal object:
library(fodr) portal <- fodr_portal("paris") portal
The search method allows you to find datasets on this portal (see the function documentation for more information). By default, and contrary to the Open Data Soft API, all elements satisfying the search are returned.
Let's look at the datasets that contain the word vote:
list_datasets <- portal$search(q = "vote") list_datasets[[1]]
library(magrittr) list_culture_datasets <- portal$search(theme = "Culture") lapply(list_culture_datasets, function(dataset) dataset$info$metas$theme) %>% unlist() %>% unique()%>% sort()
dts <- list_datasets[[1]] dts$get_records()
dts <- list_datasets[[1]] dts$get_records(nrows = dts$info$metas$records_count, refine = list(validite = "oui"))
Some datasets have attached files in a pdf, docx, xlsx, ... format. These can be retrieved using the get_attachments method:
dts <- fodr_dataset("erdf", "coefficients-des-profils") dts$get_attachments("DictionnaireProfils_1JUIL18.xlsb")
Some datasets have geographical information on each data point.
For these datasets, two additional columns will be present when fetching records: lng and lat that correspond to the longitude and latitude of the coordinates of the data point. Additionally, if there are shapes associated to data points (polygons or linestrings for example), they will be stored in the geo_shape column either as a list of data.frames with the same two columns lng and lat or in a list sf objects if sf package is already installed.
The latter allows a straigtforward way to plot geometric data.
See for example the following dataset:
dts <- fodr_dataset("stif", "gares-routieres-idf") dfRecords <- dts$get_records(nrows = 10) dfRecords
You can then use leaflet to easily plot this data on a map, either using data points:
library(leaflet) leaflet(dfRecords) %>% addProviderTiles("CartoDB.Positron") %>% addMarkers(popup = ~gare_nom)

or using the geo_shape column:
library(sf) dfRecords[1,] %>% st_as_sf() %>% leaflet() %>% addProviderTiles("CartoDB.Positron") %>% addPolygons(label = ~gare_nom)

Most of the data is available under the Open Licence (english PDF version) but double check if you are unsure.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.