##
## 1. equal
##
stopifnot(
all.equal(compareLengths(1:3, 4:6), c("equal", ''))
)
##
## 2. compatible
##
a <- 1:2
b <- letters[1:6]
comp.ab <- compareLengths(a, b, message0='Chk:')
comp.ba <- compareLengths(b, a, message0='Chk:')
# check
chk.ab <- c('compatible',
'Chk: length(b) = 6 is 3 times length(a) = 2')
stopifnot(
all.equal(comp.ab, chk.ab)
)
stopifnot(
all.equal(comp.ba, chk.ab)
)
##
## 3. incompatible
##
Z <- LETTERS[1:3]
comp.aZ <- compareLengths(a, Z)
# check
chk.aZ <- c('incompatible',
' length(Z) = 3 is not a multiple of length(a) = 2')
stopifnot(
all.equal(comp.aZ, chk.aZ)
)
##
## 4. problems with name.x and name.y
##
comp.ab2 <- compareLengths(a, b, '', '')
# check
chk.ab2 <- c('compatible',
'in compareLengths: length(y) = 6 is 3 times length(x) = 2')
stopifnot(
all.equal(comp.ab2, chk.ab2)
)
##
## 5. zeroLength
##
zeroLen <- compareLengths(logical(0), 1)
# check
zeroL <- c('compatible', ' length(logical(0)) = 0')
stopifnot(
all.equal(zeroLen, zeroL)
)
Run the code above in your browser using DataLab