Skip to content

Commit

Permalink
Fix: selected numeric TypeError in dependence()
Browse files Browse the repository at this point in the history
  • Loading branch information
brian-j-smith committed Apr 19, 2022
1 parent 39c743a commit b09d393
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions R/dependence.R
Original file line number Diff line number Diff line change
Expand Up @@ -64,23 +64,27 @@ dependence <- function(
throw(check_assignment(stats))

select_values <- function(x) {
if (is.factor(x)) {
if (is(x, "factor")) {
unique(x)
} else if (is.vector(x)) {
} else if (is(x, "logical")) {
intersect(c(FALSE, TRUE), x)
} else if (is(x, "numeric") || is(x, "Date")) {
x <- sort(x)
n <- min(n, length(x))
switch(intervals,
unique(switch(intervals,
"quantile" = x[round(seq(1, length(x), length = n))],
"uniform" = {
y <- seq(x[1], x[length(x)], length = n)
indices <- findInterval(y, x, all.inside = TRUE)
x_lower <- x[indices]
x_upper <- x[indices + 1]
unique(ifelse(y - x_lower < x_upper - y, x_lower, x_upper))
ifelse(y - x_lower < x_upper - y, x_lower, x_upper)
}
)
))
} else {
throw(TypeError(x, c("factor", "vector"), "selected variable"))
throw(TypeError(
x, c("Date", "factor", "logical", "numeric"), "selected variable"
))
}
}

Expand Down

0 comments on commit b09d393

Please sign in to comment.