Skip to content

Commit

Permalink
center = TRUE/FALSE throws an error in bols. Fixes #70
Browse files Browse the repository at this point in the history
(cherry picked from commit e10a432)
  • Loading branch information
hofnerb committed Feb 15, 2017
1 parent c6c849c commit 2354122
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
9 changes: 8 additions & 1 deletion R/bl.R
Original file line number Diff line number Diff line change
Expand Up @@ -404,8 +404,15 @@ bols <- function(..., by = NULL, index = NULL, intercept = TRUE, df = NULL,

cll <- match.call()
cll[[1]] <- as.name("bols")

mf <- list(...)

## check that center = TRUE/FALSE is not specified in ...
if ("center" %in% names(mf) &&
(length(mf[["center"]]) == 1 && is.logical(mf[["center"]])))
stop(sQuote("bols(, center = TRUE/FALSE)"), " is deprecated. Please use ",
sQuote("bols(, intercept = TRUE/FALSE)"), " instead.")

if (length(mf) == 1 && ((isMATRIX(mf[[1]]) || is.data.frame(mf[[1]])) &&
ncol(mf[[1]]) > 1 )) {
mf <- mf[[1]]
Expand Down
2 changes: 1 addition & 1 deletion tests/bugfixes.R
Original file line number Diff line number Diff line change
Expand Up @@ -533,4 +533,4 @@ if (require("survival")){
summary(cbind(ipcw1, ipcw2))

stopifnot(identical(ipcw1, ipcw2))
}
}
20 changes: 20 additions & 0 deletions tests/testthat/test-baselearners.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,23 @@ test_that("extrapolation is possible for kronecker product, kronecker product an
})


test_that("center = TRUE/FALSE throws an error in bols", {
data("bodyfat", package = "TH.data")

expect_error(mboost(DEXfat ~ bols(waistcirc, center=TRUE), data = bodyfat), regexp = ".*deprecated.*")
expect_error(mboost(DEXfat ~ bols(waistcirc, center=FALSE), data = bodyfat), regexp = ".*deprecated.*")
expect_error(mboost(DEXfat ~ bols(waistcirc, center=T), data = bodyfat), regexp = ".*deprecated.*")
expect_error(mboost(DEXfat ~ bols(waistcirc, center=F), data = bodyfat), regexp = ".*deprecated.*")

## not throw errors if variable is called center
bodyfat$center <- rnorm(nrow(bodyfat))
mod <- mboost(DEXfat ~ bols(waistcirc, center), data = bodyfat)
expect_length(coef(mod)[[1]], 3)
expect_equal(names(coef(mod)[[1]])[3], "center")

## not throw errors if logical variable is called center
bodyfat$center <- sample(c(TRUE, FALSE), nrow(bodyfat), replace = TRUE)
mod <- mboost(DEXfat ~ bols(waistcirc, center), data = bodyfat)
expect_length(coef(mboost(DEXfat ~ bols(waistcirc, center), data = bodyfat))[[1]], 3)
expect_equal(names(coef(mod)[[1]])[3], "centerTRUE")
})

0 comments on commit 2354122

Please sign in to comment.