Skip to content

Commit d59314e

Browse files
authored
Merge pull request #51 from cmu-delphi/look-at-dup
Edits to duplicate values checks
2 parents 59be7d5 + 927f057 commit d59314e

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

DESCRIPTION

+1-4
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,5 @@ Imports:
5151
tidyr,
5252
tsibble
5353
Suggests:
54-
testthat (>= 3.0.0),
55-
delphi.epidata
56-
Remotes:
57-
github::cmu-delphi/delphi-epidata-r
54+
testthat (>= 3.0.0),
5855
Config/testthat/edition: 3

R/growth_rate.R

+7-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@
2222
#' @param log_scale Should growth rates be estimated using the parametrization
2323
#' on the log scale? See details for an explanation. Default is `FALSE`.
2424
#' @param dup_rm Should we check and remove duplicates in `x` (and corresponding
25-
#' elements of `y`) before the computation? Default is `FALSE`.
25+
#' elements of `y`) before the computation? Some methods might handle
26+
#' duplicate `x` values gracefully, whereas others might fail (either quietly
27+
#' or loudly). Default is `FALSE`.
2628
#' @param na_rm Should missing values be removed before the computation? Default
2729
#' is `FALSE`.
2830
#' @param ... Additional arguments to pass to the method used to estimate the
@@ -122,9 +124,13 @@ growth_rate = function(x = seq_along(y), y, x0 = x,
122124
# Remove duplicates if we need to
123125
if (dup_rm) {
124126
o = !duplicated(x)
127+
if (any(!o)) {
128+
Warn("`x` contains duplicate values. (If being run on a column in an `epi_df`, did you group by relevant key variables?)")
129+
}
125130
x = x[o]
126131
y = y[o]
127132
}
133+
128134

129135
# Remove NAs if we need to
130136
if (na_rm) {

R/outliers.R

+3-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ detect_outlr = function(x = seq_along(y), y,
5353
combiner = match.arg(combiner)
5454

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

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

0 commit comments

Comments
 (0)