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
|
library("listenv")
message("*** lapply() ...")
x <- as.list(1:6)
names(x) <- letters[seq_along(x)]
y <- as.listenv(x)
z0 <- lapply(x, FUN = function(x) x^2)
z1 <- lapply(y, FUN = function(x) x^2)
stopifnot(identical(z1, z0))
message("*** lapply() ... DONE")
message("*** apply() ...")
x <- matrix(as.list(1:6), nrow = 2)
rownames(x) <- letters[seq_len(nrow(x))]
colnames(x) <- LETTERS[seq_len(ncol(x))]
y <- as.listenv(x)
z0 <- apply(x, MARGIN = 1L, FUN = function(x) sum(unlist(x)))
## FIXME: Implement proper aperm() for listenv
aperm.listenv <- function(a, ...) {
a <- as.list(a)
a <- aperm(a, ...)
as.listenv(a)
}
z1 <- apply(y, MARGIN = 1L, FUN = function(x) sum(unlist(x)))
stopifnot(identical(z1, z0))
message("*** apply() ... DONE")
|