From e5dbbfce44d91dfb573f51305378e9b9bedfaeef Mon Sep 17 00:00:00 2001 From: Sam Date: Tue, 18 Jan 2022 10:16:37 -0500 Subject: [PATCH] Avoid NA problem in barnett location evaluation (#172) * Avoid occasional issue where does_not_span evaluates to NA, which breaks the if() * Restored original warning --- src/features/phone_locations/barnett/daily_features.R | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/features/phone_locations/barnett/daily_features.R b/src/features/phone_locations/barnett/daily_features.R index 25f057f9..5da1e754 100644 --- a/src/features/phone_locations/barnett/daily_features.R +++ b/src/features/phone_locations/barnett/daily_features.R @@ -25,9 +25,11 @@ barnett_daily_features <- function(snakemake){ datetime_end_regex = "[0-9]{4}[\\-|\\/][0-9]{2}[\\-|\\/][0-9]{2} 23:59:59" location <- location %>% mutate(is_daily = str_detect(assigned_segments, paste0(".*#", datetime_start_regex, ",", datetime_end_regex, ".*"))) - - if(nrow(segment_labels) == 0 || nrow(location) == 0 || all(location$is_daily == FALSE) || (max(location$timestamp) - min(location$timestamp) < 86400000)){ - warning("Barnett's location features cannot be computed for data or time segments that do not span one or more entire days (00:00:00 to 23:59:59). Values below point to the problem:", + + does_not_span = nrow(segment_labels) == 0 || nrow(location) == 0 || all(location$is_daily == FALSE) || (max(location$timestamp) - min(location$timestamp) < 86400000) + + if(is.na(does_not_span) || does_not_span){ + warning("Barnett's location features cannot be computed for data or time segments that do not span one or more entire days (00:00:00 to 23:59:59). Values below point to the problem:", "\nLocation data rows within a daily time segment: ", nrow(filter(location, is_daily)), "\nLocation data time span in days: ", round((max(location$timestamp) - min(location$timestamp)) / 86400000, 2) )