Skip to content

Commit e82b378

Browse files
committed
feat: allow features of type logical
1 parent 16bf190 commit e82b378

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# randomPlantedForest 0.2.1.9000 (Development version)
22

3+
* Allow features of type `logical`, which are now converted via `as.integer`.
34
* The `parallel = TRUE|FALSE` argument in `rpf()` has been substituted by an `nthreads = 1L` argument, allowing for more flexible parallelization.
45
The previous behavior only allowed for either no parallelization or using n-1 of n available cores.
56
The new implementation should be reasonably robust and the default behavior remains serial execution.

R/utils.R

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,12 @@ pca_order <- function(x, y) {
8080
preprocess_predictors_fit <- function(processed) {
8181
predictors <- as.data.table(processed$predictors)
8282

83+
# Convert logicals to binary integers
84+
logical_cols <- names(which(sapply(predictors, is.logical)))
85+
if (length(logical_cols) > 0) {
86+
predictors[, (logical_cols) := lapply(.SD, as.integer), .SDcols = logical_cols]
87+
}
88+
8389
# Convert characters to factors
8490
char_cols <- names(which(sapply(predictors, is.character)))
8591
if (length(char_cols) > 0) {
@@ -114,6 +120,12 @@ preprocess_predictors_fit <- function(processed) {
114120
preprocess_predictors_predict <- function(object, predictors) {
115121
predictors <- as.data.table(predictors)
116122

123+
# Convert logicals to binary integers
124+
logical_cols <- names(which(sapply(predictors, is.logical)))
125+
if (length(logical_cols) > 0) {
126+
predictors[, (logical_cols) := lapply(.SD, as.integer), .SDcols = logical_cols]
127+
}
128+
117129
# Convert characters to factors
118130
char_cols <- names(which(sapply(predictors, is.character)))
119131
if (length(char_cols) > 0) {
@@ -152,7 +164,7 @@ preprocess_outcome <- function(processed, loss) {
152164

153165
if (is_binary & is_integerish) {
154166
warning(paste(
155-
"y is binary integer, assuming regression task.",
167+
"y is a binary integer, assuming regression task.",
156168
"Recode y to a factor for classification."
157169
))
158170
}

0 commit comments

Comments
 (0)