library(abind)
x <- array(1:24,dim=c(2,3,4),dimnames=list(letters[1:2],LETTERS[1:3],letters[23:26]))
dimnames(x)
dimnames(asub(x, 1, 1))
# example using y to check that we're getting the right 'x' in the eval inside asub()
y <- array(1:24,dim=c(2,3,4),dimnames=list(LETTERS[1:2],letters[1:3],LETTERS[23:26]))
dimnames(asub(y, 1, 1, drop=TRUE))
dimnames(asub(x, 1, 1, drop=FALSE))
dimnames(asub(x, 1, 2))
dimnames(asub(x, 1, 2, drop=TRUE))
dimnames(asub(x, 1, 2, drop=FALSE))
dimnames(asub(x, 1, 3))
dimnames(asub(x, 1, 3, drop=TRUE))
dimnames(asub(x, 1, 3, drop=FALSE))
dimnames(asub(x, 1:2, 1))
dimnames(asub(x, 1:2, 1, drop=TRUE))
dimnames(asub(x, 1:2, 1, drop=FALSE))
dimnames(asub(x, 1:2, 2))
dimnames(asub(x, 1:2, 2, drop=TRUE))
dimnames(asub(x, 1:2, 2, drop=FALSE))
dimnames(asub(x, 1:2, 3))
dimnames(asub(x, 1:2, 3, drop=TRUE))
dimnames(asub(x, 1:2, 3, drop=FALSE))
dimnames(asub(x, list(1:2,2), c(1,2)))
dimnames(asub(x, list(1:2,2), c(1,2), drop=TRUE))
dimnames(asub(x, list(1:2,2), c(1,2), drop=FALSE))
dimnames(asub(x, list(1:2,2), c(2,1)))
dimnames(asub(x, list(1:2,2), c(2,1), drop=TRUE))
dimnames(asub(x, list(1:2,2), c(2,1), drop=FALSE))
dimnames(asub(x, list(1:2,2), c(1,3)))
dimnames(asub(x, list(1:2,2), c(1,3), drop=TRUE))
dimnames(asub(x, list(1:2,2), c(1,3), drop=FALSE))
dimnames(asub(x, list(1:2,2), c(3,1)))
dimnames(asub(x, list(1:2,2), c(3,1), drop=TRUE))
dimnames(asub(x, list(1:2,2), c(3,1), drop=FALSE))
dimnames(asub(x, list(1:2,2), c(3,2)))
dimnames(asub(x, list(1:2,2), c(3,2), drop=TRUE))
dimnames(asub(x, list(1:2,2), c(3,2), drop=FALSE))
dimnames(asub(x, list(1:2,2), c(2,3)))
dimnames(asub(x, list(1:2,2), c(2,3), drop=TRUE))
dimnames(asub(x, list(1:2,2), c(2,3), drop=FALSE))
dimnames(asub(x, list(1:2,2:3,1:2), c(1,2,3)))
dimnames(asub(x, list(1:2,2:3,1:2), c(1,3,2)))
dimnames(asub(x, list(1:2,2:3,1:2)))
dimnames(asub(x, list(1:2,2,1:2)))
x <- 5:1
asub(x, 2:3)
asub(x, list(2:3))
x <- matrix(1:6, ncol=2)
asub(x, list(2:3,NULL))
asub(x, list(2:3,NULL), drop=FALSE)
asub(x, list(NULL,1), drop=FALSE)
asub(x, list(1), 1, drop=FALSE)
asub(x, list(1), 2, drop=FALSE)
i <- 1
asub(x, i, 1)
(function() {i <- 2; asub(x, i, 1)})()
j <- 3
(function() {i <- 2; asub(x, j, 1)})()
j <- 1
(function() {i <- 2; asub(x, j, i)})()
(function() {i <- 2; (function() asub(x, j, i))()})()

# 10-d example
x <- array(seq(len=prod(1:10)), dim=1:10)
dim(x)
dim(asub(x, 1, 1))
dim(asub(x, 1, 2))
dim(asub(x, 1, 3))
dim(asub(x, 1, 3, drop=F))
dim(asub(x, list(1,1), c(3,5), drop=F))
dim(asub(x, list(1,1), c(3,5)))
