Skip to content

Commit

Permalink
Merge pull request #372 from imbs-hl/issue371
Browse files Browse the repository at this point in the history
Accept variable named 'none'
  • Loading branch information
mnwright committed Dec 7, 2018
2 parents 976c058 + 88f1daa commit 3136a55
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 7 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
@@ -1,8 +1,8 @@
Package: ranger
Type: Package
Title: A Fast Implementation of Random Forests
Version: 0.10.5
Date: 2018-09-13
Version: 0.10.6
Date: 2018-12-07
Author: Marvin N. Wright [aut, cre], Stefan Wager [ctb], Philipp Probst [ctb]
Maintainer: Marvin N. Wright <cran@wrig.de>
Description: A fast implementation of Random Forests, particularly suited for high
Expand Down
3 changes: 3 additions & 0 deletions NEWS
@@ -1,3 +1,6 @@
##### Version 0.10.6
* Bug fixes

##### Version 0.10.5
* Add support of splitting weights for corrected impurity importance
* Bug fixes
Expand Down
3 changes: 3 additions & 0 deletions NEWS.md
@@ -1,3 +1,6 @@
##### Version 0.10.6
* Bug fixes

##### Version 0.10.5
* Add support of splitting weights for corrected impurity importance
* Bug fixes
Expand Down
2 changes: 1 addition & 1 deletion R/predict.R
Expand Up @@ -268,7 +268,7 @@ predict.ranger.forest <- function(object, data, predict.all = FALSE,
}

## Defaults for variables not needed
dependent.variable.name <- "none"
dependent.variable.name <- ""
mtry <- 0
importance <- 0
min.node.size <- 0
Expand Down
4 changes: 2 additions & 2 deletions R/ranger.R
Expand Up @@ -246,7 +246,7 @@ ranger <- function(formula = NULL, data = NULL, num.trees = 500, mtry = NULL,
stop("Error: Please give formula or dependent variable name.")
}
if (is.null(status.variable.name)) {
status.variable.name <- "none"
status.variable.name <- ""
response <- data[, dependent.variable.name, drop = TRUE]
} else {
response <- survival::Surv(data[, dependent.variable.name], data[, status.variable.name]) #data[, c(dependent.variable.name, status.variable.name)]
Expand Down Expand Up @@ -310,7 +310,7 @@ ranger <- function(formula = NULL, data = NULL, num.trees = 500, mtry = NULL,
status.variable.name <- dimnames(response)[[2]][2]
} else {
dependent.variable.name <- names(data.selected)[1]
status.variable.name <- "none"
status.variable.name <- ""
}
independent.variable.names <- names(data.selected)[-1]
} else {
Expand Down
2 changes: 1 addition & 1 deletion cpp_version/src/version.h
@@ -1,3 +1,3 @@
#ifndef RANGER_VERSION
#define RANGER_VERSION "0.10.5"
#define RANGER_VERSION "0.10.6"
#endif
9 changes: 8 additions & 1 deletion tests/testthat/test_ranger.R
Expand Up @@ -330,4 +330,11 @@ test_that("Meaningful predictions with max.depth = 1", {
expect_lte(max(pred), max(iris$Sepal.Length))
})


test_that("Does not crash when variable named 'none'", {
dat <- data.frame(y = rbinom(100, 1, .5),
x = rbinom(100, 1, .5),
none = rbinom(100, 1, .5))
rf <- ranger(data = dat, dependent.variable.name = "y")
expect_equal(rf$forest$independent.variable.names, c("x", "none"))
expect_silent(predict(rf, dat))
})

0 comments on commit 3136a55

Please sign in to comment.