Skip to content

Commit 7dd058f

Browse files
committed
Adding germany and argentina scripts.
1 parent 19e77d1 commit 7dd058f

5 files changed

Lines changed: 22 additions & 10 deletions

File tree

R/argentina.R

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,11 +183,13 @@ download_argentina_data <- function(site, var_id, start_date, end_date) {
183183

184184
types_present <- unique(dt$procedimiento)
185185
if (length(types_present) <= 1) {
186-
dt <- dt[, .SD, .SDcols = c("Date", value_col)]
186+
cols <- c("Date", value_col)
187+
dt <- dt[, cols, with = FALSE]
187188
data.table::setorder(dt, Date)
188189
} else {
189190
data.table::setnames(dt, "procedimiento", "Measurement_type")
190-
dt <- dt[, .SD, .SDcols = c("Date", value_col, "Measurement_type")]
191+
cols <- c("Date", value_col, "Measurement_type")
192+
dt <- dt[, cols, with = FALSE]
191193
data.table::setorder(dt, Date, Measurement_type)
192194
}
193195

R/germany.R

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#' @return data frame of discharge time-series
1717
#' @examples
1818
#' \dontrun{
19-
#' #Note the German API currently only provides access to stage data from the previous 30 days.
19+
#' #Note the German API currently only provides access to stage data from the previous 30 days, so start and end date is ignored for this function.
2020
#' site <- "593647aa-9fea-43ec-a7d6-6476a76ae868"
2121
#' stage <- germany(site, variable = "stage")
2222
#' plot(stage$Date, stage$H, type = "l")
@@ -38,7 +38,7 @@ germany <- function(site,
3838
}
3939
param_code <- if (variable == "stage") "W" else "Q"
4040
column_name <- if (variable == "discharge") "Q" else "H"
41-
41+
latest_available=Sys.Date()
4242
end_date <- if (is.null(end_date)) Sys.Date() else as.Date(end_date)
4343

4444
# --- PEGELONLINE-specific: clamp start_date to the 30-day window --------
@@ -52,6 +52,14 @@ germany <- function(site,
5252
start_date <- earliest_available
5353
}
5454

55+
if (end_date < earliest_available|end_date>latest_available) {
56+
warning(
57+
"PEGELONLINE only retains 30 days of raw data. Requested end_date ",
58+
end_date, " is outside of data range -- clamping to ", latest_available, "."
59+
)
60+
end_date <- latest_available
61+
}
62+
5563
original_data <- try(
5664
download_germany_data(site, param_code, start_date, end_date),
5765
silent = TRUE
@@ -66,11 +74,9 @@ germany <- function(site,
6674
dt <- data.table::as.data.table(original_data)
6775
dt[, Date := as.Date(timestamp)]
6876
data.table::setnames(dt, "value", column_name)
69-
dt <- dt[Date >= start_date & Date <= end_date, .SD, .SDcols = c("Date", column_name)]
70-
# PEGELONLINE reports sub-daily (often 15-min) readings; collapse to a
71-
# daily mean so the output matches every other RivRetrieve function's
72-
# one-row-per-day convention.
73-
dt <- dt[, .(value = mean(get(column_name), na.rm = TRUE)), by = Date]
77+
78+
dt <- dt[Date>=start_date&Date<=end_date, .(value = mean(get(column_name), na.rm = TRUE)), by = Date]
79+
7480
data.table::setnames(dt, "value", column_name)
7581
data.table::setorder(dt, Date)
7682

R/sysdata.rda

40.2 KB
Binary file not shown.

data-raw/add-data.R

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
## TODO
22

33
load("data-raw/australia_sites.rda")
4+
load("data-raw/argentina_sites.rda")
45
load("data-raw/brazil_sites.rda")
56
load("data-raw/canada_sites.rda")
67
load("data-raw/chile_sites.rda")
78
load("data-raw/french_sites.rda")
9+
load("data-raw/german_sites.rda")
810
load("data-raw/ireland_sites.rda")
911
load("data-raw/japan_sites.rda")
1012
load("data-raw/quebec_sites.rda")
@@ -16,10 +18,12 @@ load("data-raw/usa_sites.rda")
1618

1719
usethis::use_data(
1820
australia_sites,
21+
argentina_sites,
1922
brazil_sites,
2023
canada_sites,
2124
chile_sites,
2225
french_sites,
26+
german_sites,
2327
ireland_sites,
2428
japan_sites,
2529
quebec_sites,

man/germany.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)