Hi Wolfgang,
unfortunately, I do not remember why I introduced that patch. There was
indeed a reason for that. I guess, it was a problem occurring while
testing, I do not recall any details.
I will remove the commit and keep the diff somewhere until the problem
re-appears eventually.
-- Claus
On 24/11/16 13:09, Wolfgang Mauerer wrote:
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.
I agree that it does not make sense to scale an empty data set.
Do you know where this happens in the actual code? It might be
better to respond with an error in scale.data and fix any callers
instead. An empty data set would likely cause problems later on
of the caller is not aware that this case can happen.
Thanks, Wolfgang
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)
}
Attachment:
signature.asc
Description: OpenPGP digital signature