/usr/share/doc/r-cran-matrixstats/tests/rowVarDiffs.R is in r-cran-matrixstats 0.14.2-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | library("matrixStats")
FUNs <- list(
rowVarDiffs=list(rowVarDiffs, colVarDiffs),
rowSdDiffs=list(rowSdDiffs, colSdDiffs),
rowMadDiffs=list(rowMadDiffs, colMadDiffs),
rowIQRDiffs=list(rowIQRDiffs, colIQRDiffs)
)
for (fcn in names(FUNs)) {
cat(sprintf("%s()...\n", fcn))
rFUN <- FUNs[[fcn]][[1L]]
cFUN <- FUNs[[fcn]][[2L]]
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# With and without some NAs
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
for (mode in c("integer", "double")) {
for (addNA in c(FALSE, TRUE)) {
cat("addNA=", addNA, "\n", sep="")
x <- matrix(1:100+0.1, nrow=20, ncol=5)
if (addNA) {
x[13:17,c(2,4)] <- NA_real_
}
cat("mode: ", mode, "\n", sep="")
storage.mode(x) <- mode
str(x)
# Row/column ranges
for (na.rm in c(FALSE, TRUE)) {
cat("na.rm=", na.rm, "\n", sep="")
r1 <- rFUN(x, na.rm=na.rm)
r2 <- cFUN(t(x), na.rm=na.rm)
stopifnot(all.equal(r1, r2))
}
} # for (addNA ...)
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# All NAs
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
for (mode in c("integer", "double")) {
x <- matrix(NA_real_, nrow=20, ncol=5)
cat("mode: ", mode, "\n", sep="")
storage.mode(x) <- mode
str(x)
for (na.rm in c(FALSE, TRUE)) {
cat("na.rm=", na.rm, "\n", sep="")
r1 <- rFUN(x, na.rm=na.rm)
r2 <- cFUN(t(x), na.rm=na.rm)
stopifnot(all.equal(r1, r2))
}
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# A 1x1 matrix
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
x <- matrix(0, nrow=1, ncol=1)
for (na.rm in c(FALSE, TRUE)) {
cat("na.rm=", na.rm, "\n", sep="")
r1 <- rFUN(x, na.rm=na.rm)
r2 <- cFUN(t(x), na.rm=na.rm)
stopifnot(all.equal(r1, r2))
}
cat(sprintf("%s()...DONE\n", fcn))
} # for (fcn ...)
|