Skip to content

Commit daae751

Browse files
authored
Merge pull request #63 from Enchufa2/main
Use Rcpp's stop function
2 parents 4e57525 + 8200932 commit daae751

5 files changed

Lines changed: 31 additions & 31 deletions

File tree

src/bsplines.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Rcpp::NumericMatrix cpp_bsplines(arma::vec x, arma::vec iknots, arma::vec bknots
2323
Rcpp::NumericMatrix cpp_bsplinesD1(arma::vec x, arma::vec iknots, arma::vec bknots, unsigned int order) {
2424

2525
if ((order - 1) <= 0) {
26-
Rf_error("(order - 1) <= 0");
26+
Rcpp::stop("(order - 1) <= 0");
2727
}
2828

2929
bbasis B0(x, iknots, bknots, order);
@@ -74,7 +74,7 @@ Rcpp::NumericMatrix cpp_bsplinesD1(arma::vec x, arma::vec iknots, arma::vec bkno
7474
Rcpp::NumericMatrix cpp_bsplinesD2(arma::vec x, arma::vec iknots, arma::vec bknots, unsigned int order) {
7575

7676
if ((order - 2) <= 0) {
77-
Rf_error("(order - 2) <= 0");
77+
Rcpp::stop("(order - 2) <= 0");
7878
}
7979

8080
bbasis B0(x, iknots, bknots, order);

src/cpr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ bbasis::bbasis(arma::vec& x_, arma::vec & iknots_, arma::vec & bknots_, unsigned
3232
}
3333

3434
if (!xi.is_sorted()) {
35-
Rf_error("Knots are not sorted.");
35+
Rcpp::stop("Knots are not sorted.");
3636
}
3737

3838
// define xi_star

tests/test-bsplineD.R

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,15 @@ with(e, {
7575
stopifnot(isTRUE( all.equal(cprD2[-100, ], baseD2[-100, ])))
7676

7777
x <- tryCatch(bsplineD(xvec, derivative = 1.5), error = function(e) {e})
78-
stopifnot(identical(class(x), c("simpleError", "error", "condition")))
78+
stopifnot(inherits(x, "error"))
7979
stopifnot(identical(x$message, "Only first and second derivatives are supported"))
8080

8181
x <- tryCatch(bsplineD(xvec, derivative = 3), error = function(e) {e})
82-
stopifnot(identical(class(x), c("simpleError", "error", "condition")))
82+
stopifnot(inherits(x, "error"))
8383
stopifnot(identical(x$message, "Only first and second derivatives are supported"))
8484

8585
x <- tryCatch(bsplineD(xvec, order = 2, derivative = 2), error = function(e) {e})
86-
stopifnot(identical(class(x), c("simpleError", "error", "condition")))
86+
stopifnot(inherits(x, "error"))
8787
stopifnot(identical(x$message, "(order - 2) <= 0"))
8888
})
8989

@@ -97,16 +97,16 @@ with(e, {
9797
bmatD1 <- tryCatch(bsplineD(xvec, bknots = bknots, order = 1, derivative = 1L), error = function(e) e)
9898
bmatD2 <- tryCatch(bsplineD(xvec, bknots = bknots, order = 1, derivative = 2L), error = function(e) e)
9999

100-
stopifnot(inherits(bmat, "simpleError"))
101-
stopifnot(inherits(bmatD1, "simpleError"))
102-
stopifnot(inherits(bmatD2, "simpleError"))
100+
stopifnot(inherits(bmat, "error"))
101+
stopifnot(inherits(bmatD1, "error"))
102+
stopifnot(inherits(bmatD2, "error"))
103103

104104
stopifnot(identical(bmat$message, "order needs to be an integer value >= 2."))
105105
stopifnot(identical(bmatD1$message, "order needs to be an integer value >= 2."))
106106
stopifnot(identical(bmatD2$message, "order needs to be an integer value >= 2."))
107107

108108
bmat <- tryCatch(bsplines(xvec, bknots = bknots, order = 1.9), error = function(e) e)
109-
stopifnot(inherits(bmat, "simpleError"))
109+
stopifnot(inherits(bmat, "error"))
110110
stopifnot(identical(bmat$message, "order needs to be an integer value >= 2."))
111111

112112
bmat <- tryCatch(bsplines(xvec, bknots = bknots, order = 2.9), error = function(e) e)

tests/test-bsplines.R

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ with(e, {
6868
bknots = c(-1, 1)
6969

7070
x <- tryCatch(bsplines(xvec, iknots = iknots, bknots = bknots), error = function(e) {e})
71-
stopifnot(inherits(x, "simpleError"))
71+
stopifnot(inherits(x, "error"))
7272
stopifnot(identical(x$message, "Knots are not sorted."))
7373

7474
x <- tryCatch(bsplines(xvec, iknots = sort(iknots), bknots = bknots), error = function(e) {e})
@@ -92,7 +92,7 @@ with(e, {
9292
e <- new.env()
9393
with(e, {
9494
x <- tryCatch(bsplines(list(1:10)), error = function(e) { e })
95-
stopifnot(inherits(x, "simpleError"))
95+
stopifnot(inherits(x, "error"))
9696
stopifnot("error if list passed to bsplines" = identical(x$message, "x is a list. Use btensor instead of bsplines."))
9797
})
9898

@@ -104,7 +104,7 @@ with(e, {
104104
bknots <- c(-1, 1)
105105

106106
x <- tryCatch(bsplines(xvec, df = 2, bknots = bknots), warning = function(w) {w})
107-
stopifnot(identical(class(x), c("simpleWarning", "warning", "condition")))
107+
stopifnot(inherits(x, "warning"))
108108
stopifnot(identical(x$message, "df being set to order"))
109109

110110
x <- suppressWarnings(bsplines(xvec, df = 2, bknots = bknots))
@@ -118,7 +118,7 @@ with(e, {
118118
stopifnot(isTRUE(all.equal(x, z, check.attributes = FALSE)))
119119

120120
x <- tryCatch(bsplines(xvec, iknots = 0.2, df = 6, bknots = bknots), warning = function(w) {w})
121-
stopifnot(identical(class(x), c("simpleWarning", "warning", "condition")))
121+
stopifnot(inherits(x, "warning"))
122122
stopifnot(identical(x$message, "Both iknots and df defined, using iknots"))
123123

124124
x <- suppressWarnings(bsplines(xvec, iknots = 0.2, df = 6, bknots = bknots))
@@ -210,16 +210,16 @@ with(e, {
210210
stopifnot(isTRUE( all.equal(cprD2[-100, ], baseD2[-100, ])))
211211

212212
x <- tryCatch(bsplineD(xvec, derivative = 1.5), error = function(e) {e})
213-
stopifnot(identical(class(x), c("simpleError", "error", "condition")))
213+
stopifnot(inherits(x, "error"))
214214
stopifnot(identical(x$message, "Only first and second derivatives are supported"))
215215
rm(x)
216216

217217
x <- tryCatch(bsplineD(xvec, derivative = 3), error = function(e) {e})
218-
stopifnot(identical(class(x), c("simpleError", "error", "condition")))
218+
stopifnot(inherits(x, "error"))
219219
stopifnot(identical(x$message, "Only first and second derivatives are supported"))
220220

221221
x <- tryCatch(bsplineD(xvec, order = 2, derivative = 2), error = function(e) {e})
222-
stopifnot(identical(class(x), c("simpleError", "error", "condition")))
222+
stopifnot(inherits(x, "error"))
223223
stopifnot(identical(x$message, "(order - 2) <= 0"))
224224
})
225225

@@ -233,16 +233,16 @@ with(e, {
233233
bmatD1 <- tryCatch(bsplineD(xvec, bknots = bknots, order = 1, derivative = 1L), error = function(e) e)
234234
bmatD2 <- tryCatch(bsplineD(xvec, bknots = bknots, order = 1, derivative = 2L), error = function(e) e)
235235

236-
stopifnot(inherits(bmat, "simpleError"))
237-
stopifnot(inherits(bmatD1, "simpleError"))
238-
stopifnot(inherits(bmatD2, "simpleError"))
236+
stopifnot(inherits(bmat, "error"))
237+
stopifnot(inherits(bmatD1, "error"))
238+
stopifnot(inherits(bmatD2, "error"))
239239

240240
stopifnot(identical(bmat$message, "order needs to be an integer value >= 2."))
241241
stopifnot(identical(bmatD1$message, "order needs to be an integer value >= 2."))
242242
stopifnot(identical(bmatD2$message, "order needs to be an integer value >= 2."))
243243

244244
bmat <- tryCatch(bsplines(xvec, bknots = bknots, order = 1.9), error = function(e) e)
245-
stopifnot(inherits(bmat, "simpleError"))
245+
stopifnot(inherits(bmat, "error"))
246246
stopifnot(identical(bmat$message, "order needs to be an integer value >= 2."))
247247

248248
bmat <- tryCatch(bsplines(xvec, bknots = bknots, order = 2.9), error = function(e) e)

tests/test-order_statistics.R

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,11 @@ e <- new.env()
7676
with(e, {
7777
d <- tryCatch(d_order_statistic(x = x, n = 4:6, j = 2, distribution = "norm")
7878
, error = function(e) e)
79-
stopifnot(inherits(d, "simpleError"))
79+
stopifnot(inherits(d, "error"))
8080
stopifnot(d$message == "length(n) == 1 is not TRUE")
8181
p <- tryCatch(p_order_statistic(q = x, n = 4:6, j = 2, distribution = "norm")
8282
, error = function(e) e)
83-
stopifnot(inherits(p, "simpleError"))
83+
stopifnot(inherits(p, "error"))
8484
stopifnot(p$message == "length(n) == 1 is not TRUE")
8585
})
8686
rm(e)
@@ -89,12 +89,12 @@ e <- new.env()
8989
with(e, {
9090
d <- tryCatch(d_order_statistic(x = x, n = numeric(0), j = 2, distribution = "norm")
9191
, error = function(e) e)
92-
stopifnot(inherits(d, "simpleError"))
92+
stopifnot(inherits(d, "error"))
9393
stopifnot(d$message == "length(n) == 1 is not TRUE")
9494

9595
p <- tryCatch(p_order_statistic(q = x, n = numeric(0), j = 2, distribution = "norm")
9696
, error = function(e) e)
97-
stopifnot(inherits(p, "simpleError"))
97+
stopifnot(inherits(p, "error"))
9898
stopifnot(p$message == "length(n) == 1 is not TRUE")
9999
})
100100
rm(e)
@@ -103,12 +103,12 @@ e <- new.env()
103103
with(e, {
104104
d <- tryCatch(d_order_statistic(x = 0, n = NA_real_, j = 2, distribution = "norm")
105105
, error = function(e) e)
106-
stopifnot(inherits(d, "simpleError"))
106+
stopifnot(inherits(d, "error"))
107107
stopifnot(d$message == "!is.na(n) is not TRUE")
108108

109109
p <- tryCatch(p_order_statistic(q = 0, n = NA_real_, j = 2, distribution = "norm")
110110
, error = function(e) e)
111-
stopifnot(inherits(p, "simpleError"))
111+
stopifnot(inherits(p, "error"))
112112
stopifnot(p$message == "!is.na(n) is not TRUE")
113113
})
114114
rm(e)
@@ -117,12 +117,12 @@ e <- new.env()
117117
with(e, {
118118
d <- tryCatch(d_order_statistic(x = 0, n = 10, j = 11, distribution = "norm")
119119
, error = function(e) e)
120-
stopifnot(inherits(d, "simpleError"))
120+
stopifnot(inherits(d, "error"))
121121
stopifnot(d$message == "n >= stats::na.omit(j) is not TRUE")
122122

123123
p <- tryCatch(p_order_statistic(q = 0, n = 10, j = 11, distribution = "norm")
124124
, error = function(e) e)
125-
stopifnot(inherits(p, "simpleError"))
125+
stopifnot(inherits(p, "error"))
126126
stopifnot(p$message == "n >= stats::na.omit(j) is not TRUE")
127127
})
128128
rm(e)
@@ -131,12 +131,12 @@ e <- new.env()
131131
with(e, {
132132
d <- tryCatch(d_order_statistic(x = 0, n = 10, j = -1, distribution = "norm")
133133
, error = function(e) e)
134-
stopifnot(inherits(d, "simpleError"))
134+
stopifnot(inherits(d, "error"))
135135
stopifnot(d$message == "stats::na.omit(j) >= 1 is not TRUE")
136136

137137
p <- tryCatch(p_order_statistic(q = 0, n = 10, j = -1, distribution = "norm")
138138
, error = function(e) e)
139-
stopifnot(inherits(p, "simpleError"))
139+
stopifnot(inherits(p, "error"))
140140
stopifnot(p$message == "stats::na.omit(j) >= 1 is not TRUE")
141141
})
142142
rm(e)

0 commit comments

Comments
 (0)