R Under development (unstable) (2024-09-10 r87115 ucrt) -- "Unsuffered Consequences" Copyright (C) 2024 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > library(abind) > x <- array(1:24,dim=c(2,3,4),dimnames=list(letters[1:2],LETTERS[1:3],letters[23:26])) > dimnames(x) [[1]] [1] "a" "b" [[2]] [1] "A" "B" "C" [[3]] [1] "w" "x" "y" "z" > dimnames(asub(x, 1, 1)) [[1]] [1] "A" "B" "C" [[2]] [1] "w" "x" "y" "z" > # 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)) [[1]] [1] "a" "b" "c" [[2]] [1] "W" "X" "Y" "Z" > dimnames(asub(x, 1, 1, drop=FALSE)) [[1]] [1] "a" [[2]] [1] "A" "B" "C" [[3]] [1] "w" "x" "y" "z" > dimnames(asub(x, 1, 2)) [[1]] [1] "a" "b" [[2]] [1] "w" "x" "y" "z" > dimnames(asub(x, 1, 2, drop=TRUE)) [[1]] [1] "a" "b" [[2]] [1] "w" "x" "y" "z" > dimnames(asub(x, 1, 2, drop=FALSE)) [[1]] [1] "a" "b" [[2]] [1] "A" [[3]] [1] "w" "x" "y" "z" > dimnames(asub(x, 1, 3)) [[1]] [1] "a" "b" [[2]] [1] "A" "B" "C" > dimnames(asub(x, 1, 3, drop=TRUE)) [[1]] [1] "a" "b" [[2]] [1] "A" "B" "C" > dimnames(asub(x, 1, 3, drop=FALSE)) [[1]] [1] "a" "b" [[2]] [1] "A" "B" "C" [[3]] [1] "w" > dimnames(asub(x, 1:2, 1)) [[1]] [1] "a" "b" [[2]] [1] "A" "B" "C" [[3]] [1] "w" "x" "y" "z" > dimnames(asub(x, 1:2, 1, drop=TRUE)) [[1]] [1] "a" "b" [[2]] [1] "A" "B" "C" [[3]] [1] "w" "x" "y" "z" > dimnames(asub(x, 1:2, 1, drop=FALSE)) [[1]] [1] "a" "b" [[2]] [1] "A" "B" "C" [[3]] [1] "w" "x" "y" "z" > dimnames(asub(x, 1:2, 2)) [[1]] [1] "a" "b" [[2]] [1] "A" "B" [[3]] [1] "w" "x" "y" "z" > dimnames(asub(x, 1:2, 2, drop=TRUE)) [[1]] [1] "a" "b" [[2]] [1] "A" "B" [[3]] [1] "w" "x" "y" "z" > dimnames(asub(x, 1:2, 2, drop=FALSE)) [[1]] [1] "a" "b" [[2]] [1] "A" "B" [[3]] [1] "w" "x" "y" "z" > dimnames(asub(x, 1:2, 3)) [[1]] [1] "a" "b" [[2]] [1] "A" "B" "C" [[3]] [1] "w" "x" > dimnames(asub(x, 1:2, 3, drop=TRUE)) [[1]] [1] "a" "b" [[2]] [1] "A" "B" "C" [[3]] [1] "w" "x" > dimnames(asub(x, 1:2, 3, drop=FALSE)) [[1]] [1] "a" "b" [[2]] [1] "A" "B" "C" [[3]] [1] "w" "x" > dimnames(asub(x, list(1:2,2), c(1,2))) [[1]] [1] "a" "b" [[2]] [1] "w" "x" "y" "z" > dimnames(asub(x, list(1:2,2), c(1,2), drop=TRUE)) [[1]] [1] "a" "b" [[2]] [1] "w" "x" "y" "z" > dimnames(asub(x, list(1:2,2), c(1,2), drop=FALSE)) [[1]] [1] "a" "b" [[2]] [1] "B" [[3]] [1] "w" "x" "y" "z" > dimnames(asub(x, list(1:2,2), c(2,1))) [[1]] [1] "A" "B" [[2]] [1] "w" "x" "y" "z" > dimnames(asub(x, list(1:2,2), c(2,1), drop=TRUE)) [[1]] [1] "A" "B" [[2]] [1] "w" "x" "y" "z" > dimnames(asub(x, list(1:2,2), c(2,1), drop=FALSE)) [[1]] [1] "b" [[2]] [1] "A" "B" [[3]] [1] "w" "x" "y" "z" > dimnames(asub(x, list(1:2,2), c(1,3))) [[1]] [1] "a" "b" [[2]] [1] "A" "B" "C" > dimnames(asub(x, list(1:2,2), c(1,3), drop=TRUE)) [[1]] [1] "a" "b" [[2]] [1] "A" "B" "C" > dimnames(asub(x, list(1:2,2), c(1,3), drop=FALSE)) [[1]] [1] "a" "b" [[2]] [1] "A" "B" "C" [[3]] [1] "x" > dimnames(asub(x, list(1:2,2), c(3,1))) [[1]] [1] "A" "B" "C" [[2]] [1] "w" "x" > dimnames(asub(x, list(1:2,2), c(3,1), drop=TRUE)) [[1]] [1] "A" "B" "C" [[2]] [1] "w" "x" > dimnames(asub(x, list(1:2,2), c(3,1), drop=FALSE)) [[1]] [1] "b" [[2]] [1] "A" "B" "C" [[3]] [1] "w" "x" > dimnames(asub(x, list(1:2,2), c(3,2))) [[1]] [1] "a" "b" [[2]] [1] "w" "x" > dimnames(asub(x, list(1:2,2), c(3,2), drop=TRUE)) [[1]] [1] "a" "b" [[2]] [1] "w" "x" > dimnames(asub(x, list(1:2,2), c(3,2), drop=FALSE)) [[1]] [1] "a" "b" [[2]] [1] "B" [[3]] [1] "w" "x" > dimnames(asub(x, list(1:2,2), c(2,3))) [[1]] [1] "a" "b" [[2]] [1] "A" "B" > dimnames(asub(x, list(1:2,2), c(2,3), drop=TRUE)) [[1]] [1] "a" "b" [[2]] [1] "A" "B" > dimnames(asub(x, list(1:2,2), c(2,3), drop=FALSE)) [[1]] [1] "a" "b" [[2]] [1] "A" "B" [[3]] [1] "x" > dimnames(asub(x, list(1:2,2:3,1:2), c(1,2,3))) [[1]] [1] "a" "b" [[2]] [1] "B" "C" [[3]] [1] "w" "x" > dimnames(asub(x, list(1:2,2:3,1:2), c(1,3,2))) [[1]] [1] "a" "b" [[2]] [1] "A" "B" [[3]] [1] "x" "y" > dimnames(asub(x, list(1:2,2:3,1:2))) [[1]] [1] "a" "b" [[2]] [1] "B" "C" [[3]] [1] "w" "x" > dimnames(asub(x, list(1:2,2,1:2))) [[1]] [1] "a" "b" [[2]] [1] "w" "x" > x <- 5:1 > asub(x, 2:3) [1] 4 3 > asub(x, list(2:3)) [1] 4 3 > x <- matrix(1:6, ncol=2) > asub(x, list(2:3,NULL)) [,1] [,2] [1,] 2 5 [2,] 3 6 > asub(x, list(2:3,NULL), drop=FALSE) [,1] [,2] [1,] 2 5 [2,] 3 6 > asub(x, list(NULL,1), drop=FALSE) [,1] [1,] 1 [2,] 2 [3,] 3 > asub(x, list(1), 1, drop=FALSE) [,1] [,2] [1,] 1 4 > asub(x, list(1), 2, drop=FALSE) [,1] [1,] 1 [2,] 2 [3,] 3 > i <- 1 > asub(x, i, 1) [1] 1 4 > (function() {i <- 2; asub(x, i, 1)})() [1] 2 5 > j <- 3 > (function() {i <- 2; asub(x, j, 1)})() [1] 3 6 > j <- 1 > (function() {i <- 2; asub(x, j, i)})() [1] 1 2 3 > (function() {i <- 2; (function() asub(x, j, i))()})() [1] 1 2 3 > > # 10-d example > x <- array(seq(len=prod(1:10)), dim=1:10) > dim(x) [1] 1 2 3 4 5 6 7 8 9 10 > dim(asub(x, 1, 1)) [1] 2 3 4 5 6 7 8 9 10 > dim(asub(x, 1, 2)) [1] 3 4 5 6 7 8 9 10 > dim(asub(x, 1, 3)) [1] 2 4 5 6 7 8 9 10 > dim(asub(x, 1, 3, drop=F)) [1] 1 2 1 4 5 6 7 8 9 10 > dim(asub(x, list(1,1), c(3,5), drop=F)) [1] 1 2 1 4 1 6 7 8 9 10 > dim(asub(x, list(1,1), c(3,5))) [1] 2 4 6 7 8 9 10 > > proc.time() user system elapsed 0.37 0.04 0.40