Skip to content

Commit

Permalink
Merge 9e6891a into ad001b9
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan van der Laan committed Jun 12, 2017
2 parents ad001b9 + 9e6891a commit bb1fc0e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
8 changes: 8 additions & 0 deletions pkg/R/gower.R
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,14 @@ gower_work <- function(x, y, pair_x, pair_y, n, eps, nthread){
}

factor_pair <- as.integer(sapply(x,is.factor))
# check factor levels
for (i in seq_along(pair)) {
if (factor_pair[i] &&
!isTRUE(all.equal(levels(x[[i]]), levels(y[[pair[i]]]))))
stop("Levels in column ", i, " of x do not match those of column ",
pair[i], " in y.")
}

eps <- as.double(eps)
# translate to C-indices (base-0).
pair <- as.integer(pair-1L)
Expand Down
7 changes: 7 additions & 0 deletions pkg/tests/testthat/test_gower.R
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,16 @@ test_that("exceptions",{
))

expect_warning(gower_dist(data.frame(x=rep(1,100)), data.frame(x=1,100)))

expect_error(gower_dist(
data.frame(a = letters[1:3], stringsAsFactors = TRUE),
data.frame(a = letters[2:4], stringsAsFactors = TRUE)
))
})




context("Top-n")

test_that("gower_topn",{
Expand Down

0 comments on commit bb1fc0e

Please sign in to comment.