Skip to content

Commit

Permalink
Clarify wtf_metadata_match message
Browse files Browse the repository at this point in the history
  • Loading branch information
bpbond committed Feb 29, 2024
1 parent 0c51d11 commit 3957fe0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
8 changes: 5 additions & 3 deletions R/metadata.R
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,16 @@ wtf_metadata_match <- function(data_timestamps,
matches <- rep(NA_real_, length(data_timestamps))
entries <- seq_along(start_timestamps)
for(i in entries) {
mtch <- data_timestamps >= start_timestamps[i] & data_timestamps <= stop_timestamps[i]
mtch <- data_timestamps >= start_timestamps[i] & data_timestamps < stop_timestamps[i]
matches[mtch] <- i
}

# Metadata rows with zero matches seems unexpected
no_matches <- base::setdiff(entries, unique(matches, na.omit(matches)))
if(length(no_matches)) {
wtf_message("Entries with no timestamp matches: ", paste(no_matches, collapse = ", "))
lnm <- length(no_matches)
if(lnm) {
wtf_message(lnm, ifelse(lnm == 1, " entry", " entries"),
" had no timestamp matches!")
}

return(matches)
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-metadata.R
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,5 @@ test_that("wtf_metadata_match works", {
s_d <- c("2024-01-01", "2024-01-01", "2024-01-10")
s_t <- c("13:00:00", "13:05:00", "13:10:00")
expect_message(wtf_metadata_match(d_t, s_d, s_t, c(60, 60, 60)),
regexp = "no timestamp matches: 3")
regexp = "1 entry had no timestamp matches")
})

0 comments on commit 3957fe0

Please sign in to comment.