bgreenwell / fastshap

Fast approximate Shapley values in R
https://bgreenwell.github.io/fastshap/
113 stars 18 forks source link

Fix ‘copy_classes’ for older R releases #9

Closed bgreenwell closed 4 years ago

bgreenwell commented 4 years ago

See current status of tests: https://cran.r-project.org/web/checks/check_results_fastshap.html

bgreenwell commented 4 years ago

Issue seems related to this PR (which was patched in R 3.6.0): https://bugs.r-project.org/bugzilla/show_bug.cgi?id=17548

Essentially, as.matrix.data.frame() coerces TRUE -> " TRUE" whenever FALSE is also present. Consequently, coercing " TRUE" back to logical using as.logical() results an NA, as opposed to TRUE. Simple fix would be to add

x[[name]] <- if(getRversion() <= "3.6.0") {
  as.logical(trimws(x[[name]]))
} else {
  as.logical(x[[name]])
}