From d83a6aa4a0efa340447a1d057c6dd8feb1344ebb Mon Sep 17 00:00:00 2001 From: HannaMeyer Date: Mon, 22 Jan 2024 17:18:37 +0100 Subject: [PATCH] handling of potential error --- R/CreateSpacetimeFolds.R | 3 +++ 1 file changed, 3 insertions(+) diff --git a/R/CreateSpacetimeFolds.R b/R/CreateSpacetimeFolds.R index a1b3113f..83fcb77c 100644 --- a/R/CreateSpacetimeFolds.R +++ b/R/CreateSpacetimeFolds.R @@ -47,6 +47,9 @@ CreateSpacetimeFolds <- function(x,spacevar=NA,timevar=NA, x <- data.frame(x) ### if classification is used, make sure that classes are equally distributed across folds if(!is.na(class)){ + if(is.numeric(x[,class])){ + stop("argument class only works for categorical data") + } unit <- unique(x[,c(spacevar,class)]) unit$CAST_fold <- createFolds(unit[,which(names(unit)==class)],k = k,list=FALSE) #x <- merge(x,unit,by.x=c(spacevar,class),by.y=c(spacevar,class),all.x=TRUE,sort=FALSE)