From 7bb96d6aa419d9b28051c16c6898acdbaf6af2e4 Mon Sep 17 00:00:00 2001 From: Dorchies David Date: Mon, 13 Feb 2023 10:08:35 +0100 Subject: [PATCH 1/5] feat: automatic configuration of endpoints Refs #14 --- R/sysdata.rda | Bin 2540 -> 2226 bytes data-raw/config.yml | 546 +-------------------------------------- data-raw/configuration.R | 40 +++ 3 files changed, 41 insertions(+), 545 deletions(-) diff --git a/R/sysdata.rda b/R/sysdata.rda index 1fb8e30616c480c1aa9993cccd27152f59274bb4..5f313cebee3f00565629ed3cd480261cff048405 100644 GIT binary patch literal 2226 zcmV;j2u=4wT4*^jL0KkKSuE_uO#lsV|J48g|Nqc~_)sh{)WpB{|L{Nn03Zke00H0& zUo^I`8TU5|f<#dY0nijWIP3t1B_jnqri0NmG+~s8X)CrcFIf0MIlBnq=W% z=Ts;_f(E)uNio)lwGl$pQq>eF$e;vBvIvGBwjaJD_{0vM`@uk^q$W1sS3~egEx#X3 z3#T#1hydC`2@oL>j7CC4kVzIY*<4m-jeym?0dcN*IZ;z}6!C%80mp8QP~m=^A}0hZ z@;zTpM#t3KQEHM;+Aby5%%DIE$#BFHK!p$hH6najwRADRHjB5fb8PSMWxbk+(oCzc zs)XQxQA9}wKzPOZdwwqcK7CGQvwy-20%aOXBtcIQYwol5nS`v*D7|&1r1PRAkckKd z*(KBua-b~6)-^EM$6PK|pO?6DfxiMmoV=!FC$GY-}%Rba`x)~pSfF__VaAo8ma=(}|qaPasF7oR(otTBN)%qWBW=lRR5bNU6pO0D4tb2r7s`f&>vNlnR20Q4tkC7$Sk^%}_;B zDkKC4vTlmaX2U7rxa4wYJq(2`6New4wdBHj8o)>e^H~E=Lm-jbgU0!-Mn6g+$>z$; zc#Ro4z45<_I}}=T>RR^oU$})WqQHg-ltM-y8AO7}wu&9(R4#YpRw6^?B_PILAZ%(j zlMJCHaok}HAd!P1T!jo_8JQVH5@2YjCzBVoq1}W9(Jl8WMzdClM!^tIvHX-!(Kts{NGEg+{$kah5 z4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LK`VzX5PD zyf_G)qqh9ey$)%WZvoz{YV3#w7~m zn~JWR{Om9+xRC5RP5Pdr>D?HW=&Y4j z*pkBQD6mn>*jZ9-stS9A$f_#J5sS-?Bx@B1Ke=j3yY0;#u&qQbV#k4DWDil_&G7m> z{0RJ|3*$gc&)(gQvO`>^08Uu!!g`DWhS6gwj z(i@@RLF@vV(KK-V*Fit=;(MZf>}`uV<}eG}FTb&p2}OMkbpun=_5;Vl#tG7)-V)i(GjH0Q*~XnCDdK@P$rWzT4_MJ$h1- zNYEKlR#KI$g^k07jQ0i0MKv2uepQ7?P&Fv|Z{3NOM51}Pz$rJ}zK~M` z+hIF`4 zgah7AE83JvAtW{7px`&FQ&?aMS?dNFHxXc5aGv=_sqFS#ok~a&ND{(dLssK|jZ@M@ z3c%cebS^8l5rRf6NDzWZi1~>JW$>JO9qCSvE#wv$o7N!?InW^1Fd#-j%q*?TnrXxh z`mVQFd+~Lit(4u=E#RfI-Y6M_mGF9+L^&Z}M-8Qv*)mTw_&t9eWA zsGqy9-HDazQ2C;bF&aZ@!a5QYHVGzDSXQcxV5~(5ps_|EEF~E%P*DLhVR&@MmnVKE ziHbG|tALP&k!l5TJV=a;myDuyBrQhZ)L>3o_PXJT9(OnIoad9{dHcR^Z0*cAe~oCB zg+q#PfHy@X86;#Y5(5Du5Q1b{*#QEbFa9`5o-%wTDtUg<8z$m6)h|hwv89zC&uswck&B# zdJcv`s+E%GOKvFPcNHn%mI((+Q0!TIrfyzryfc%C7`QkIIx8;#hI&?4J=*wPiO{%% ze`t8?HmLYn3)Q$bmkv6@K!qbl5G5CLHbNBgP< CL3I!S diff --git a/data-raw/config.yml b/data-raw/config.yml index 8c339be..dbef1e3 100644 --- a/data-raw/config.yml +++ b/data-raw/config.yml @@ -1,565 +1,21 @@ default: api_url: https://hubeau.eaufrance.fr/api + api_docs: api-docs user_agent: https://github.com/inrae/hubeau apis: prelevements: path: v1/prelevements - endpoints: - points_prelevement: - path: referentiel/points_prelevement - fields: - - code_bdlisa - - code_bss_point_eau - - code_commune_insee - - code_departement - - code_entite_hydro_cours_eau - - code_entite_hydro_plan_eau - - code_mer_ocean - - code_nature - - code_ouvrage - - code_point_prelevement - - code_type_milieu - - code_zone_hydro - - date_exploitation - - fields - - libelle_departement - - nappe_accompagnement - - nom_commune - - nom_point_prelevement - chroniques: - path: chroniques - fields: - - annee - - bbox - - code_commune_insee - - code_departement - - code_mode_obtention_volume - - code_ouvrage - - code_qualification_volume - - code_statut_instruction - - code_statut_volume - - code_usage - - distance - - fields - - latitude - - libelle_departement - - longitude - - nom_commune - - prelevement_ecrasant - - producteur_donnee - - volume_max - - volume_min - ouvrages: - path: referentiel/ouvrages - fields: - - bbox - - code_bdlisa - - code_commune_insee - - code_departement - - code_entite_hydro_cours_eau - - code_entite_hydro_plan_eau - - code_mer_ocean - - code_ouvrage - - code_type_milieu - - codes_points_prelevements - - date_exploitation - - distance - - fields - - latitude - - libelle_departement - - longitude - - nom_commune - - nom_ouvrage indicateurs_services: path: v0/indicateurs_services - endpoints: - communes: - path: communes - fields: - - annee - - code_commune - - code_departement - - detail_service - - fields - - type_service - indicateurs: - path: indicateurs - fields: - - annee - - code_indicateur - - fields - services: - path: services - fields: - - annee - - code_commune - - code_departement - - fields - - type_service hydrometrie: path: v1/hydrometrie - endpoints: - stations: - path: referentiel/stations - fields: - - bbox - - code_commune_station - - code_cours_eau - - code_departement - - code_region - - code_sandre_reseau_station - - code_site - - code_station - - date_fermeture_station - - date_ouverture_station - - distance - - en_service - - fields - - latitude - - libelle_cours_eau - - libelle_site - - libelle_station - - longitude - sites: - path: referentiel/sites - fields: - - bbox - - code_commune_site - - code_cours_eau - - code_departement - - code_region - - code_site - - code_troncon_hydro_site - - code_zone_hydro_site - - distance - - fields - - latitude - - libelle_cours_eau - - libelle_site - - longitude - observations_tr: - path: observations_tr - fields: - - bbox - - code_entite - - cursor - - date_debut_obs - - date_fin_obs - - distance - - fields - - grandeur_hydro - - latitude - - longitude - - timestep - obs_elab: - path: obs_elab - fields: - - bbox - - code_entite - - cursor - - date_debut_obs_elab - - date_fin_obs_elab - - distance - - fields - - grandeur_hydro_elab - - latitude - - longitude - - resultat_max - - resultat_min niveaux_nappes: path: v1/niveaux_nappes - endpoints: - chroniques: - path: chroniques - fields: - - code_bss - - date_debut_mesure - - date_fin_mesure - - fields - chroniques_tr: - path: chroniques_tr - fields: - - bbox - - bss_id - - code_bss - - date_debut_mesure - - date_fin_mesure - - fields - - niveau_ngf_max - - niveau_ngf_min - - profondeur_max - - profondeur_min - stations: - path: stations - fields: - - bbox - - bss_id - - code_bdlisa - - code_bss - - code_commune - - code_departement - - codes_masse_eau_edl - - date_recherche - - fields - - srid poisson: path: v1/etat_piscicole - endpoints: - observations: - path: observations - fields: - - code_operation - - date_operation - - etat_avancement_operation - - code_qualification_operation - - libelle_qualification_operation - - code_station - - libelle_station - - uri_station - - coordonnee_x_station - - coordonnee_y_station - - code_epsg_projection_station - - code_projection_station - - libelle_projection_station - - code_point_prelevement - - code_point_prelevement_aspe - - libelle_point_prelevement_aspe - - coordonnee_x_point_prelevement - - coordonnee_y_point_prelevement - - code_epsg_projection_point_prelevement - - code_projection_point_prelevement - - libelle_projection_point_prelevement - - lieu_dit_point_prelevement - - localisation_precise_point_prelevement - - longitude - - code_entite_hydro - - latitude - - libelle_entite_hydro - - uri_entite_hydro - - code_commune - - libelle_commune - - code_departement - - libelle_departement - - code_region - - libelle_region - - code_bassin - - libelle_bassin - - codes_dispositifs_collecte - - libelles_dispositifs_collecte - - uris_dispositifs_collecte - - protocole_peche - - objectifs_operation - - code_prelevement_elementaire - - type_prelevement_elementaire - - duree_prelevement_elementaire - - numero_passage - - type_points - - nombre_points - - nombre_points_sans_poisson - - nombre_points_facies_courant - - nombre_points_facies_plat - - nombre_points_facies_profond - - nombre_points_annexes - - nombre_points_berge - - nombre_points_chenal - - nom_ambiance - - longueur_ambiance - - largeur_ambiance - - profondeur_ambiance - - code_facies_ambiance - - libelle_facies_ambiance - - situation_ambiance - - localisation_ambiance - - classe_vitesse_courant_ambiance - - code_ombrage_ambiance - - libelle_ombrage_ambiance - - code_granulo_ambiance_dominant - - libelle_granulo_ambiance_dominant - - code_granulo_ambiance_accessoire - - libelle_granulo_ambiance_accessoire - - vegetation_ambiance - - abondance_cache_vegetation_aquatique_ambiance - - abondance_cache_embacles_ambiance - - abondance_cache_vegetation_bordure_ambiance - - abondance_cache_sous_berge_ambiance - - abondance_cache_granulo_ambiance - - observation_ambiance - - code_lot - - code_type_lot - - libelle_type_lot - - effectif_lot - - code_taxon - - code_alternatif_taxon - - nom_commun_taxon - - nom_latin_taxon - - uri_taxon - - taille_min_lot - - taille_max_lot - - type_longueur_lot - - poids_lot_mesure - - poids_lot_estime - - methode_estimation_poids_lot - - code_individu - - taille_individu - - type_longueur_individu - - mesure_individu_reelle - - poids_individu_mesure - - poids_individu_estime - - methode_estimation_poids_individu - - sexe_individu - - age_individu - - codes_pathologies_lot - - libelles_pathologies_lot - - codes_fractions_pathologies_lot - - libelles_fractions_pathologies_lot - - uris_fractions_pathologies_lot - - importances_pathologies_lot - - codes_pathologies_individu - - libelles_pathologies_individu - - codes_fractions_pathologies_individu - - libelles_fractions_pathologies_individu - - uris_fractions_pathologies_individu - - importances_pathologies_individu - - fields ecoulement: path: vbeta/ecoulement - endpoints: - stations: - path: stations - fields: - - code_station - - libelle_station - - uri_station - - code_departement - - libelle_departement - - code_commune - - libelle_commune - - code_region - - libelle_region - - code_bassin - - libelle_bassin - - coordonnee_x_station - - coordonnee_y_station - - code_projection_station - - libelle_projection_station - - code_epsg_station - - code_cours_eau - - libelle_cours_eau - - uri_cours_eau - - etat_station - - date_maj_station - - latitude - - longitude - - distance - - bbox - - fields - observations: - path: observations - fields: - - format - - code_station - - libelle_station - - code_departement - - libelle_departement - - code_commune - - libelle_commune - - code_region - - libelle_region - - code_bassin - - libelle_bassin - - code_cours_eau - - libelle_cours_eau - - code_campagne - - code_reseau - - libelle_reseau - - date_observation_min - - date_observation_max - - code_ecoulement - - libelle_ecoulement - - longitude - - latitude - - distance - - bbox - - page - - size - - fields - - accept - campagnes: - path: campagnes - fields: - - code_campagne - - date_campagne_min - - date_campagne_max - - code_type_campagne - - libelle_type_campagne - - code_reseau - - libelle_reseau - - code_departement - - libelle_departement - - page - - size - - fields - - accept hydrobio: path: v1/hydrobio - endpoints: - stations: - path: stations_hydrobio - fields: - - bbox - - code_bassin - - code_commune - - code_cours_eau - - code_departement - - code_masse_eau - - code_region - - code_sous_bassin - - code_station_hydrobio - - codes_appel_taxons - - codes_indices - - codes_reseaux - - codes_supports - - date_service - - distance - - fields - - format - - latitude - - libelle_station_hydrobio - - longitude - - page - - size - indices: - path: indices - fields: - - bbox - - code_banque_reference - - code_bassin - - code_commune - - code_cours_eau - - code_departement - - code_indice - - code_masse_eau - - code_prelevement - - code_qualification - - code_region - - code_sous_bassin - - code_station_hydrobio - - code_support - - date_debut_prelevement - - date_fin_prelevement - - distance - - fields - - format - - latitude - - libelle_indice - - longitude - - page - - resultat_indice_max - - resultat_indice_min - - size - taxons: - path: taxons - fields: - - bbox - - code_appel_taxon - - code_banque_reference - - code_bassin - - code_commune - - code_cours_eau - - code_departement - - code_indice - - code_masse_eau - - code_prelevement - - code_qualification - - code_region - - code_sous_bassin - - code_station_hydrobio - - code_support - - code_type_resultat - - codes_indices_operation - - date_debut_prelevement - - date_fin_prelevement - - distance - - fields - - format - - latitude - - longitude - - page - - size temperature: path: v1/temperature - endpoints: - station: - path: station - fields: - - bbox - - code_banque_reference - - code_bassin - - code_commune - - code_cours_eau - - code_departement - - code_eu_masse_eau - - code_masse_eau - - code_region - - code_sous_bassin - - code_station - - code_troncon_hydro - - date_debut_maj - - date_debut_mesure - - date_fin_maj - - date_fin_mesure - - distance - - exact_count - - fields - - latitude - - libelle_bassin - - libelle_commune - - libelle_cours_eau - - libelle_departement - - libelle_masse_eau - - libelle_region - - libelle_sous_bassin - - libelle_station - - longitude - - size - - type_entite_hydro - chronique: - path: chronique - fields: - - bbox - - code_banque_reference - - code_bassin - - code_commune - - code_cours_eau - - code_departement - - code_eu_masse_eau - - code_masse_eau - - code_qualification - - code_region - - code_sous_bassin - - code_station - - code_statut - - code_troncon_hydro - - date_debut_maj - - date_debut_mesure - - date_fin_maj - - date_fin_mesure - - distance - - fields - - format - - latitude - - libelle_bassin - - libelle_commune - - libelle_cours_eau - - libelle_departement - - libelle_masse_eau - - libelle_qualification - - libelle_region - - libelle_sous_bassin - - libelle_station - - libelle_statut - - longitude - - resultat_max - - resultat_min - - size - - type_entite_hydro diff --git a/data-raw/configuration.R b/data-raw/configuration.R index d6e873f..422887a 100644 --- a/data-raw/configuration.R +++ b/data-raw/configuration.R @@ -1,6 +1,46 @@ ## code to prepare `.cfg` dataset update.packages("config") +library(httr) + .cfg <- config::get(file = "data-raw/config.yml") +defineApis <- function(api, cfg) { + message("Processing API: ", api$path) + query <- file.path(cfg$api_url, api$path, cfg$api_docs) + d <- content(GET(query), as = "parsed") + sapply(c("swagger", "openapi"), function(fmt) { + if (!is.null(d[[fmt]])) { + message(fmt, " ", d[[fmt]]) + } + }) + path_endpoints <- names(d$paths) + path_endpoints <- path_endpoints[!grepl(".csv", path_endpoints, fixed = TRUE)] + endpoints <- basename(path_endpoints) + fields <- lapply(path_endpoints, function(ep) { + if(!is.null(d$paths[[ep]]$get$parameters)) { + sapply(d$paths[[ep]]$get$parameters, "[[", "name") + } + }) + l <- lapply(seq_along(endpoints), function(i) { + path <- gsub(api$path, "", path_endpoints[i]) + path <- gsub("^/+", "", path) + list(path = path, + fields = fields[[i]]) + }) + names(l) <- endpoints + return(list(path = api$path, endpoints = l)) +} + +.cfg$apis <- lapply(.cfg$apis, defineApis, cfg = .cfg) + +# Fix issue https://github.com/BRGM/hubeau/issues/127 +ecoulement_ep <- names(.cfg$apis$ecoulement$endpoints) +for (ep in ecoulement_ep) { + which_fields <- which(grepl("fields", .cfg$apis$ecoulement$endpoints[[ep]]$fields)) + .cfg$apis$ecoulement$endpoints[[ep]]$fields[which_fields] <- "fields" +} + + + usethis::use_data(.cfg, overwrite = TRUE, internal = TRUE) From 97cfc64841da074dc4e828a33bafa6c611bb1261 Mon Sep 17 00:00:00 2001 From: Dorchies David Date: Mon, 13 Feb 2023 10:10:08 +0100 Subject: [PATCH 2/5] fix(get_hydrobio): wrong endpoint name for stations_hydrobio Refs #7 --- NAMESPACE | 2 +- R/get_hydrobio.R | 10 +++++----- man/get_hydrobio.Rd | 12 ++++++------ 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/NAMESPACE b/NAMESPACE index 9a6ed41..10d991c 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -6,7 +6,7 @@ export(get_ecoulement_campagnes) export(get_ecoulement_observations) export(get_ecoulement_stations) export(get_hydrobio_indices) -export(get_hydrobio_stations) +export(get_hydrobio_stations_hydrobio) export(get_hydrobio_taxons) export(get_hydrometrie_obs_elab) export(get_hydrometrie_observations_tr) diff --git a/R/get_hydrobio.R b/R/get_hydrobio.R index ed63f41..24d5b1b 100644 --- a/R/get_hydrobio.R +++ b/R/get_hydrobio.R @@ -4,7 +4,7 @@ #' The data originate from the "NAIADES" database. #' Available endpoints are: #' -#' - `get_hydrobio_stations` retrieves site data and locations +#' - `get_hydrobio_stations_hydrobio` retrieves site data and locations #' - `get_hydrobio_indices` retrieves bioassessment indices values #' - `get_hydrobio_taxons` retrieves taxa data #' @@ -21,9 +21,9 @@ #' if(interactive()) { #' # Retrieve the hydrobiology monitoring sites in the Pays-de-Loire region #' list_params(api = "hydrobio", -#' endpoint = "stations") +#' endpoint = "stations_hydrobio") #' -#' stations_pdl <- get_hydrobio_stations( +#' stations_pdl <- get_hydrobio_stations_hydrobio( #' list(code_region = 52)) #' #' # Retrieve the hydrobiological bioassessment indices in the city of Rennes @@ -40,10 +40,10 @@ #' taxons_rennes <- hubeau::get_hydrobio_taxons( #' list(code_commune = 35051)) #' } -get_hydrobio_stations <- function(params) +get_hydrobio_stations_hydrobio <- function(params) { l <- doApiQuery(api = "hydrobio", - endpoint = "stations", + endpoint = "stations_hydrobio", params = params) select_non_nested(l) %>% diff --git a/man/get_hydrobio.Rd b/man/get_hydrobio.Rd index 1e1f0ea..21e007a 100644 --- a/man/get_hydrobio.Rd +++ b/man/get_hydrobio.Rd @@ -1,12 +1,12 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/get_hydrobio.R -\name{get_hydrobio_stations} -\alias{get_hydrobio_stations} +\name{get_hydrobio_stations_hydrobio} +\alias{get_hydrobio_stations_hydrobio} \alias{get_hydrobio_indices} \alias{get_hydrobio_taxons} \title{Retrieve data from API "Hydrobiologie"} \usage{ -get_hydrobio_stations(params) +get_hydrobio_stations_hydrobio(params) get_hydrobio_indices(params) @@ -22,7 +22,7 @@ A \link[tibble:tibble]{tibble::tibble} with one row by record and one column by The data originate from the "NAIADES" database. Available endpoints are: \itemize{ -\item \code{get_hydrobio_stations} retrieves site data and locations +\item \code{get_hydrobio_stations_hydrobio} retrieves site data and locations \item \code{get_hydrobio_indices} retrieves bioassessment indices values \item \code{get_hydrobio_taxons} retrieves taxa data } @@ -33,9 +33,9 @@ See the API documentation for available filter parameters: \url{https://hubeau.e if(interactive()) { # Retrieve the hydrobiology monitoring sites in the Pays-de-Loire region list_params(api = "hydrobio", - endpoint = "stations") + endpoint = "stations_hydrobio") -stations_pdl <- get_hydrobio_stations( +stations_pdl <- get_hydrobio_stations_hydrobio( list(code_region = 52)) # Retrieve the hydrobiological bioassessment indices in the city of Rennes From f86ce64913cf9616dd014cb0fc849af7e05d1011 Mon Sep 17 00:00:00 2001 From: Dorchies David Date: Mon, 13 Feb 2023 10:10:53 +0100 Subject: [PATCH 3/5] test: add running example for select_non_nested Refs #7 --- R/utils.R | 10 +++++++++- man/utils.Rd | 10 +++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/R/utils.R b/R/utils.R index 57b8d4b..9a2839a 100644 --- a/R/utils.R +++ b/R/utils.R @@ -9,7 +9,15 @@ #' #' @examples #' \dontrun{ -#' my_flat_list <- select_non_nested(my_nested_list) +#' l <- doApiQuery(api = "hydrobio", +#' endpoint = "stations_hydrobio", +#' params = list(code_region = 52)) +#' +#' select_non_nested(l) %>% +#' select(-code_commune, +#' -libelle_departement, +#' -(libelle_region:longitude)) %>% +#' distinct() #' } select_non_nested <- function(my_list) diff --git a/man/utils.Rd b/man/utils.Rd index bd87282..192d790 100644 --- a/man/utils.Rd +++ b/man/utils.Rd @@ -17,6 +17,14 @@ Selected the non-list elements in a nested list } \examples{ \dontrun{ -my_flat_list <- select_non_nested(my_nested_list) +l <- doApiQuery(api = "hydrobio", + endpoint = "stations_hydrobio", + params = list(code_region = 52)) + +select_non_nested(l) \%>\% + select(-code_commune, + -libelle_departement, + -(libelle_region:longitude)) \%>\% + distinct() } } From 8a2174c157a89e177f19473de4d163a6aeaf3d0d Mon Sep 17 00:00:00 2001 From: Dorchies David Date: Mon, 13 Feb 2023 10:11:23 +0100 Subject: [PATCH 4/5] chore: gitignore for R package --- .gitignore | 48 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 234f028..3ec1363 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,49 @@ -.Rproj.user +# History files .Rhistory +.Rapp.history + +# Session Data files .RData +.RDataTmp + +# User-specific files .Ruserdata -docs + +# Example code in package build process +*-Ex.R + +# Output files from R CMD build +/*.tar.gz + +# Output files from R CMD check +/*.Rcheck/ + +# RStudio files +.Rproj.user/ + +# produced vignettes +vignettes/*.html +*.pdf + +# OAuth2 token, see https://github.com/hadley/httr/releases/tag/v0.3 +.httr-oauth + +# knitr and R markdown default cache directories +*_cache/ +/cache/ + +# Temporary files created by R markdown +*.utf8.md +*.knit.md + +# R Environment Variables +.Renviron + +# pkgdown site +docs/ + +# translation temp files +po/*~ + +# RStudio Connect folder +rsconnect/ From fb3794f2a9d1b5607db9ad4baa605519bd2d2626 Mon Sep 17 00:00:00 2001 From: Dorchies David Date: Mon, 13 Feb 2023 10:11:48 +0100 Subject: [PATCH 5/5] test: test all examples in the check Refs #14 --- tests/testthat/test-run_all_examples.R | 29 ++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 tests/testthat/test-run_all_examples.R diff --git a/tests/testthat/test-run_all_examples.R b/tests/testthat/test-run_all_examples.R new file mode 100644 index 0000000..afb0d91 --- /dev/null +++ b/tests/testthat/test-run_all_examples.R @@ -0,0 +1,29 @@ +skip_on_cran() +package <- "hubeau" + +with_warnings <- c("get_hydrometrie_obs_elab") + +db <- tools::Rd_db(package) + +lapply(db, function(Rd_fun) { + tags <- tools:::RdTags(Rd_fun) + which_ex <- which(tags=="\\examples") + name <- unlist(Rd_fun[tags == "\\name"]) + if (length(which_ex) > 0) { + ex <- unlist(Rd_fun[which_ex]) + ex <- gsub("\n", "", ex) + ex <- c("interactive <- function() TRUE", ex) + file <- file.path(tempdir(), paste0(name, ".R")) + writeLines(ex, file) + test_that(paste("Examples", name, "run without error"), { + if (name %in% with_warnings) { + suppressWarnings(source(file)) + } else { + source(file) + } + expect_equal(TRUE, TRUE) + }) + } +}) + +