aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGertjan van den Burg <gertjanvandenburg@gmail.com>2020-08-30 21:40:23 +0100
committerGertjan van den Burg <gertjanvandenburg@gmail.com>2020-08-30 21:40:23 +0100
commit11be90a6e2e9921da3b2b6580815fda457a04023 (patch)
tree4cf676d76151a1b3e9f23e3dd3e7104595b50c8c
parentAdd cran-release to buildignore (diff)
downloadrgensvm-11be90a6e2e9921da3b2b6580815fda457a04023.tar.gz
rgensvm-11be90a6e2e9921da3b2b6580815fda457a04023.zip
Properly handle errors
-rw-r--r--R/gensvm.train.test.split.R3
-rw-r--r--R/predict.gensvm.R4
-rw-r--r--R/predict.gensvm.grid.R3
3 files changed, 3 insertions, 7 deletions
diff --git a/R/gensvm.train.test.split.R b/R/gensvm.train.test.split.R
index cd40ecc..680743c 100644
--- a/R/gensvm.train.test.split.R
+++ b/R/gensvm.train.test.split.R
@@ -60,8 +60,7 @@ gensvm.train.test.split <- function(x, y=NULL, train.size=NULL, test.size=NULL,
return.idx=FALSE)
{
if (!is.null(y) && dim(as.matrix(x))[1] != dim(as.matrix(y))[1]) {
- cat("Error: First dimension of x and y should be equal.\n")
- return
+ stop("Error: First dimension of x and y should be equal.\n")
}
n.objects <- dim(as.matrix(x))[1]
diff --git a/R/predict.gensvm.R b/R/predict.gensvm.R
index 43a0d52..b9a9d7a 100644
--- a/R/predict.gensvm.R
+++ b/R/predict.gensvm.R
@@ -61,9 +61,7 @@ predict.gensvm <- function(object, newdata, add.rownames=FALSE, ...)
# Sanity check
if (ncol(x.test) != object$n.features) {
- cat("Error: Number of features of fitted model and testing",
- "data disagree.\n")
- return(invisible(NULL))
+ stop("Error: Number of features of fitted model and testing data disagree.\n")
}
x.train <- eval.parent(object$call$x)
diff --git a/R/predict.gensvm.grid.R b/R/predict.gensvm.grid.R
index 9d0bc53..e74822d 100644
--- a/R/predict.gensvm.grid.R
+++ b/R/predict.gensvm.grid.R
@@ -49,8 +49,7 @@
predict.gensvm.grid <- function(object, newdata, ...)
{
if (is.null(object$best.estimator)) {
- cat("Error: Can't predict, the best.estimator element is NULL\n")
- return
+ stop("Error: Can't predict, the best.estimator element is NULL\n")
}
return(predict(object$best.estimator, newdata, ...))