Skip to content

Commit

Permalink
docs(vignette niveaux nappes): refine and set data cache package
Browse files Browse the repository at this point in the history
Refs #42
  • Loading branch information
DDorch committed Feb 22, 2024
1 parent b79ebdc commit a26fe2d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 10 deletions.
32 changes: 24 additions & 8 deletions data-raw/vignette_example_niveaux_nappes_api.R
Original file line number Diff line number Diff line change
@@ -1,27 +1,43 @@
## code to prepare `vignette_example_niveaux_nappes_api` dataset goes here
library(hubeau)
library(dplyr)

my_water_table_code <- "GG063"

stations <- get_niveaux_nappes_stations(
codes_masse_eau_edl = my_water_table_code
)

water_table_level <- map_df(.x = stations$code_bss,
.f = function(x) get_niveaux_nappes_chroniques(code_bss = x,
date_debut_mesure = "2015-01-01"))
water_table_level <- purrr::map_df(
.x = stations$code_bss,
.f = function(x)
get_niveaux_nappes_chroniques(code_bss = x,
date_debut_mesure = "2015-01-01")
)

water_table_level <- water_table_level %>%
mutate(date_mesure = lubridate::ymd(date_mesure),
year = lubridate::year(date_mesure),
month = lubridate::month(date_mesure))

yearly_mean_water_table_level <- water_table_level %>%
group_by(code_bss,
year) %>%
summarise(n_months = n_distinct(month)) %>%
filter(n_months == 12) # complete years

vignette_example_niveaux_nappes_api <- list(
stations = stations,
water_table_level = water_table_level
)
yearly_mean_water_table_level <- yearly_mean_water_table_level %>%
select(-n_months) %>%
left_join(water_table_level) %>% # filtering join
group_by(code_bss,
year,
month) %>%
summarise(monthly_mean_water_table_level = mean(niveau_nappe_eau, na.rm = TRUE)) %>%
group_by(code_bss,
year) %>%
summarise(yearly_mean_water_table_level = mean(monthly_mean_water_table_level, na.rm = TRUE)) %>%
ungroup()

save(stations,
water_table_level,
yearly_mean_water_table_level,
file = "inst/vignettes/example_niveaux_nappes_api.RData")
Binary file modified inst/vignettes/example_niveaux_nappes_api.RData
Binary file not shown.
5 changes: 3 additions & 2 deletions vignettes/example_niveaux_nappes_api.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,10 @@ water_table_level <- water_table_level %>%
month = lubridate::month(date_mesure))
```

Selection, for each of the stations, of the years with 12 months of data. This is done to prevent incomplete time periods to influence the yearly mean water level excessively.
Selection, for each of the stations, of the years with 12 months of data.
This is done to prevent incomplete time periods to influence the yearly mean water level excessively.

```{r}
```{r, eval = FALSE}
yearly_mean_water_table_level <- water_table_level %>%
group_by(code_bss,
year) %>%
Expand Down

0 comments on commit a26fe2d

Please sign in to comment.