Am 13/10/2016 um 17:29 schrieb Claus Hunsen:
If the given data is empty, the function 'max' throws warnings about
that. To prevent this, the function now checks for empty data and
returns early.
Signed-off-by: Claus Hunsen <hunsen@xxxxxxxxxxxxxxxxx>
---
codeface/R/utils.r | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/codeface/R/utils.r b/codeface/R/utils.r
index 9911497..28aae41 100644
--- a/codeface/R/utils.r
+++ b/codeface/R/utils.r
@@ -30,16 +30,24 @@ gen.df.from.ts <- function(ts, type) {
## Scale a given data set to the range [min,max]
scale.data <- function(dat, .min=0, .max=1) {
+ ## catch empty data
+ if (is.null(dat)) {
+ return(as.numeric(c())) # an empty numeric vector
+ }
+
## calculate the scale factor with which to divide the data
maxDat <- max(dat)
scale.factor <- (maxDat - min(dat))/(.max - .min)
+
## If the data is not all the same, do apply the scale factor
if (scale.factor > 0) {
dat <- dat / scale.factor
maxDat <- maxDat / scale.factor
}
+
## Set the maximum to .max
dat <- dat + (- maxDat + .max)
+
return(dat)
}