[codeface] [PATCH 19/26] Fix cycle extraction in ML analysis

  • From: Claus Hunsen <hunsen@xxxxxxxxxxxxxxxxx>
  • To: codeface@xxxxxxxxxxxxx
  • Date: Thu, 13 Oct 2016 17:29:51 +0200

If there are no cycles (i.e., release ranges) in the database for the
given project - which happens in the ML test, for example -, the
subsetting of the result throws an error.

By, returning an empty data.frame instead, everything is fine. The user
only needs to check for "nrow(res) > 0" if they rely on the result.

Signed-off-by: Claus Hunsen <hunsen@xxxxxxxxxxxxxxxxx>
---
 codeface/R/query.r | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/codeface/R/query.r b/codeface/R/query.r
index 4911136..72c8504 100644
--- a/codeface/R/query.r
+++ b/codeface/R/query.r
@@ -137,9 +137,11 @@ get.cycles.con <- function(con, pid, boundaries=FALSE, 
allow.empty.ranges=FALSE)
     column.selection <- c("range.id", "date.start", "date.end", "cycle")
   }
 
-  res <- res[, column.selection]
-  res$date.start <- ymd_hms(res$date.start, quiet=TRUE)
-  res$date.end <- ymd_hms(res$date.end, quiet=TRUE)
+  if (nrow(res) > 0) {
+    res <- res[, column.selection]
+    res$date.start <- ymd_hms(res$date.start, quiet=TRUE)
+    res$date.end <- ymd_hms(res$date.end, quiet=TRUE)
+  }
 
   return(res)
 }
-- 
2.10.0


Other related posts: