# NOT RUN {
## prepare test data:
set.seed(9992722L, kind="Mersenne-Twister")
x.double=model.matrix(~gl(5,8))[sample(40), ]
## typical uses
unique(x.double)
unique(x.double, fromLast=TRUE)
unique(t(x.double), MARGIN=2)
unique(t(x.double), MARGIN=2, fromLast=TRUE)
anyDuplicated(x.double)
anyDuplicated(x.double, fromLast = TRUE)
## additional atomic test data
x.integer=as.integer(x.double); attributes(x.integer)=attributes(x.double)
x.factor=as.factor(x.integer); dim(x.factor)=dim(x.integer); dimnames(x.factor)=dimnames(x.integer)
x.logical=as.logical(x.double); attributes(x.logical)=attributes(x.double)
x.character=as.character(x.double); attributes(x.character)=attributes(x.double)
x.complex=as.complex(x.double); attributes(x.complex)=attributes(x.double)
x.raw=as.raw(x.double); attributes(x.raw)=attributes(x.double)
## compare results with base:
stopifnot(identical(base::duplicated.matrix(x.double),
uniqueAtomMat::duplicated.matrix(x.double)
))
stopifnot(identical(base::duplicated.matrix(x.integer, fromLast=TRUE),
uniqueAtomMat::duplicated.matrix(x.integer, fromLast=TRUE)
))
stopifnot(identical(base::duplicated.matrix(t(x.logical), MARGIN=2L),
uniqueAtomMat::duplicated.matrix(t(x.logical), MARGIN=2L)
))
stopifnot(identical(base::duplicated.matrix(t(x.character), MARGIN=2L, fromLast=TRUE),
uniqueAtomMat::duplicated.matrix(t(x.character), MARGIN=2L, fromLast=TRUE)
))
stopifnot(identical(base::unique.matrix(x.complex),
uniqueAtomMat::unique.matrix(x.complex)
))
stopifnot(identical(base::unique.matrix(x.raw),
uniqueAtomMat::unique.matrix(x.raw)
))
stopifnot(identical(base::unique.matrix(x.factor),
uniqueAtomMat::unique.matrix(x.factor)
))
stopifnot(identical(base::duplicated.matrix(x.double, MARGIN=0),
uniqueAtomMat::duplicated.matrix(x.double, MARGIN=0)
))
stopifnot(identical(base::anyDuplicated.matrix(x.integer, MARGIN=0),
uniqueAtomMat::anyDuplicated.matrix(x.integer, MARGIN=0)
))
## benchmarking
if (require(microbenchmark)){
print(microbenchmark(base::duplicated.matrix(x.double)))
print(microbenchmark(uniqueAtomMat::duplicated.matrix(x.double)))
print(microbenchmark(base::duplicated.matrix(x.character)))
print(microbenchmark(uniqueAtomMat::duplicated.matrix(x.character)))
}else{
print(system.time(replicate(5e3L, base::duplicated.matrix(x.double))))
print(system.time(replicate(5e3L, uniqueAtomMat::duplicated.matrix(x.double))))
print(system.time(replicate(5e3L, base::duplicated.matrix(x.character))))
print(system.time(replicate(5e3L, uniqueAtomMat::duplicated.matrix(x.character))))
}
# }
Run the code above in your browser using DataLab