From 3996e0ab17cded689acb3f3506b4c4d738a6dede Mon Sep 17 00:00:00 2001 From: JulioV Date: Fri, 9 Oct 2020 17:00:20 -0400 Subject: [PATCH] Fix bug when episodes are empty --- src/features/utils/resample_episodes.R | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/features/utils/resample_episodes.R b/src/features/utils/resample_episodes.R index 6572424a..b25f05ce 100644 --- a/src/features/utils/resample_episodes.R +++ b/src/features/utils/resample_episodes.R @@ -14,9 +14,11 @@ resampled_episodes["end_timestamp"] <- pmin(resampled_episodes["start_timestamp" resampled_episodes <- resampled_episodes %>% select(-nrow) resampled_episodes <- resampled_episodes %>% uncount(2, .id = "end_flag") -resampled_episodes["timestamp"] = NA_real_ -resampled_episodes[resampled_episodes$end_flag ==1, "timestamp"] = resampled_episodes[resampled_episodes$end_flag ==1, "start_timestamp"] -resampled_episodes[resampled_episodes$end_flag ==2, "timestamp"] = resampled_episodes[resampled_episodes$end_flag ==2, "end_timestamp"] +resampled_episodes <- resampled_episodes %>% add_column(timestamp = NA_real_) +if(nrow(resampled_episodes) > 0){ + resampled_episodes[resampled_episodes$end_flag ==1, "timestamp"] = resampled_episodes[resampled_episodes$end_flag ==1, "start_timestamp"] + resampled_episodes[resampled_episodes$end_flag ==2, "timestamp"] = resampled_episodes[resampled_episodes$end_flag ==2, "end_timestamp"] +} resampled_episodes <- resampled_episodes %>% select(-end_flag) write.csv(resampled_episodes, snakemake@output[[1]], row.names = FALSE)