Skip to content

Commit

Permalink
bug fix in summary_temperature
Browse files Browse the repository at this point in the history
  • Loading branch information
lilyclements committed Jan 30, 2024
1 parent fe355e6 commit 89b1949
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
27 changes: 16 additions & 11 deletions R/summary_temp.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,27 @@
#' @export
#'
#' @examples #daily_niger_1 <- daily_niger %>% filter(year < 1950)
#' #summary_temperature(data = daily_niger_1, date_time = "date", station = "station_name",
#' # tmax = "tmax", tmin = "tmin", na_prop = 0.05)
#' #summary_temperature(data = daily_niger_1, date_time = "date", station = "station_name", tmax = "tmax", tmin = "tmin", na_prop = 0.05)

summary_temperature <- function(data, date_time, tmin = NULL, tmax = NULL, year = NULL,
month = NULL, station = NULL, to = c("annual", "monthly"),
summaries = c("mean", "min", "max"), na_rm = FALSE,
na_prop = NULL, na_n = NULL, na_consec = NULL, na_n_non = NULL) {
to <- match.arg(to)
summaries_all <- c()
if ("mean" %in% summaries){ summaries_all <- cbind(summaries_all, mean = "mean")}
if ("min" %in% summaries){ summaries_all <- cbind(summaries_all, min = "min")}
if ("max" %in% summaries){ summaries_all <- cbind(summaries_all, max = "max")}
climatic_summary(data = data, date_time = date_time,
station = station, elements = c(tmin, tmax),
year = year, month = month, to = to,
summaries = c(mean = "mean"), na_rm = na_rm,
na_prop = na_prop, na_n = na_n,
na_n_non = na_n_non, names = "{.fn}_{.col}")
if ("mean" %in% summaries){ summaries_all <- c(summaries_all, mean = "mean")}
if ("min" %in% summaries){ summaries_all <- c(summaries_all, min = "min")}
if ("max" %in% summaries){ summaries_all <- c(summaries_all, max = "max")}

# Use the dynamically created summaries_all in your climatic_summary function, if it's not empty
if (length(summaries_all) > 0) {
climatic_summary(data = data, date_time = date_time,
station = station, elements = c(tmin, tmax),
year = year, month = month, to = to,
summaries = summaries_all, na_rm = na_rm,
na_prop = na_prop, na_n = na_n,
na_n_non = na_n_non, names = "{.fn}_{.col}")
} else {
warning("No summaries were specified.")
}
}
3 changes: 1 addition & 2 deletions man/summary_temperature.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 89b1949

Please sign in to comment.