From bebb93c6a72acd98d3e9124701803a3be3f0deb1 Mon Sep 17 00:00:00 2001 From: Max-Bladen Date: Tue, 15 Nov 2022 14:00:55 +1100 Subject: [PATCH] Fix for Issue #266 fix: added fail safe for when `Inf` or `-Inf` are found in transformed `newdata` data frame. Changes them to `NaN` which can be safely handled by downstream functions --- R/predict.R | 3 +++ 1 file changed, 3 insertions(+) diff --git a/R/predict.R b/R/predict.R index aac4c71e..1c26b8d5 100644 --- a/R/predict.R +++ b/R/predict.R @@ -405,6 +405,9 @@ predict.mixo_pls <- newdata[which(!is.na(ind.match))] = lapply(which(!is.na(ind.match)), function(x){sweep(newdata[[x]], 2, STATS = attr(X[[x]], "scaled:center"))}) if (scale) newdata[which(!is.na(ind.match))] = lapply(which(!is.na(ind.match)), function(x){sweep(newdata[[x]], 2, FUN = "/", STATS = attr(X[[x]], "scaled:scale"))}) + if (any(unlist(lapply(newdata[which(!is.na(ind.match))], function(x){any(is.infinite(x))})))) { + newdata[which(!is.na(ind.match))] <- lapply(which(!is.na(ind.match)), function(x){df <- newdata[[x]]; df[which(is.infinite(df))] <- NaN; return(df)}) + } means.Y = matrix(attr(Y, "scaled:center"),nrow=nrow(newdata[[1]]),ncol=q,byrow=TRUE); if (scale)