Skip to content

Commit 2c09250

Browse files
committed
Fix NA cell issue for xgboost projections
1 parent 534d69b commit 2c09250

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

R/engine_xgboost.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -875,7 +875,8 @@ engine_xgboost <- function(x,
875875
if(nrow(newdata)==nrow(model$predictors)){
876876
prediction <- try({model_to_background(model)}, silent = TRUE)
877877
prediction[] <- pred_xgb
878-
prediction <- terra::mask(prediction, model$background)
878+
mask_tmp <- sum(terra::rast(newdata_copy, crs = terra::crs(prediction)))
879+
prediction <- terra::mask(prediction, mask_tmp) # make sure to only use nonNA cells
879880
} else {
880881
assertthat::assert_that(utils::hasName(newdata_copy,"x")&&utils::hasName(newdata_copy,"y"),
881882
msg = "Projection data.frame has no valid coordinates or differs in grain!")

0 commit comments

Comments
 (0)