Skip to content

Edits to duplicate values checks #51

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,5 @@ Imports:
tidyr,
tsibble
Suggests:
testthat (>= 3.0.0),
delphi.epidata
Remotes:
github::cmu-delphi/delphi-epidata-r
testthat (>= 3.0.0),
Config/testthat/edition: 3
8 changes: 7 additions & 1 deletion R/growth_rate.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
#' @param log_scale Should growth rates be estimated using the parametrization
#' on the log scale? See details for an explanation. Default is `FALSE`.
#' @param dup_rm Should we check and remove duplicates in `x` (and corresponding
#' elements of `y`) before the computation? Default is `FALSE`.
#' elements of `y`) before the computation? Some methods might handle
#' duplicate `x` values gracefully, whereas others might fail (either quietly
#' or loudly). Default is `FALSE`.
#' @param na_rm Should missing values be removed before the computation? Default
#' is `FALSE`.
#' @param ... Additional arguments to pass to the method used to estimate the
Expand Down Expand Up @@ -122,9 +124,13 @@ growth_rate = function(x = seq_along(y), y, x0 = x,
# Remove duplicates if we need to
if (dup_rm) {
o = !duplicated(x)
if (any(!o)) {
Warn("`x` contains duplicate values. (If being run on a column in an `epi_df`, did you group by relevant key variables?)")
}
x = x[o]
y = y[o]
}


# Remove NAs if we need to
if (na_rm) {
Expand Down
4 changes: 3 additions & 1 deletion R/outliers.R
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ detect_outlr = function(x = seq_along(y), y,
combiner = match.arg(combiner)

# Validate that x contains all distinct values
if (max(table(x)) > 1) Abort("`x` must not contain duplicate values; did you group your `epi_df` by all relevant key variables?")
if (any(duplicated(x))) {
Abort("`x` cannot contain duplicate values. (If being run on a column in an `epi_df`, did you group by relevant key variables?)")
}

# Run all outlier detection methods
results = purrr::pmap_dfc(methods, function(method, args, abbr) {
Expand Down