Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
IN-WOP
hubeau
Commits
78c8c13e
Commit
78c8c13e
authored
Aug 05, 2021
by
Dorchies David
Browse files
refactor: use internal function convert_list_to_tibble
parent
796f9e03
Changes
7
Hide whitespace changes
Inline
Side-by-side
R/doApiQuery.R
View file @
78c8c13e
...
...
@@ -86,8 +86,10 @@ doApiQuery <- function(api,
}
else
{
l
<-
httr
::
content
(
resp
,
"parsed"
)
if
(
as.numeric
(
l
$
count
)
>
20000
)
{
stop
(
"The request reach the API limitation of 20000 records.\n"
,
"Use filter arguments to reduce the number of records of your request."
)
stop
(
"The request reach the API limitation of 20000 records.\n"
,
"Use filter arguments to reduce the number of records of your request."
)
}
data
<-
c
(
data
,
l
$
data
)
if
(
resp
$
status_code
==
206
)
{
...
...
@@ -104,3 +106,24 @@ doApiQuery <- function(api,
}
return
(
data
)
}
#' Convert list provided by the API into a tibble
#'
#' @param l a [list] provided by the API
#'
#' @return a [tibble:tibble] with one row by list item and one column by list sub-item
#' @noRd
#'
convert_list_to_tibble
<-
function
(
l
)
{
l
<-
lapply
(
l
,
function
(
row
)
{
lapply
(
row
,
function
(
cell
)
{
if
(
is.null
(
unlist
(
cell
)))
NA
else
unlist
(
cell
)
})
})
return
(
purrr
::
map_df
(
l
,
tibble
::
as_tibble
))
}
R/get_indicateurs_services_communes.R
View file @
78c8c13e
...
...
@@ -32,6 +32,5 @@ get_indicateurs_services_communes <- function(params,
x
$
indicateurs
<-
NULL
x
})
l
<-
lapply
(
l
,
function
(
row
)
{
lapply
(
row
,
function
(
cell
)
{
if
(
is.null
(
unlist
(
cell
)))
NA
else
unlist
(
cell
)
})})
return
(
purrr
::
map_df
(
l
,
tibble
::
as_tibble
))
convert_list_to_tibble
(
l
)
}
R/get_indicateurs_services_indicateurs.R
View file @
78c8c13e
...
...
@@ -26,12 +26,10 @@ get_indicateurs_services_indicateurs <- function(params,
params
=
params
,
cfg
=
cfg
)
l
i
<-
lapply
(
l
,
function
(
x
)
{
l
<-
lapply
(
l
,
function
(
x
)
{
x
$
codes_commune
<-
NULL
x
$
noms_commune
<-
NULL
x
})
li
<-
lapply
(
li
,
function
(
row
)
{
lapply
(
row
,
function
(
cell
)
{
if
(
is.null
(
unlist
(
cell
)))
NA
else
unlist
(
cell
)
})})
df
<-
purrr
::
map_df
(
li
,
tibble
::
as_tibble
)
return
()
convert_list_to_tibble
(
l
)
}
R/get_prelevements_chroniques.R
View file @
78c8c13e
...
...
@@ -21,6 +21,5 @@ get_prelevements_chroniques <- function(params, cfg = config::get(file = system.
x
$
geometry
<-
NULL
x
})
l
<-
lapply
(
l
,
function
(
row
)
{
lapply
(
row
,
function
(
cell
)
{
if
(
is.null
(
unlist
(
cell
)))
NA
else
unlist
(
cell
)
})})
return
(
purrr
::
map_df
(
l
,
tibble
::
as_tibble
))
convert_list_to_tibble
(
l
)
}
R/get_prelevements_ouvrages.R
View file @
78c8c13e
...
...
@@ -23,6 +23,5 @@ get_prelevements_ouvrages <- function(params, cfg = config::get(file = system.fi
x
})
l
<-
lapply
(
l
,
function
(
row
)
{
lapply
(
row
,
function
(
cell
)
{
if
(
is.null
(
unlist
(
cell
)))
NA
else
unlist
(
cell
)
})})
return
(
purrr
::
map_df
(
l
,
tibble
::
as_tibble
))
convert_list_to_tibble
(
l
)
}
R/get_prelevements_points_prelevement.R
View file @
78c8c13e
...
...
@@ -18,6 +18,5 @@ get_prelevements_points_prelevement <- function(params, cfg = config::get(file =
params
=
params
,
cfg
=
cfg
)
l
<-
lapply
(
l
,
function
(
row
)
{
lapply
(
row
,
function
(
cell
)
{
if
(
is.null
(
unlist
(
cell
)))
NA
else
unlist
(
cell
)
})})
return
(
purrr
::
map_df
(
l
,
tibble
::
as_tibble
))
convert_list_to_tibble
(
l
)
}
man/get_prelevements_chroniques.Rd
View file @
78c8c13e
...
...
@@ -2,7 +2,7 @@
% Please edit documentation in R/get_prelevements_chroniques.R
\name{get_prelevements_chroniques}
\alias{get_prelevements_chroniques}
\title{Retrieve time series of withdrawals from
Hub'Eau API
}
\title{Retrieve time series of withdrawals from
API "Prélèvements en eau"
}
\usage{
get_prelevements_chroniques(
params,
...
...
@@ -19,7 +19,7 @@ configuration}
a \link[tibble:tibble]{tibble::tibble} with all available parameters in columns and one row by device, year and usage.
}
\description{
See the API documentation for available filter parameters: \url{https://hubeau.eaufrance.fr/page/api-prelevements-eau
#/prelevements/chronique
}
See the API documentation for available filter parameters: \url{https://hubeau.eaufrance.fr/page/api-prelevements-eau}
}
\examples{
# For retrieving the withdrawal time series of the devices located in Romilly-sur-Seine
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment