From 82cb174e603176ded837bcd8dc63399fd1f523d4 Mon Sep 17 00:00:00 2001 From: Dorchies David <david.dorchies@inrae.fr> Date: Fri, 6 Aug 2021 12:02:10 +0200 Subject: [PATCH] feat: add get_indicateurs_services_services` Refs #4 --- NAMESPACE | 1 + R/get_indicateurs_services_services.R | 40 ++++++++++++++++++++++++ R/hubeau.R | 1 + man/get_indicateurs_services_services.Rd | 39 +++++++++++++++++++++++ man/hubeau.Rd | 1 + 5 files changed, 82 insertions(+) create mode 100644 R/get_indicateurs_services_services.R create mode 100644 man/get_indicateurs_services_services.Rd diff --git a/NAMESPACE b/NAMESPACE index ea72a59..ed1cd39 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -7,6 +7,7 @@ export(get_hydrometrie_sites) export(get_hydrometrie_stations) export(get_indicateurs_services_communes) export(get_indicateurs_services_indicateurs) +export(get_indicateurs_services_services) export(get_niveaux_nappes_chroniques) export(get_niveaux_nappes_chroniques_tr) export(get_niveaux_nappes_stations) diff --git a/R/get_indicateurs_services_services.R b/R/get_indicateurs_services_services.R new file mode 100644 index 0000000..e1a0b1d --- /dev/null +++ b/R/get_indicateurs_services_services.R @@ -0,0 +1,40 @@ +#' Retrieve performance indicators from drinking water supply and sanitation services at commune level +#' +#' See the API documentation for available filter parameters: \url{https://hubeau.eaufrance.fr/page/api-indicateurs-services} +#' +#' @template param_get_common +#' +#' @return a [tibble::tibble] with one row by commune, by service and by year and the following columns: +#' +#' - "code_service": [character] identifier of the service +#' - "nom_service": [character] name of the service +#' - "code_commune_insee": [character] identifier of the commune +#' - "nom_commune": [character] name of the commune +#' - "numero_siren ": [character] SIREN identifier of the service +#' - "type_collectivite": [character] kind of collectivity +#' - "mode_gestion": [character] management mechanism of the service +#' - "annee": [integer] year of the data +#' - The following columns are the performance indicators flagged by their respective codes. The documentation of these codes can be found at this URL: \url{https://www.services.eaufrance.fr/indicateurs/indicateurs}. +#' +#' @export +#' +#' @examples +#' # Retrieve performance indicator time series of the services in Romilly-sur-Seine +#' get_indicateurs_services_services(list(code_commune = "10323")) +#' +get_indicateurs_services_services <- function(params, + cfg = config::get(file = system.file("config.yml", + package = "hubeau"))) { + + l <- doApiQuery(api = "indicateurs_services", + operation = "services", + params = params, + cfg = cfg) + + l <- lapply(l, function(x) { + x <- c(x, x$indicateurs) + x$indicateurs <- NULL + x + }) + convert_list_to_tibble(l) +} diff --git a/R/hubeau.R b/R/hubeau.R index 847f3ef..95685a3 100644 --- a/R/hubeau.R +++ b/R/hubeau.R @@ -22,6 +22,7 @@ #' #' - [get_indicateurs_services_communes]: performance indicators by commune #' - [get_indicateurs_services_indicateurs]: performance indicators by indicator +#' - [get_indicateurs_services_services]: performance indicators by commune for each service #' #' **API "Piézométrie"** #' diff --git a/man/get_indicateurs_services_services.Rd b/man/get_indicateurs_services_services.Rd new file mode 100644 index 0000000..7b98395 --- /dev/null +++ b/man/get_indicateurs_services_services.Rd @@ -0,0 +1,39 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/get_indicateurs_services_services.R +\name{get_indicateurs_services_services} +\alias{get_indicateurs_services_services} +\title{Retrieve performance indicators from drinking water supply and sanitation services at commune level} +\usage{ +get_indicateurs_services_services( + params, + cfg = config::get(file = system.file("config.yml", package = "hubeau")) +) +} +\arguments{ +\item{params}{a \link{list} the list of parameters of the queries and their values in the format \code{list(ParamName = "Param value", ...)}, use the function \link{get_available_params} for a list of the available parameters for a given operation in an API and see the API documentation for the complete list of available filter parameters} + +\item{cfg}{a \link{config} object Configuration of the communication. Use by default the internal package +configuration} +} +\value{ +a \link[tibble:tibble]{tibble::tibble} with one row by commune, by service and by year and the following columns: +\itemize{ +\item "code_service": \link{character} identifier of the service +\item "nom_service": \link{character} name of the service +\item "code_commune_insee": \link{character} identifier of the commune +\item "nom_commune": \link{character} name of the commune +\item "numero_siren ": \link{character} SIREN identifier of the service +\item "type_collectivite": \link{character} kind of collectivity +\item "mode_gestion": \link{character} management mechanism of the service +\item "annee": \link{integer} year of the data +\item The following columns are the performance indicators flagged by their respective codes. The documentation of these codes can be found at this URL: \url{https://www.services.eaufrance.fr/indicateurs/indicateurs}. +} +} +\description{ +See the API documentation for available filter parameters: \url{https://hubeau.eaufrance.fr/page/api-indicateurs-services} +} +\examples{ +# Retrieve performance indicator time series of the services in Romilly-sur-Seine +get_indicateurs_services_services(list(code_commune = "10323")) + +} diff --git a/man/hubeau.Rd b/man/hubeau.Rd index 7182d81..1fdd9b3 100644 --- a/man/hubeau.Rd +++ b/man/hubeau.Rd @@ -29,6 +29,7 @@ Available functions: \itemize{ \item \link{get_indicateurs_services_communes}: performance indicators by commune \item \link{get_indicateurs_services_indicateurs}: performance indicators by indicator +\item \link{get_indicateurs_services_services}: performance indicators by commune for each service } \strong{API "Piézométrie"} -- GitLab