Skip to content

Commit

Permalink
Fix for Issue #266
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Max-Bladen committed Nov 15, 2022
1 parent 7a5464e commit bebb93c
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions R/predict.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit bebb93c

Please sign in to comment.