The scaling of empty data should not happen in the analyses. As a result
the corresponding function 'scale.data' throws an error if the given
data is empty.
Additionally, this prevents warning from the function 'max' about the
empty data.
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..d06437d 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)) {
+ stop("Scaling empty data should not happen. Please check your data.")
+ }
+
## 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)
}
--
2.10.2