Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add checks to prediction output #136

Merged
merged 1 commit into from
Jul 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ This release is intended to be the last before stable version 1.0.0.

## Major changes

- Factor-valued predictions are not anymore supported.
- Factor-valued predictions are not supported anymore.

## Maintenance

- Fix CRAN note about unavailable link to `gam::gam()`.
- Added dependency to {MASS} for calculating Moore-Penrose generalized matrix inverse.
- Slight code improvements.

# kernelshap 0.5.0

Expand Down
8 changes: 7 additions & 1 deletion R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,13 @@ align_pred <- function(x) {
if (is.data.frame(x) && ncol(x) == 1L) {
x <- x[[1L]]
}
as.matrix(x)
if (!is.matrix(x)) {
x <- as.matrix(x)
}
if (!is.numeric(x) && !is.logical(x)) {
stop("Predictions must be numeric!")
}
return(x)
}

#' Head of List Elements
Expand Down
5 changes: 5 additions & 0 deletions tests/testthat/test-utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,8 @@ test_that("wrowmean_vector() works for 1D matrices", {
expect_equal(out2, cbind(a = c(a, b)))
})

test_that("align_pred() works", {
expect_error(align_pred(c("A", "B")))
expect_error(align_pred(factor(c("A", "B"))))
expect_equal(align_pred(1:4), as.matrix(1:4))
})
Loading