diff --git a/DESCRIPTION b/DESCRIPTION index 232f334..62d0272 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -15,8 +15,9 @@ RoxygenNote: 7.3.2 Imports: colorRamps, data.table, - distillery, + databook, dplyr, + distillery, extRemes, fields, forcats, @@ -40,4 +41,5 @@ Imports: tidyselect, zoo Remotes: + IDEMSInternational/databook, IDEMSInternational/instatExtras \ No newline at end of file diff --git a/NAMESPACE b/NAMESPACE index 582d0cd..f7da66f 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -13,10 +13,8 @@ export(convert_yy_to_yyyy) export(cumulative_inventory) export(dd_to_dms) export(fourier_series) -export(get_default_significant_figures) export(ggwalter_lieth) export(import_from_iri) -export(make_factor) export(other_rose_plots) export(output_CPT) export(plot_declustered) diff --git a/R/climdex.R b/R/climdex.R index 5f6d10b..656983d 100644 --- a/R/climdex.R +++ b/R/climdex.R @@ -1,7 +1,6 @@ -#' Calculate climate indices +#' Calculate Climate Indices #' -#' @description -#' This function calculates climate indices based on temperature and precipitation data. +#' @description This function calculates climate indices based on temperature and precipitation data. #' #' @param data A data frame containing the temperature and precipitation data. #' @param station The name of the column in the data frame that represents the station. diff --git a/R/climdex_single_station.R b/R/climdex_single_station.R index 9310f5e..2957e1f 100644 --- a/R/climdex_single_station.R +++ b/R/climdex_single_station.R @@ -1,7 +1,5 @@ - -#' climdex_single_station -#' @description -#' This function calculates climate indices for a single weather station based on the provided parameters. The function utilizes the climdex.pcic package to compute various climate indices. The indices can be calculated either on an annual or monthly basis, depending on the specified frequency. +#' Climdex Single Station +#' @description This function calculates climate indices for a single weather station based on the provided parameters. The function utilizes the climdex.pcic package to compute various climate indices. The indices can be calculated either on an annual or monthly basis, depending on the specified frequency. #' #' @param ci #' The climate data for the weather station. @@ -36,8 +34,6 @@ #'#data <- read.csv("climate_data.csv") #'#climdex_single_station(data, freq = "annual", indices = c("fd", "su"), #'# year = "Year") - - climdex_single_station <- function(ci, freq = "annual", indices, year, month, spells.can.span.years = FALSE, gsl.mode = gsl.mode, threshold = 1) { @@ -91,5 +87,4 @@ climdex_single_station <- function(ci, freq = "annual", indices, year, month, if (indices[[i]] == "rnnmm") names(df_ind)[ncol(df_ind)] <- paste(indices[[i]], threshold, sep = "_") } return(df_ind) -} - +} \ No newline at end of file diff --git a/R/climdexpcic_functions.R b/R/climdexpcic_functions.R index e215923..b176b08 100644 --- a/R/climdexpcic_functions.R +++ b/R/climdexpcic_functions.R @@ -9,7 +9,7 @@ valid.climdexInput <- function(object) { present.data.vars <- names(object@data) length.check.slots <- c("dates", "jdays") length.check.members <- c("date.factors", "data") - data.lengths <- c(sapply(object@data, length), sapply(length.check.slots, function(y) length(slot(object, y))), unlist(sapply(length.check.members, function(y) { sapply(slot(object, y), length) }))) + data.lengths <- c(sapply(object@data, length), sapply(length.check.slots, function(y) length(methods::slot(object, y))), unlist(sapply(length.check.members, function(y) { sapply(methods::slot(object, y), length) }))) quantiles <- list(tmax=temp.quantiles, tmin=temp.quantiles, prec=prec.quantiles) if(!all(data.lengths == max(data.lengths))) @@ -129,11 +129,11 @@ valid.climdexInput <- function(object) { #' library(PCICt) #' #' ## Parse the dates into PCICt. -#' tmax.dates <- as.PCICt(do.call(paste, ec.1018935.tmax[,c("year", +#' tmax.dates <- PCICt::as.PCICt(do.call(paste, ec.1018935.tmax[,c("year", #' "jday")]), format="%Y %j", cal="gregorian") -#' tmin.dates <- as.PCICt(do.call(paste, ec.1018935.tmin[,c("year", +#' tmin.dates <- PCICt::as.PCICt(do.call(paste, ec.1018935.tmin[,c("year", #' "jday")]), format="%Y %j", cal="gregorian") -#' prec.dates <- as.PCICt(do.call(paste, ec.1018935.prec[,c("year", +#' prec.dates <- PCICt::as.PCICt(do.call(paste, ec.1018935.prec[,c("year", #' "jday")]), format="%Y %j", cal="gregorian") #' #' ## Load the data in. @@ -160,36 +160,44 @@ setClass("climdexInput", #' @description #' This function creates a climdexInput object from data already ingested into #' R. -#' -#' @details -#' This function takes input climate data at daily resolution, and produces as -#' output a ClimdexInput data structure. This data structure can then be passed -#' to any of the routines used to compute the Climdex indices. The indices -#' themselves are specified on the webpage cited in the references section. -#' The \code{base.range} argument is a pair of 4 digit years which bound the -#' data on which the base percentiles are calculated. -#' -#' The \code{tmax}, \code{tmin}, and \code{prec} arguments are numeric vectors -#' containing the data on which the indices are to be computed. The units are -#' assumed to be degrees C for temperature, and mm/day for precipitation. #' -#' The \code{tmax.dates}, \code{tmin.dates}, and \code{prec.dates} arguments -#' are vectors of type \code{PCICt}. -#' -#' The \code{n} argument specifies the size of the window used when computing -#' the percentiles used in \code{\link{climdex.tx10p}}, -#' \code{\link{climdex.tn10p}}, \code{\link{climdex.tx90p}}, and -#' \code{\link{climdex.tn90p}}. -#' -#' The \code{northern.hemisphere} argument specifies whether the data came from +#' @param tmax numeric vector containing the data on which the indices are to be computed. (degrees C) +#' @param tmin numeric vector containing the data on which the indices are to be computed. (degrees C) +#' @param prec numeric vector containing the data on which the indices are to be computed. (mm/day) +#' @param tmax.dates vector of type \code{PCICt} of the maximum date. +#' @param tmin.dates vector of type \code{PCICt} of the minimum date. +#' @param prec.dates vector of type \code{PCICt} of the precipitation date. +#' @param base.range a pair of 4 digit years which bound the data on which the base percentiles are calculated. +#' @param n the size of the window used when computing the percentiles used in \code{\link{climdex.tx10p}}, +#' \code{\link{climdex.tn10p}}, \code{\link{climdex.tx90p}}, and \code{\link{climdex.tn90p}}. +#' @param northern.hemisphere whether the data came from #' the northern hemisphere. If FALSE, data is assumed to have come from the #' southern hemisphere. This is used when computing growing season length; if #' the data is from the southern hemisphere, growing season length is the #' growing season starting in the beginning of July of the year indicated, #' running to the end of June of the following year. +#' @param tavg Average temperature, default `NULL` +#' @param tavg.dates Average temperature dates, default `NULL` +#' @param quantiles supply pre-computed quantiles. This is a list consisting of quantiles for each variable. +#' @param temp.qtiles modify the quantiles calculated. For example, specifying +#' temp.qtiles=c(0.10, 0.50, 0.90) would calculate the 10th, 50th, and 90th +#' percentiles for temperature. +#' @param prec.qtiles modify the quantiles calculated. +#' @param max.missing.days vector consisting of 'annual' +#' (the number of days that can be missing in a year), 'monthly' (the +#' number of days that can be missing in a month and 'seasonal' (the +#' number of days that can be missing in a season. If one month in a year fails +#' the test, the corresponding year will be omitted. +#' @param min.base.fraction.present the minimum fraction +#' of data which must be present for a quantile to be calculated for a +#' particular day. If the fraction of data present is less than this threshold, +#' the quantile for that day will be set to NA. #' -#' The \code{quantiles} argument allows the user to supply pre-computed quantiles. -#' This is a list consisting of quantiles for each variable. +#' @details +#' This function takes input climate data at daily resolution, and produces as +#' output a ClimdexInput data structure. This data structure can then be passed +#' to any of the routines used to compute the Climdex indices. The indices +#' themselves are specified on the webpage cited in the references section. #' #' For each temperature variable, there are separate lists of quantiles for #' inbase and outbase, with these names. In both cases, quantiles within these @@ -204,33 +212,18 @@ setClass("climdexInput", #' #' For precipitation variables, there is a named vector of quantiles, consisting #' of at least q95 and q99. -#' -#' The \code{temp.qtiles} and \code{prec.qtiles} arguments allow the user to -#' modify the quantiles calculated. For example, specifying -#' temp.qtiles=c(0.10, 0.50, 0.90) would calculate the 10th, 50th, and 90th -#' percentiles for temperature. -#' -#' The \code{min.base.fraction.present} argument specifies the minimum fraction -#' of data which must be present for a quantile to be calculated for a -#' particular day. If the fraction of data present is less than this threshold, -#' the quantile for that day will be set to NA. -#' -#' The \code{max.missing.days} argument is a vector consisting of 'annual' -#' (the number of days that can be missing in a year), 'monthly' (the -#' number of days that can be missing in a month and 'seasonal' (the -#' number of days that can be missing in a season. If one month in a year fails -#' the test, the corresponding year will be omitted. #' #' @seealso \code{\link{climdex.pcic-package}}, \code{\link{strptime}}. -#' @references \url{http://etccdi.pacificclimate.org/list_27_indices.shtml} #' @keywords ts climate +#' @references For Climdex Indices: \url{http://etccdi.pacificclimate.org/list_27_indices.shtml} +#' This function is from the `pacificclimate/climdex.pcic` repository. +#' The `climdex.pcic` package was developed and maintained by the Pacific Climate Impacts Consortium (PCIC). +#' For more information, visit the repository: +#' Special thanks to the contributors of the `climdex.pcic` package for their efforts in climate data analysis. #' -#' @param northern.hemisphere Whether this point is in the northern hemisphere. -#' @param quantiles Threshold quantiles for supplied variables. -#' @param max.missing.days Vector containing thresholds for number of days -#' allowed missing per year (annual), per month (monthly) and per season (seasonal). #' @return An object of class \code{\link{climdexInput-class}} for use with #' other climdex methods. +#' #' @note Units are assumed to be mm/day for precipitation and degrees Celsius #' for temperature. No units conversion is performed internally. #' @@ -241,23 +234,17 @@ setClass("climdexInput", #' ## ready to go. #' #' ## Parse the dates into PCICt. -#' tmax.dates <- as.PCICt(do.call(paste, ec.1018935.tmax[,c("year", +#' tmax.dates <- PCICt::as.PCICt(do.call(paste, ec.1018935.tmax[,c("year", #' "jday")]), format="%Y %j", cal="gregorian") -#' tmin.dates <- as.PCICt(do.call(paste, ec.1018935.tmin[,c("year", +#' tmin.dates <- PCICt::as.PCICt(do.call(paste, ec.1018935.tmin[,c("year", #' "jday")]), format="%Y %j", cal="gregorian") -#' prec.dates <- as.PCICt(do.call(paste, ec.1018935.prec[,c("year", +#' prec.dates <- PCICt::as.PCICt(do.call(paste, ec.1018935.prec[,c("year", #' "jday")]), format="%Y %j", cal="gregorian") #' #' ## Load the data in. #' ci <- climdexInput.raw(ec.1018935.tmax$MAX_TEMP, #' ec.1018935.tmin$MIN_TEMP, ec.1018935.prec$ONE_DAY_PRECIPITATION, #' tmax.dates, tmin.dates, prec.dates, base.range=c(1971, 2000)) -#' -#' @references This function is from the `pacificclimate/climdex.pcic` repository. -#' The `climdex.pcic` package was developed and maintained by the Pacific Climate Impacts Consortium (PCIC). -#' For more information, visit the repository: -#' Special thanks to the contributors of the `climdex.pcic` package for their efforts in climate data analysis. -#' #' @export climdexInput.raw <- function(tmax=NULL, tmin=NULL, prec=NULL, tmax.dates=NULL, tmin.dates=NULL, prec.dates=NULL, base.range=c(1961, 1990), n=5, northern.hemisphere=TRUE, @@ -271,11 +258,11 @@ climdexInput.raw <- function(tmax=NULL, tmin=NULL, prec=NULL, tmax.dates=NULL, t cal <- attr(all.dates, "cal") ## Convert base range (in years) to PCICt - bs.date.range <- as.PCICt(paste(base.range, c("01-01", last.day.of.year), sep="-"), cal=cal) + bs.date.range <- PCICt::as.PCICt(paste(base.range, c("01-01", last.day.of.year), sep="-"), cal=cal) bs.date.series <- seq(bs.date.range[1], bs.date.range[2], by="day") ## Get dates for normal data - new.date.range <- as.PCICt(paste(as.numeric(format(range(all.dates), "%Y", tz="GMT")), c("01-01", last.day.of.year), sep="-"), cal=cal) + new.date.range <- PCICt::as.PCICt(paste(as.numeric(format(range(all.dates), "%Y", tz="GMT")), c("01-01", last.day.of.year), sep="-"), cal=cal) date.series <- seq(new.date.range[1], new.date.range[2], by="day") jdays <- get.jdays.replaced.feb29(get.jdays(date.series)) @@ -379,7 +366,7 @@ climdexInput.raw <- function(tmax=NULL, tmin=NULL, prec=NULL, tmax.dates=NULL, t quantiles <- as.environment(quantiles) } - return(new("climdexInput", data=filled.list, quantiles=quantiles, namasks=namasks, dates=date.series, jdays=jdays, base.range=bs.date.range, date.factors=date.factors, northern.hemisphere=northern.hemisphere, max.missing.days=max.missing.days)) + return(methods::new("climdexInput", data=filled.list, quantiles=quantiles, namasks=namasks, dates=date.series, jdays=jdays, base.range=bs.date.range, date.factors=date.factors, northern.hemisphere=northern.hemisphere, max.missing.days=max.missing.days)) } ## Get the last month and day of the year as a character sting, separated by the specified separator. @@ -398,6 +385,11 @@ get.years <- function(dates) { return(as.POSIXlt(dates)$year + 1900) } +## Get month number +get.months <- function(dates) { + return(as.POSIXlt(dates)$mon + 1) +} + ## Juggle the list so that day 366 == day 365 get.jdays.replaced.feb29 <- function(jdays) { indices <- which(jdays == 366) @@ -408,10 +400,10 @@ get.jdays.replaced.feb29 <- function(jdays) { ## Converts a positional index with respect to some origin into a PCICt object in the format %Y-%m-%d. ymd.dates <- function(origin, cal, exact.day, val) { - origin.pcict <- as.PCICt(origin, cal) + origin.pcict <- PCICt::as.PCICt(origin, cal) seconds.per.day <- 86400 exact.day.pcict <- origin.pcict + (ifelse(is.na(exact.day),1,exact.day - 1)) * seconds.per.day - ymd <- as.PCICt(exact.day.pcict, cal = cal, format = "%Y-%m-%d") + ymd <- PCICt::as.PCICt(exact.day.pcict, cal = cal, format = "%Y-%m-%d") ymd <- format(ymd, "%Y-%m-%d") ymd[is.na(val)] <- NA return(ymd) @@ -564,14 +556,14 @@ zhang.running.qtile <- function(x, dates.base, qtiles, bootstrap.range, include. bs.data <- x[inset] qdat <- NULL - if(get.bootstrap.data) { - d <- .Call("running_quantile_windowed_bootstrap", bs.data, n, qtiles, dpy, min.fraction.present, PACKAGE='climdex.pcic') - dim(d) <- c(dpy, nyears, nyears - 1, length(qtiles)) - qdat <- lapply(1:length(qtiles), function(x) { r <- d[,,,x, drop=FALSE]; dim(r) <- dim(r)[1:3]; r }) - } else { + #if(get.bootstrap.data) { + # d <- .Call("running_quantile_windowed_bootstrap", bs.data, n, qtiles, dpy, min.fraction.present, PACKAGE='climdex.pcic') + # dim(d) <- c(dpy, nyears, nyears - 1, length(qtiles)) + # qdat <- lapply(1:length(qtiles), function(x) { r <- d[,,,x, drop=FALSE]; dim(r) <- dim(r)[1:3]; r }) + #} else { res <- running.quantile(bs.data, n, qtiles, dpy, min.fraction.present) qdat <- lapply(1:length(qtiles), function(x) { res[,x] }) - } + #} names(qdat) <- paste("q", qtiles * 100, sep="") return(qdat) } @@ -588,7 +580,7 @@ get.temp.var.quantiles <- function(filled.data, date.series, bs.date.series, qti get.prec.var.quantiles <- function(filled.prec, date.series, bs.date.range, qtiles=c(0.95, 0.99)) { wet.days <- !(is.na(filled.prec) | filled.prec < 1) inset <- date.series >= bs.date.range[1] & date.series <= bs.date.range[2] & !is.na(filled.prec) & wet.days - pq <- quantile(filled.prec[inset], qtiles, type=8) + pq <- stats::quantile(filled.prec[inset], qtiles, type=8) names(pq) <- paste("q", qtiles * 100, sep="") return(pq) } @@ -608,6 +600,18 @@ compute.stat <- function(ci, stat, data.key, freq = c("monthly", "annual", "seas return(suppressWarnings(tapply.fast(data, date.factors, stat, na.rm = TRUE)) * mask) } +## Returns an n-day running quantile for each day of data (dimensions c(dpy, q)) +running.quantile <- function(data, n, q, dpy, min.fraction) { + ret <- .Call("running_quantile_windowed", data, n, q, dpy, min.fraction, PACKAGE='climdex.pcic') + dim(ret) <- c(length(q), dpy) + return(t(ret)) +} + +## Get number of days within range +get.num.days.in.range <- function(x, date.range) { + return(sum(x >= date.range[1] & x <= date.range[2])) +} + ## Helper function to extract parameters for rxnday indices. get.rxnday.params <- function(ci, freq= c("monthly", "annual", "seasonal")) { stopifnot(!is.null(ci@data$prec)) @@ -728,7 +732,7 @@ spell.length.max <- function(daily.prec, date.factor, threshold, op, spells.can. start <- end - max.spell origin <- paste(names(max.spell), "01", "01", sep = "-") - origin.pcict <- as.PCICt(origin, cal) + origin.pcict <- PCICt::as.PCICt(origin, cal) seconds.per.day <- 86400 start.pcict <- origin.pcict + start * seconds.per.day end.pcict <- origin.pcict + (end - 1) * seconds.per.day @@ -775,4 +779,114 @@ running.mean <- function(vec, bin){ means = cumsum(means)/bin # apply precomputed differences means = c(rep(NA,left.bin), means, rep(NA,right.bin)) # extend to original vector length return(means) +} + +## Simple Precipitation Intensity Index +simple.precipitation.intensity.index <- function(daily.prec, date.factor) { + return(tapply.fast(daily.prec, date.factor, function(prec) { idx <- prec >= 1 & !is.na(prec); if(sum(idx) == 0) { return(0); } else { return(sum(prec[idx], na.rm=TRUE) / sum(idx)) } } )) +} + +## DTR +## Computes mean diurnal temperature range in each period (as specified by date.factor). +## Max and min temps are assumed to be same length +compute.mean.daily.temp.range <- function(daily.max.temp, daily.min.temp, date.factor) { + dat <- tapply.fast(daily.max.temp - daily.min.temp, date.factor, mean, na.rm=TRUE) + dat[is.nan(dat)] <- NA + dat +} + +## Flexible GSL function - This function computes the growing season length (GSL) given the input, +## which is allowed to vary considerably from the ETCCDI definitions. +growing.season.length <- function(daily.mean.temp, date.factor, dates, northern.hemisphere, + min.length = 6, t.thresh = 5, gsl.mode = c("GSL", "GSL_first", "GSL_max", "GSL_sum"), include.exact.dates = FALSE, cal) { + gsl.mode <- match.arg(gsl.mode) + month.series <- get.months(dates) + transition.month <- if (northern.hemisphere) 7 else 1 + if (gsl.mode == "GSL") { + growing.season <- (tapply.fast(1:length(daily.mean.temp), date.factor, function(idx) { + temp.data <- daily.mean.temp[idx] + ts.mid <- utils::head(which(month.series[idx] == transition.month), n = 1) + if (!length(ts.mid)) { + return(NA) + } + + ts.len <- length(temp.data) + gs.begin <- which(select.blocks.gt.length(temp.data[1:(ts.mid - 1)] > t.thresh, min.length - 1)) + + ## Growing season actually ends the day -before- the sequence of sketchy days + gs.end <- which(select.blocks.gt.length(temp.data[ts.mid:ts.len] < t.thresh, min.length - 1)) - 1 + + ## If no growing season start, 0 length; if no end, ends at end of year; otherwise, end - start + 1 + # season.length <- ifelse(length(gs.begin) == 0, 0, ifelse(length(gs.end) == 0, ts.len - gs.begin[1] + 1, gs.end[1] - gs.begin[1] + ts.mid)) + + if (is.na(gs.begin[1])) { + start <- NA_character_ + end <- NA_character_ + season.length <- 0 # Set season length to 0 + } + else if (is.na(gs.end[1])) { + start <- gs.begin[1] + end <- ts.len - 1 # Last DOY + season.length <- ts.len - start + 1 + } + else { + start <- gs.begin[1] + end <- gs.end[1] + ts.mid -1 + season.length <- end - start +1 + } + + if (include.exact.dates) { + if(northern.hemisphere){ + origin <- paste(year = unique(date.factor[idx]), "01", "01", sep = "-") + } + else {origin <- paste(year = unique(date.factor[idx]), "07", "01", sep = "-")} + + origin.pcict <- PCICt::as.PCICt(origin, cal) + seconds.per.day <- 86400 + + if (!is.na(start)){ + start.pcict <- origin.pcict + (start - 1) * seconds.per.day + start <- format(start.pcict, "%Y-%m-%d") + end.pcict <- origin.pcict + (end * seconds.per.day) + end <- format(end.pcict, "%Y-%m-%d") + } + + result <- c(start, sl <- season.length, end) + } + else { result <- season.length} + return(result) + })) + + if (include.exact.dates) { + start <- growing.season[seq(1, length(growing.season), by = 3)] + sl <- growing.season[seq(2, length(growing.season), by = 3)] + sl <- as.numeric(sl) + end <- growing.season[seq(3, length(growing.season), by = 3)] + year <- names(growing.season[1:length(start)]) + if(!northern.hemisphere){ + sl <- c(sl,NA) + end <- c(end,NA) + } + df <- data.frame(start,sl, end) + rownames(df) <- year + return(df) + } + return(growing.season) + } + else { + in.gsl <- !select.blocks.gt.length(!select.blocks.gt.length(daily.mean.temp >= t.thresh, min.length - 1), min.length - 1) + warning("GSL_first, GSL_max, and GSL_sum are experimental alternative growing season length definitions. Use at your own risk.") + + innerfunc <- switch(gsl.mode, + GSL_first = function(bl) { + ifelse(any(bl > 0), (bl[bl > 0])[1], 0) + }, + GSL_max = max, + GSL_sum = sum + ) + return(tapply.fast(in.gsl, date.factor, function(ts) { + block.lengths <- get.series.lengths.at.ends(ts) + return(innerfunc(block.lengths)) + })) + } } \ No newline at end of file diff --git a/R/get_default_significant_figures.R b/R/get_default_significant_figures.R index bd02be5..da44b71 100644 --- a/R/get_default_significant_figures.R +++ b/R/get_default_significant_figures.R @@ -5,11 +5,6 @@ #' @param data \code{numeric(1)} A numerical vector #' #' @return If the data is numeric, "3", otherwise NA. -#' @export -#' -#' @examples -#' x <- 1:8 -#' get_default_significant_figures(x) get_default_significant_figures <- function(data) { if(is.numeric(data)) return(3) else return(NA) diff --git a/R/make_factor.R b/R/make_factor.R index 94a322b..52ddb6d 100644 --- a/R/make_factor.R +++ b/R/make_factor.R @@ -9,8 +9,6 @@ #' and the ordered parameter is consistent with the existing ordering, the input data is returned as is. #' Otherwise, the input data is converted into a factor variable with the specified ordering. #' -#' @export -#' #' @examples #' # Create a factor from a numeric vector #' #make_factor(c(1, 2,3,3,2,2,1,1,1, 3, 2), ordered = TRUE) diff --git a/R/spei_input.R b/R/spei_input.R index 45c9fc2..a8e8178 100644 --- a/R/spei_input.R +++ b/R/spei_input.R @@ -1,7 +1,7 @@ #' Calculate SPEI Input Data #' #' @description -#' This function calculates the Standardized Precipitation-Evapotranspiration Index (SPEI) input data from a given data frame. The function sorts the data by year and month, checks for data completeness, and prepares the data for further SPEI calculations. +#' This function calculates the Standardised Precipitation-Evapotranspiration Index (SPEI) input data from a given data frame. The function sorts the data by year and month, checks for data completeness, and prepares the data for further SPEI calculations. #' #' #' @details #' The function expects the input data to be in a data frame format. It calculates the SPEI input data by performing the following steps: diff --git a/R/spei_output.R b/R/spei_output.R index bfc387e..55d9564 100644 --- a/R/spei_output.R +++ b/R/spei_output.R @@ -2,7 +2,7 @@ #' #' @description #' -#' This function extracts the Standardized Precipitation-Evapotranspiration Index (SPEI) or Standardized Precipitation Index (SPI) column from a 'spei' object. It is designed to work with the original data and handle multiple stations if present. The function removes NA values introduced when unstacking the data to return a vector of the correct length. +#' This function extracts the Standardised Precipitation-Evapotranspiration Index (SPEI) or Standardized Precipitation Index (SPI) column from a 'spei' object. It is designed to work with the original data and handle multiple stations if present. The function removes NA values introduced when unstacking the data to return a vector of the correct length. #' # It requires the original data in order to return a vector of the correct length by removing NA values introduced when unstacking. # An alternative to this is to have a single wrapper SPEI/SPI function to handle this. diff --git a/R/summary_functions.R b/R/summary_functions.R deleted file mode 100644 index 76c83d7..0000000 --- a/R/summary_functions.R +++ /dev/null @@ -1,93 +0,0 @@ -#' Calculate Mean of Data -#' -#' Computes the mean or weighted mean of a dataset. -#' -#' @param x A numeric vector. -#' @param add_cols Additional columns (not used directly in calculation). -#' @param weights Optional weights for the data. -#' @param na.rm Logical. Should missing values be removed? Defaults to `FALSE`. -#' @param trim Numeric. Fraction of observations to trim from each end before computing the mean. -#' @param na_type Character string indicating the type of NA check to perform. -#' @param ... Additional arguments passed to `na_check`. -#' @return The mean or weighted mean of the data. -summary_mean <- function (x, add_cols, weights = NULL, na.rm = FALSE, trim = 0, na_type = "", ...) { - if( length(x)==0 || (na.rm && length(x[!is.na(x)])==0) ) return(NA) - else { - if(na.rm && na_type != "" && !na_check(x, na_type = na_type, ...)) return(NA) - else { - if (missing(weights) || is.null(weights)) - return(mean(x, na.rm = na.rm, trim = trim)) - else - return(stats::weighted.mean(x, w = weights, na.rm = na.rm)) - } - } -} - - -#' Calculate Sum of Data -#' -#' Computes the sum or weighted sum of a dataset. -#' -#' @param x A numeric vector. -#' @param weights Optional weights for the data. -#' @param na.rm Logical. Should missing values be removed? Defaults to `FALSE`. -#' @param na_type Character string indicating the type of NA check to perform. -#' @param ... Additional arguments passed to `na_check`. -#' @return The sum or weighted sum of the data. -summary_sum <- function (x, weights = NULL, na.rm = FALSE, na_type = "", ...) { - if(na.rm && na_type != "" && !na_check(x, na_type = na_type, ...)) return(NA) - else { - if (missing(weights) || is.null(weights)) return(sum(x, na.rm = na.rm)) - else return(sum(x * weights, na.rm = na.rm)) - } -} - -#' Check Missing Values Based on Conditions -#' -#' Evaluates a vector against specified conditions for missing values. -#' -#' @param x A vector to check for missing values. -#' @param na_type A character vector specifying the types of checks to perform. Options include: -#' \itemize{ -#' \item `"n"`: Total number of missing values (`<= na_max_n`). -#' \item `"prop"`: Proportion of missing values (`<= na_max_prop` in percentage). -#' \item `"n_non_miss"`: Minimum number of non-missing values (`>= na_min_n`). -#' \item `"FUN"`: A custom function to evaluate missing values. -#' \item `"con"`: Maximum consecutive missing values (`<= na_consecutive_n`). -#' } -#' @param na_consecutive_n Optional. Maximum allowed consecutive missing values. -#' @param na_max_n Optional. Maximum allowed missing values. -#' @param na_max_prop Optional. Maximum allowed proportion of missing values (in percentage). -#' @param na_min_n Optional. Minimum required non-missing values. -#' @param na_FUN Optional. A custom function to evaluate missing values. -#' @param ... Additional arguments passed to the custom function `na_FUN`. -#' @return Logical. Returns `TRUE` if all specified checks pass, otherwise `FALSE`. -na_check <- function(x, na_type = c(), na_consecutive_n = NULL, na_max_n = NULL, na_max_prop = NULL, na_min_n = NULL, na_FUN = NULL, ...) { - res <- c() - for (i in seq_along(na_type)) { - type <- na_type[i] - if (type %in% c("n","'n'")) { - res[i] <- summary_count_miss(x) <= na_max_n - } - else if (type %in% c("prop","'prop'")) { - res[i] <- (summary_count_miss(x) / summary_count(x)) <= na_max_prop / 100 - } - else if (type %in% c("n_non_miss","'n_non_miss'")) { - res[i] <- summary_count(x) >= na_min_n - } - else if (type %in% c("FUN","'FUN'")) { - res[i] <- na_FUN(x, ...) - } - else if (type %in% c("con","'con'")) { - is_na_rle <- rle(is.na(x)) - res[i] <- max(is_na_rle$lengths[is_na_rle$values]) <= na_consecutive_n - } - else { - stop("Invalid na_type specified for missing values check.") - } - if (!res[i]) { - return(FALSE) - } - } - return(all(res)) -} \ No newline at end of file diff --git a/R/wwr_report.R b/R/wwr_report.R index f009957..f0adfe8 100644 --- a/R/wwr_report.R +++ b/R/wwr_report.R @@ -84,7 +84,7 @@ wwr_export <- function(data, year, month, mean_station_pressure, mean_sea_level_ if (!missing(mean_station_pressure)) { df_2_means <- data %>% dplyr::group_by(!!! rlang::syms(c(link, year))) %>% - dplyr::summarise(mean = sprintf("%6s", round(summary_mean(.data[[mean_station_pressure]], na.rm = TRUE), 1)), .groups = "keep") + dplyr::summarise(mean = sprintf("%6s", round(databook::summary_mean(.data[[mean_station_pressure]], na.rm = TRUE), 1)), .groups = "keep") data[[mean_station_pressure]] <- ifelse(is.na(data[[mean_station_pressure]]), "", round(data[[mean_station_pressure]], 1)) data[[mean_station_pressure]] <- sprintf("%6s", data[[mean_station_pressure]]) @@ -96,7 +96,7 @@ wwr_export <- function(data, year, month, mean_station_pressure, mean_sea_level_ if (!missing(mean_sea_level_pressure)) { df_3_means <- data %>% dplyr::group_by(!!! rlang::syms(c(link, year))) %>% - dplyr::summarise(mean = sprintf("%6s", round(summary_mean(.data[[mean_sea_level_pressure]], na.rm = TRUE), 1)), .groups = "keep") + dplyr::summarise(mean = sprintf("%6s", round(databook::summary_mean(.data[[mean_sea_level_pressure]], na.rm = TRUE), 1)), .groups = "keep") data[[mean_sea_level_pressure]] <- ifelse(is.na(data[[mean_sea_level_pressure]]), "", round(data[[mean_sea_level_pressure]], 1)) data[[mean_sea_level_pressure]] <- sprintf("%6s", data[[mean_sea_level_pressure]]) @@ -108,7 +108,7 @@ wwr_export <- function(data, year, month, mean_station_pressure, mean_sea_level_ if (!missing(mean_temp)) { df_4_means <- data %>% dplyr::group_by(!!! rlang::syms(c(link, year))) %>% - dplyr::summarise(mean = sprintf("%6s", round(summary_mean(.data[[mean_temp]], na.rm = TRUE), 1)), .groups = "keep") + dplyr::summarise(mean = sprintf("%6s", round(databook::summary_mean(.data[[mean_temp]], na.rm = TRUE), 1)), .groups = "keep") data[[mean_temp]] <- ifelse(is.na(data[[mean_temp]]), "", round(data[[mean_temp]], 1)) data[[mean_temp]] <- sprintf("%6s", data[[mean_temp]]) @@ -120,7 +120,7 @@ wwr_export <- function(data, year, month, mean_station_pressure, mean_sea_level_ if (!missing(total_precip)) { df_5_means <- data %>% dplyr::group_by(!!! rlang::syms(c(link, year))) %>% - dplyr::summarise(mean = sprintf("%6s", format(summary_sum(.data[[total_precip]], na.rm = TRUE), digits = 1, nsmall = 1)), .groups = "keep") + dplyr::summarise(mean = sprintf("%6s", format(databook::summary_sum(.data[[total_precip]], na.rm = TRUE), digits = 1, nsmall = 1)), .groups = "keep") data[[total_precip]] <- ifelse(is.na(data[[total_precip]]), "", ifelse(data[[total_precip]] <= 0.05, 0, format(data[[total_precip]], digits = 1, nsmall = 1))) data[[total_precip]] <- sprintf("%6s", data[[total_precip]]) @@ -132,7 +132,7 @@ wwr_export <- function(data, year, month, mean_station_pressure, mean_sea_level_ if (!missing(mean_max_temp)) { df_6_means <- data %>% dplyr::group_by(!!! rlang::syms(c(link, year))) %>% - dplyr::summarise(mean = sprintf("%6s", round(summary_mean(.data[[mean_max_temp]], na.rm = TRUE), 1)), .groups = "keep") + dplyr::summarise(mean = sprintf("%6s", round(databook::summary_mean(.data[[mean_max_temp]], na.rm = TRUE), 1)), .groups = "keep") data[[mean_max_temp]] <- ifelse(is.na(data[[mean_max_temp]]), "", round(data[[mean_max_temp]], 1)) data[[mean_max_temp]] <- sprintf("%6s", data[[mean_max_temp]]) @@ -144,7 +144,7 @@ wwr_export <- function(data, year, month, mean_station_pressure, mean_sea_level_ if (!missing(mean_min_temp)) { df_7_means <- data %>% dplyr::group_by(!!! rlang::syms(c(link, year))) %>% - dplyr::summarise(mean = sprintf("%6s", round(summary_mean(.data[[mean_min_temp]], na.rm = TRUE), 1)), .groups = "keep") + dplyr::summarise(mean = sprintf("%6s", round(databook::summary_mean(.data[[mean_min_temp]], na.rm = TRUE), 1)), .groups = "keep") data[[mean_min_temp]] <- ifelse(is.na(data[[mean_min_temp]]), "", round(data[[mean_min_temp]], 1)) data[[mean_min_temp]] <- sprintf("%6s", data[[mean_min_temp]]) @@ -157,7 +157,7 @@ wwr_export <- function(data, year, month, mean_station_pressure, mean_sea_level_ if (any(data[[mean_rel_hum]] < 0 | data[[mean_rel_hum]] > 100, na.rm = TRUE)) stop("Mean Relative Humidity must be a percentage between 0 and 100.") df_8_means <- data %>% dplyr::group_by(!!! rlang::syms(c(link, year))) %>% - dplyr::summarise(mean = sprintf("%6s", round(summary_mean(.data[[mean_rel_hum]], na.rm = TRUE), 0)), .groups = "keep") + dplyr::summarise(mean = sprintf("%6s", round(databook::summary_mean(.data[[mean_rel_hum]], na.rm = TRUE), 0)), .groups = "keep") data[[mean_rel_hum]] <- ifelse(is.na(data[[mean_rel_hum]]), "", round(data[[mean_rel_hum]], 1)) data[[mean_rel_hum]] <- sprintf("%6s", data[[mean_rel_hum]]) diff --git a/man/climdex.Rd b/man/climdex.Rd index 43be5fd..a8210e6 100644 --- a/man/climdex.Rd +++ b/man/climdex.Rd @@ -2,7 +2,7 @@ % Please edit documentation in R/climdex.R \name{climdex} \alias{climdex} -\title{Calculate climate indices} +\title{Calculate Climate Indices} \usage{ climdex( data, diff --git a/man/climdexInput.Rd b/man/climdexInput.Rd index a080ff6..13d12c3 100644 --- a/man/climdexInput.Rd +++ b/man/climdexInput.Rd @@ -101,11 +101,11 @@ and monthly data.} library(PCICt) ## Parse the dates into PCICt. -tmax.dates <- as.PCICt(do.call(paste, ec.1018935.tmax[,c("year", +tmax.dates <- PCICt::as.PCICt(do.call(paste, ec.1018935.tmax[,c("year", "jday")]), format="\%Y \%j", cal="gregorian") -tmin.dates <- as.PCICt(do.call(paste, ec.1018935.tmin[,c("year", +tmin.dates <- PCICt::as.PCICt(do.call(paste, ec.1018935.tmin[,c("year", "jday")]), format="\%Y \%j", cal="gregorian") -prec.dates <- as.PCICt(do.call(paste, ec.1018935.prec[,c("year", +prec.dates <- PCICt::as.PCICt(do.call(paste, ec.1018935.prec[,c("year", "jday")]), format="\%Y \%j", cal="gregorian") ## Load the data in. diff --git a/man/climdexInput.raw.Rd b/man/climdexInput.raw.Rd index 53d6af5..f76b027 100644 --- a/man/climdexInput.raw.Rd +++ b/man/climdexInput.raw.Rd @@ -24,12 +24,52 @@ climdexInput.raw( ) } \arguments{ -\item{northern.hemisphere}{Whether this point is in the northern hemisphere.} +\item{tmax}{numeric vector containing the data on which the indices are to be computed. (degrees C)} -\item{quantiles}{Threshold quantiles for supplied variables.} +\item{tmin}{numeric vector containing the data on which the indices are to be computed. (degrees C)} -\item{max.missing.days}{Vector containing thresholds for number of days -allowed missing per year (annual), per month (monthly) and per season (seasonal).} +\item{prec}{numeric vector containing the data on which the indices are to be computed. (mm/day)} + +\item{tmax.dates}{vector of type \code{PCICt} of the maximum date.} + +\item{tmin.dates}{vector of type \code{PCICt} of the minimum date.} + +\item{prec.dates}{vector of type \code{PCICt} of the precipitation date.} + +\item{base.range}{a pair of 4 digit years which bound the data on which the base percentiles are calculated.} + +\item{n}{the size of the window used when computing the percentiles used in \code{\link{climdex.tx10p}}, +\code{\link{climdex.tn10p}}, \code{\link{climdex.tx90p}}, and \code{\link{climdex.tn90p}}.} + +\item{northern.hemisphere}{whether the data came from +the northern hemisphere. If FALSE, data is assumed to have come from the +southern hemisphere. This is used when computing growing season length; if +the data is from the southern hemisphere, growing season length is the +growing season starting in the beginning of July of the year indicated, +running to the end of June of the following year.} + +\item{tavg}{Average temperature, default \code{NULL}} + +\item{tavg.dates}{Average temperature dates, default \code{NULL}} + +\item{quantiles}{supply pre-computed quantiles. This is a list consisting of quantiles for each variable.} + +\item{temp.qtiles}{modify the quantiles calculated. For example, specifying +temp.qtiles=c(0.10, 0.50, 0.90) would calculate the 10th, 50th, and 90th +percentiles for temperature.} + +\item{prec.qtiles}{modify the quantiles calculated.} + +\item{max.missing.days}{vector consisting of 'annual' +(the number of days that can be missing in a year), 'monthly' (the +number of days that can be missing in a month and 'seasonal' (the +number of days that can be missing in a season. If one month in a year fails +the test, the corresponding year will be omitted.} + +\item{min.base.fraction.present}{the minimum fraction +of data which must be present for a quantile to be calculated for a +particular day. If the fraction of data present is less than this threshold, +the quantile for that day will be set to NA.} } \value{ An object of class \code{\link{climdexInput-class}} for use with @@ -44,30 +84,6 @@ This function takes input climate data at daily resolution, and produces as output a ClimdexInput data structure. This data structure can then be passed to any of the routines used to compute the Climdex indices. The indices themselves are specified on the webpage cited in the references section. -The \code{base.range} argument is a pair of 4 digit years which bound the -data on which the base percentiles are calculated. - -The \code{tmax}, \code{tmin}, and \code{prec} arguments are numeric vectors -containing the data on which the indices are to be computed. The units are -assumed to be degrees C for temperature, and mm/day for precipitation. - -The \code{tmax.dates}, \code{tmin.dates}, and \code{prec.dates} arguments -are vectors of type \code{PCICt}. - -The \code{n} argument specifies the size of the window used when computing -the percentiles used in \code{\link{climdex.tx10p}}, -\code{\link{climdex.tn10p}}, \code{\link{climdex.tx90p}}, and -\code{\link{climdex.tn90p}}. - -The \code{northern.hemisphere} argument specifies whether the data came from -the northern hemisphere. If FALSE, data is assumed to have come from the -southern hemisphere. This is used when computing growing season length; if -the data is from the southern hemisphere, growing season length is the -growing season starting in the beginning of July of the year indicated, -running to the end of June of the following year. - -The \code{quantiles} argument allows the user to supply pre-computed quantiles. -This is a list consisting of quantiles for each variable. For each temperature variable, there are separate lists of quantiles for inbase and outbase, with these names. In both cases, quantiles within these @@ -82,22 +98,6 @@ year, with a particular year replaced. For precipitation variables, there is a named vector of quantiles, consisting of at least q95 and q99. - -The \code{temp.qtiles} and \code{prec.qtiles} arguments allow the user to -modify the quantiles calculated. For example, specifying -temp.qtiles=c(0.10, 0.50, 0.90) would calculate the 10th, 50th, and 90th -percentiles for temperature. - -The \code{min.base.fraction.present} argument specifies the minimum fraction -of data which must be present for a quantile to be calculated for a -particular day. If the fraction of data present is less than this threshold, -the quantile for that day will be set to NA. - -The \code{max.missing.days} argument is a vector consisting of 'annual' -(the number of days that can be missing in a year), 'monthly' (the -number of days that can be missing in a month and 'seasonal' (the -number of days that can be missing in a season. If one month in a year fails -the test, the corresponding year will be omitted. } \note{ Units are assumed to be mm/day for precipitation and degrees Celsius @@ -110,22 +110,20 @@ library(PCICt) ## ready to go. ## Parse the dates into PCICt. -tmax.dates <- as.PCICt(do.call(paste, ec.1018935.tmax[,c("year", +tmax.dates <- PCICt::as.PCICt(do.call(paste, ec.1018935.tmax[,c("year", "jday")]), format="\%Y \%j", cal="gregorian") -tmin.dates <- as.PCICt(do.call(paste, ec.1018935.tmin[,c("year", +tmin.dates <- PCICt::as.PCICt(do.call(paste, ec.1018935.tmin[,c("year", "jday")]), format="\%Y \%j", cal="gregorian") -prec.dates <- as.PCICt(do.call(paste, ec.1018935.prec[,c("year", +prec.dates <- PCICt::as.PCICt(do.call(paste, ec.1018935.prec[,c("year", "jday")]), format="\%Y \%j", cal="gregorian") ## Load the data in. ci <- climdexInput.raw(ec.1018935.tmax$MAX_TEMP, ec.1018935.tmin$MIN_TEMP, ec.1018935.prec$ONE_DAY_PRECIPITATION, tmax.dates, tmin.dates, prec.dates, base.range=c(1971, 2000)) - } \references{ -\url{http://etccdi.pacificclimate.org/list_27_indices.shtml} - +For Climdex Indices: \url{http://etccdi.pacificclimate.org/list_27_indices.shtml} This function is from the \code{pacificclimate/climdex.pcic} repository. The \code{climdex.pcic} package was developed and maintained by the Pacific Climate Impacts Consortium (PCIC). For more information, visit the repository: \url{https://github.com/pacificclimate/climdex.pcic} diff --git a/man/climdex_single_station.Rd b/man/climdex_single_station.Rd index 15ea1a4..cf20299 100644 --- a/man/climdex_single_station.Rd +++ b/man/climdex_single_station.Rd @@ -2,7 +2,7 @@ % Please edit documentation in R/climdex_single_station.R \name{climdex_single_station} \alias{climdex_single_station} -\title{climdex_single_station} +\title{Climdex Single Station} \usage{ climdex_single_station( ci, diff --git a/man/get_default_significant_figures.Rd b/man/get_default_significant_figures.Rd index f7a17a9..538e45b 100644 --- a/man/get_default_significant_figures.Rd +++ b/man/get_default_significant_figures.Rd @@ -15,7 +15,3 @@ If the data is numeric, "3", otherwise NA. \description{ This function gets the default number of significant figures when given a numeric vector. } -\examples{ -x <- 1:8 -get_default_significant_figures(x) -} diff --git a/man/na_check.Rd b/man/na_check.Rd deleted file mode 100644 index d51f3e3..0000000 --- a/man/na_check.Rd +++ /dev/null @@ -1,47 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/summary_functions.R -\name{na_check} -\alias{na_check} -\title{Check Missing Values Based on Conditions} -\usage{ -na_check( - x, - na_type = c(), - na_consecutive_n = NULL, - na_max_n = NULL, - na_max_prop = NULL, - na_min_n = NULL, - na_FUN = NULL, - ... -) -} -\arguments{ -\item{x}{A vector to check for missing values.} - -\item{na_type}{A character vector specifying the types of checks to perform. Options include: -\itemize{ -\item \code{"n"}: Total number of missing values (\verb{<= na_max_n}). -\item \code{"prop"}: Proportion of missing values (\verb{<= na_max_prop} in percentage). -\item \code{"n_non_miss"}: Minimum number of non-missing values (\verb{>= na_min_n}). -\item \code{"FUN"}: A custom function to evaluate missing values. -\item \code{"con"}: Maximum consecutive missing values (\verb{<= na_consecutive_n}). -}} - -\item{na_consecutive_n}{Optional. Maximum allowed consecutive missing values.} - -\item{na_max_n}{Optional. Maximum allowed missing values.} - -\item{na_max_prop}{Optional. Maximum allowed proportion of missing values (in percentage).} - -\item{na_min_n}{Optional. Minimum required non-missing values.} - -\item{na_FUN}{Optional. A custom function to evaluate missing values.} - -\item{...}{Additional arguments passed to the custom function \code{na_FUN}.} -} -\value{ -Logical. Returns \code{TRUE} if all specified checks pass, otherwise \code{FALSE}. -} -\description{ -Evaluates a vector against specified conditions for missing values. -} diff --git a/man/spei_input.Rd b/man/spei_input.Rd index fbf973f..d139da0 100644 --- a/man/spei_input.Rd +++ b/man/spei_input.Rd @@ -21,7 +21,7 @@ spei_input(data, station, year, month, element) A time series object (\code{ts}) containing the calculated SPEI input data. } \description{ -This function calculates the Standardized Precipitation-Evapotranspiration Index (SPEI) input data from a given data frame. The function sorts the data by year and month, checks for data completeness, and prepares the data for further SPEI calculations. +This function calculates the Standardised Precipitation-Evapotranspiration Index (SPEI) input data from a given data frame. The function sorts the data by year and month, checks for data completeness, and prepares the data for further SPEI calculations. #' @details The function expects the input data to be in a data frame format. It calculates the SPEI input data by performing the following steps: diff --git a/man/spei_output.Rd b/man/spei_output.Rd index 52ba21b..fe21682 100644 --- a/man/spei_output.Rd +++ b/man/spei_output.Rd @@ -21,7 +21,7 @@ spei_output(x, data, station, year, month) A vector containing the extracted SPEI/SPI column from the 'spei' object 'x'. } \description{ -This function extracts the Standardized Precipitation-Evapotranspiration Index (SPEI) or Standardized Precipitation Index (SPI) column from a 'spei' object. It is designed to work with the original data and handle multiple stations if present. The function removes NA values introduced when unstacking the data to return a vector of the correct length. +This function extracts the Standardised Precipitation-Evapotranspiration Index (SPEI) or Standardized Precipitation Index (SPI) column from a 'spei' object. It is designed to work with the original data and handle multiple stations if present. The function removes NA values introduced when unstacking the data to return a vector of the correct length. } \examples{ # TODO: diff --git a/man/summary_mean.Rd b/man/summary_mean.Rd deleted file mode 100644 index 0f4f360..0000000 --- a/man/summary_mean.Rd +++ /dev/null @@ -1,37 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/summary_functions.R -\name{summary_mean} -\alias{summary_mean} -\title{Calculate Mean of Data} -\usage{ -summary_mean( - x, - add_cols, - weights = NULL, - na.rm = FALSE, - trim = 0, - na_type = "", - ... -) -} -\arguments{ -\item{x}{A numeric vector.} - -\item{add_cols}{Additional columns (not used directly in calculation).} - -\item{weights}{Optional weights for the data.} - -\item{na.rm}{Logical. Should missing values be removed? Defaults to \code{FALSE}.} - -\item{trim}{Numeric. Fraction of observations to trim from each end before computing the mean.} - -\item{na_type}{Character string indicating the type of NA check to perform.} - -\item{...}{Additional arguments passed to \code{na_check}.} -} -\value{ -The mean or weighted mean of the data. -} -\description{ -Computes the mean or weighted mean of a dataset. -} diff --git a/man/summary_sum.Rd b/man/summary_sum.Rd deleted file mode 100644 index 90799a8..0000000 --- a/man/summary_sum.Rd +++ /dev/null @@ -1,25 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/summary_functions.R -\name{summary_sum} -\alias{summary_sum} -\title{Calculate Sum of Data} -\usage{ -summary_sum(x, weights = NULL, na.rm = FALSE, na_type = "", ...) -} -\arguments{ -\item{x}{A numeric vector.} - -\item{weights}{Optional weights for the data.} - -\item{na.rm}{Logical. Should missing values be removed? Defaults to \code{FALSE}.} - -\item{na_type}{Character string indicating the type of NA check to perform.} - -\item{...}{Additional arguments passed to \code{na_check}.} -} -\value{ -The sum or weighted sum of the data. -} -\description{ -Computes the sum or weighted sum of a dataset. -}