Skip to content

Commit 75ca624

Browse files
committed
check date, lag fields present and not NA
1 parent 04b6fec commit 75ca624

File tree

1 file changed

+8
-6
lines changed
  • backfill_corrections/delphiBackfillCorrection/R

1 file changed

+8
-6
lines changed

backfill_corrections/delphiBackfillCorrection/R/utils.R

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -148,12 +148,14 @@ validity_checks <- function(df, value_type, num_col, denom_col, signal_suffixes,
148148
stop("No 'time_value' column detected for the reference date!")
149149
}
150150

151-
# issue_date or lag should exist in the dataset
152-
if ( !lag_col %in% colnames(df) ) {
153-
if ( issued_col %in% colnames(df) ) {
154-
df$lag = as.integer(df$issue_date - df$time_value)
155-
}
156-
else {stop("No issue_date or lag exists!")}
151+
# issue_date and lag should exist in the dataset
152+
if ( !(lag_col %in% colnames(df)) || !(issued_col %in% colnames(df)) ) {
153+
stop("`issue_date` and `lag` fields must exist in the input data")
154+
}
155+
156+
if ( any(is.na(df[[lag_col]])) || any(is.na(df[[issued_col]])) ||
157+
any(is.na(df$time_value)) ) {
158+
stop("`issue_date`, `lag`, or `time_value` contain missing values")
157159
}
158160

159161
return(list(df = df, value_cols = value_cols))

0 commit comments

Comments
 (0)