Skip to content

Commit

Permalink
Suppress warning of rankMatrix
Browse files Browse the repository at this point in the history
Added testthat to check correct fix
Fixes #24
  • Loading branch information
hofnerb committed Dec 17, 2015
1 parent 0aec1ac commit 74d80f4
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 2 deletions.
3 changes: 2 additions & 1 deletion pkg/mboostPatch/DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ Depends: R (>= 2.14.0), methods, stats, parallel, stabs (>= 0.5-0)
Imports: Matrix, survival, splines, lattice, nnls, quadprog, utils,
graphics, grDevices, party (>= 1.0-23)
Suggests: TH.data, MASS, fields, BayesX, gbm, mlbench,
RColorBrewer, rpart (>= 4.0-3), randomForest, nnet
RColorBrewer, rpart (>= 4.0-3), randomForest, nnet,
testthat (>= 0.10.0)
LazyData: yes
License: GPL-2
BugReports: https://github.com/hofnerb/mboost/issues
Expand Down
2 changes: 1 addition & 1 deletion pkg/mboostPatch/R/bl.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ df2lambda <- function(X, df = 4, lambda = NULL, dmat = NULL, weights,

stopifnot(xor(is.null(df), is.null(lambda)))
if (!is.null(df)) {
rank_X <- rankMatrix(X, method = 'qr')
rank_X <- rankMatrix(X, method = 'qr', warn.t = FALSE)
if (df >= rank_X) {
if (df > rank_X)
warning(sQuote("df"),
Expand Down
4 changes: 4 additions & 0 deletions pkg/mboostPatch/tests/testthat.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
library("testthat")
library("mboost")

test_check("mboost")
21 changes: 21 additions & 0 deletions pkg/mboostPatch/tests/testthat/test-baselearners.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
library(mboost)
set.seed(1234)

testthat("rankMatrix does not give a warning", {
## setting with 'p>n' should not give warning in rankMatrix()
n <- 10
x1 <- rnorm(n)
y <- 2*x1
expect_that(mod1 <- mboost(y ~ bbs(x1, df = 4)),
not(gives_warning()))
expect_equal(dim(extract(mod1, "design")[[1]]),
c(10, 24))
## for comparison: setting with 'p<n'
n <- 30
x1 <- rnorm(n)
y <- 2*x1
expect_that(mod2 <- mboost(y ~ bbs(x1, df = 4)),
not(gives_warning()))
expect_equal(dim(extract(mod2, "design")[[1]]),
c(30, 24))
})

0 comments on commit 74d80f4

Please sign in to comment.