source('kruskal.test.R')

help(kruskal.test)

data(mtcars)
mtcars$type <- rep(letters[1:2], c(16, 16))
is.vector(mtcars$type) ## TRUE

with(mtcars, kruskal.test(mpg, type))
## Error in kruskal.test.default(c(21, 21, 22.8, 21.4, 18.7, 18.1, 14.3,  : 
##   all group levels must be finite

kruskal.test(mpg ~ type, mtcars)
## Error in kruskal.test.default(c(21, 21, 22.8, 21.4, 18.7, 18.1, 14.3,  : 
##   all group levels must be finite

mtcars$type <- rep(1:2, c(16, 16))
kruskal.test(mpg ~ type, mtcars) # works

mtcars$type <- factor(mtcars$type)
kruskal.test(mpg ~ type, mtcars) # works

mtcars$type <- rep(c(8, Inf), c(16, 16))
kruskal.test(mpg ~ type, mtcars) # should fail
