Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/bsplines.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/cpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 7 additions & 7 deletions tests/test-bsplineD.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
})

Expand All @@ -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)
Expand Down
22 changes: 11 additions & 11 deletions tests/test-bsplines.R
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand All @@ -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."))
})

Expand All @@ -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))
Expand All @@ -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))
Expand Down Expand Up @@ -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"))
})

Expand All @@ -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)
Expand Down
20 changes: 10 additions & 10 deletions tests/test-order_statistics.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down