diff --git a/src/bsplines.cpp b/src/bsplines.cpp index b523ebf..dc4b2c1 100644 --- a/src/bsplines.cpp +++ b/src/bsplines.cpp @@ -23,7 +23,7 @@ Rcpp::NumericMatrix cpp_bsplines(arma::vec x, arma::vec iknots, arma::vec bknots Rcpp::NumericMatrix cpp_bsplinesD1(arma::vec x, arma::vec iknots, arma::vec bknots, unsigned int order) { if ((order - 1) <= 0) { - Rf_error("(order - 1) <= 0"); + Rcpp::stop("(order - 1) <= 0"); } bbasis B0(x, iknots, bknots, order); @@ -74,7 +74,7 @@ Rcpp::NumericMatrix cpp_bsplinesD1(arma::vec x, arma::vec iknots, arma::vec bkno Rcpp::NumericMatrix cpp_bsplinesD2(arma::vec x, arma::vec iknots, arma::vec bknots, unsigned int order) { if ((order - 2) <= 0) { - Rf_error("(order - 2) <= 0"); + Rcpp::stop("(order - 2) <= 0"); } bbasis B0(x, iknots, bknots, order); diff --git a/src/cpr.cpp b/src/cpr.cpp index 7f0caa9..c7c13e3 100644 --- a/src/cpr.cpp +++ b/src/cpr.cpp @@ -32,7 +32,7 @@ bbasis::bbasis(arma::vec& x_, arma::vec & iknots_, arma::vec & bknots_, unsigned } if (!xi.is_sorted()) { - Rf_error("Knots are not sorted."); + Rcpp::stop("Knots are not sorted."); } // define xi_star diff --git a/tests/test-bsplineD.R b/tests/test-bsplineD.R index 83f84ad..5d1204c 100644 --- a/tests/test-bsplineD.R +++ b/tests/test-bsplineD.R @@ -75,15 +75,15 @@ with(e, { stopifnot(isTRUE( all.equal(cprD2[-100, ], baseD2[-100, ]))) x <- tryCatch(bsplineD(xvec, derivative = 1.5), error = function(e) {e}) - stopifnot(identical(class(x), c("simpleError", "error", "condition"))) + stopifnot(inherits(x, "error")) stopifnot(identical(x$message, "Only first and second derivatives are supported")) x <- tryCatch(bsplineD(xvec, derivative = 3), error = function(e) {e}) - stopifnot(identical(class(x), c("simpleError", "error", "condition"))) + stopifnot(inherits(x, "error")) stopifnot(identical(x$message, "Only first and second derivatives are supported")) x <- tryCatch(bsplineD(xvec, order = 2, derivative = 2), error = function(e) {e}) - stopifnot(identical(class(x), c("simpleError", "error", "condition"))) + stopifnot(inherits(x, "error")) stopifnot(identical(x$message, "(order - 2) <= 0")) }) @@ -97,16 +97,16 @@ with(e, { bmatD1 <- tryCatch(bsplineD(xvec, bknots = bknots, order = 1, derivative = 1L), error = function(e) e) bmatD2 <- tryCatch(bsplineD(xvec, bknots = bknots, order = 1, derivative = 2L), error = function(e) e) - stopifnot(inherits(bmat, "simpleError")) - stopifnot(inherits(bmatD1, "simpleError")) - stopifnot(inherits(bmatD2, "simpleError")) + stopifnot(inherits(bmat, "error")) + stopifnot(inherits(bmatD1, "error")) + stopifnot(inherits(bmatD2, "error")) stopifnot(identical(bmat$message, "order needs to be an integer value >= 2.")) stopifnot(identical(bmatD1$message, "order needs to be an integer value >= 2.")) stopifnot(identical(bmatD2$message, "order needs to be an integer value >= 2.")) bmat <- tryCatch(bsplines(xvec, bknots = bknots, order = 1.9), error = function(e) e) - stopifnot(inherits(bmat, "simpleError")) + stopifnot(inherits(bmat, "error")) stopifnot(identical(bmat$message, "order needs to be an integer value >= 2.")) bmat <- tryCatch(bsplines(xvec, bknots = bknots, order = 2.9), error = function(e) e) diff --git a/tests/test-bsplines.R b/tests/test-bsplines.R index b24a993..bb8f2c1 100644 --- a/tests/test-bsplines.R +++ b/tests/test-bsplines.R @@ -68,7 +68,7 @@ with(e, { bknots = c(-1, 1) x <- tryCatch(bsplines(xvec, iknots = iknots, bknots = bknots), error = function(e) {e}) - stopifnot(inherits(x, "simpleError")) + stopifnot(inherits(x, "error")) stopifnot(identical(x$message, "Knots are not sorted.")) x <- tryCatch(bsplines(xvec, iknots = sort(iknots), bknots = bknots), error = function(e) {e}) @@ -92,7 +92,7 @@ with(e, { e <- new.env() with(e, { x <- tryCatch(bsplines(list(1:10)), error = function(e) { e }) - stopifnot(inherits(x, "simpleError")) + stopifnot(inherits(x, "error")) stopifnot("error if list passed to bsplines" = identical(x$message, "x is a list. Use btensor instead of bsplines.")) }) @@ -104,7 +104,7 @@ with(e, { bknots <- c(-1, 1) x <- tryCatch(bsplines(xvec, df = 2, bknots = bknots), warning = function(w) {w}) - stopifnot(identical(class(x), c("simpleWarning", "warning", "condition"))) + stopifnot(inherits(x, "warning")) stopifnot(identical(x$message, "df being set to order")) x <- suppressWarnings(bsplines(xvec, df = 2, bknots = bknots)) @@ -118,7 +118,7 @@ with(e, { stopifnot(isTRUE(all.equal(x, z, check.attributes = FALSE))) x <- tryCatch(bsplines(xvec, iknots = 0.2, df = 6, bknots = bknots), warning = function(w) {w}) - stopifnot(identical(class(x), c("simpleWarning", "warning", "condition"))) + stopifnot(inherits(x, "warning")) stopifnot(identical(x$message, "Both iknots and df defined, using iknots")) x <- suppressWarnings(bsplines(xvec, iknots = 0.2, df = 6, bknots = bknots)) @@ -210,16 +210,16 @@ with(e, { stopifnot(isTRUE( all.equal(cprD2[-100, ], baseD2[-100, ]))) x <- tryCatch(bsplineD(xvec, derivative = 1.5), error = function(e) {e}) - stopifnot(identical(class(x), c("simpleError", "error", "condition"))) + stopifnot(inherits(x, "error")) stopifnot(identical(x$message, "Only first and second derivatives are supported")) rm(x) x <- tryCatch(bsplineD(xvec, derivative = 3), error = function(e) {e}) - stopifnot(identical(class(x), c("simpleError", "error", "condition"))) + stopifnot(inherits(x, "error")) stopifnot(identical(x$message, "Only first and second derivatives are supported")) x <- tryCatch(bsplineD(xvec, order = 2, derivative = 2), error = function(e) {e}) - stopifnot(identical(class(x), c("simpleError", "error", "condition"))) + stopifnot(inherits(x, "error")) stopifnot(identical(x$message, "(order - 2) <= 0")) }) @@ -233,16 +233,16 @@ with(e, { bmatD1 <- tryCatch(bsplineD(xvec, bknots = bknots, order = 1, derivative = 1L), error = function(e) e) bmatD2 <- tryCatch(bsplineD(xvec, bknots = bknots, order = 1, derivative = 2L), error = function(e) e) - stopifnot(inherits(bmat, "simpleError")) - stopifnot(inherits(bmatD1, "simpleError")) - stopifnot(inherits(bmatD2, "simpleError")) + stopifnot(inherits(bmat, "error")) + stopifnot(inherits(bmatD1, "error")) + stopifnot(inherits(bmatD2, "error")) stopifnot(identical(bmat$message, "order needs to be an integer value >= 2.")) stopifnot(identical(bmatD1$message, "order needs to be an integer value >= 2.")) stopifnot(identical(bmatD2$message, "order needs to be an integer value >= 2.")) bmat <- tryCatch(bsplines(xvec, bknots = bknots, order = 1.9), error = function(e) e) - stopifnot(inherits(bmat, "simpleError")) + stopifnot(inherits(bmat, "error")) stopifnot(identical(bmat$message, "order needs to be an integer value >= 2.")) bmat <- tryCatch(bsplines(xvec, bknots = bknots, order = 2.9), error = function(e) e) diff --git a/tests/test-order_statistics.R b/tests/test-order_statistics.R index ecd9c3f..58b4e84 100644 --- a/tests/test-order_statistics.R +++ b/tests/test-order_statistics.R @@ -76,11 +76,11 @@ e <- new.env() with(e, { d <- tryCatch(d_order_statistic(x = x, n = 4:6, j = 2, distribution = "norm") , error = function(e) e) - stopifnot(inherits(d, "simpleError")) + stopifnot(inherits(d, "error")) stopifnot(d$message == "length(n) == 1 is not TRUE") p <- tryCatch(p_order_statistic(q = x, n = 4:6, j = 2, distribution = "norm") , error = function(e) e) - stopifnot(inherits(p, "simpleError")) + stopifnot(inherits(p, "error")) stopifnot(p$message == "length(n) == 1 is not TRUE") }) rm(e) @@ -89,12 +89,12 @@ e <- new.env() with(e, { d <- tryCatch(d_order_statistic(x = x, n = numeric(0), j = 2, distribution = "norm") , error = function(e) e) - stopifnot(inherits(d, "simpleError")) + stopifnot(inherits(d, "error")) stopifnot(d$message == "length(n) == 1 is not TRUE") p <- tryCatch(p_order_statistic(q = x, n = numeric(0), j = 2, distribution = "norm") , error = function(e) e) - stopifnot(inherits(p, "simpleError")) + stopifnot(inherits(p, "error")) stopifnot(p$message == "length(n) == 1 is not TRUE") }) rm(e) @@ -103,12 +103,12 @@ e <- new.env() with(e, { d <- tryCatch(d_order_statistic(x = 0, n = NA_real_, j = 2, distribution = "norm") , error = function(e) e) - stopifnot(inherits(d, "simpleError")) + stopifnot(inherits(d, "error")) stopifnot(d$message == "!is.na(n) is not TRUE") p <- tryCatch(p_order_statistic(q = 0, n = NA_real_, j = 2, distribution = "norm") , error = function(e) e) - stopifnot(inherits(p, "simpleError")) + stopifnot(inherits(p, "error")) stopifnot(p$message == "!is.na(n) is not TRUE") }) rm(e) @@ -117,12 +117,12 @@ e <- new.env() with(e, { d <- tryCatch(d_order_statistic(x = 0, n = 10, j = 11, distribution = "norm") , error = function(e) e) - stopifnot(inherits(d, "simpleError")) + stopifnot(inherits(d, "error")) stopifnot(d$message == "n >= stats::na.omit(j) is not TRUE") p <- tryCatch(p_order_statistic(q = 0, n = 10, j = 11, distribution = "norm") , error = function(e) e) - stopifnot(inherits(p, "simpleError")) + stopifnot(inherits(p, "error")) stopifnot(p$message == "n >= stats::na.omit(j) is not TRUE") }) rm(e) @@ -131,12 +131,12 @@ e <- new.env() with(e, { d <- tryCatch(d_order_statistic(x = 0, n = 10, j = -1, distribution = "norm") , error = function(e) e) - stopifnot(inherits(d, "simpleError")) + stopifnot(inherits(d, "error")) stopifnot(d$message == "stats::na.omit(j) >= 1 is not TRUE") p <- tryCatch(p_order_statistic(q = 0, n = 10, j = -1, distribution = "norm") , error = function(e) e) - stopifnot(inherits(p, "simpleError")) + stopifnot(inherits(p, "error")) stopifnot(p$message == "stats::na.omit(j) >= 1 is not TRUE") }) rm(e)