gbm-developers / gbm

Gradient boosted models (the old gbm package)
Other
51 stars 27 forks source link

Posible minor bug when if statement is being applied to a logical vector with more than one element. #71

Closed Samuel99-2 closed 9 months ago

Samuel99-2 commented 1 year ago

In the gbm.fit function i got thrown the error "Error in if (nrow(x) != ifelse(class(y) == "Surv", nrow(y), length(y))) { : the condition has length > 1"

I think this is because the condition inside the if statement is not a single logical value, but rather a vector of logical values.

This error is likely to occur if the class() function is being applied to the y vector or matrix, and the result is a character vector with more than one element. For example, if y is a matrix with multiple columns, and each column has a different class, then the class() function will return a character vector with one element for each column in y. In this case, the ifelse() function would return a logical vector with the same length as the character vector, which would cause the error when the if statement is executed.

I modified my own local version to ensure that the class() function returns a single character value, rather than a character vector with multiple elements. I believe this problem is fixed if "class(y)" is replaced with "class(y[1,1])"

I would suggest implementing this in the gbm package

gregridgeway commented 9 months ago

Replaced class(y) with a call to inherits() in 2.1.9