I wonder if there could be any reason behind such default behavior? If there are some consistency quirks about that I would be glad to know.
Below two different queries (resulting into 20 and 0 lengths), but I would expect them to have same behavior about dropping redundant dimensions. Subset by NULL seems to keep empty dimension for some reason. ?drop states:
Delete the dimensions of an array which have only one level.
What's the point of keeping 0 level dimensions with drop=TRUE?
I'm developing array-like class and I've hit inconsistency to base::array because of that. Should I report such issue to R dev platform?
set.seed(1L)
ar.dimnames = list(color = sort(c("green","yellow","red")),
year = as.character(2011:2015),
status = sort(c("active","inactive","archived","removed")))
ar.dim = sapply(ar.dimnames, length)
ar = array(sample(c(rep(NA, 4), 4:7/2), prod(ar.dim), TRUE),
unname(ar.dim),
ar.dimnames)
r1 = ar["green",,,drop=TRUE]
dimnames(r1)
#$year
#[1] "2011" "2012" "2013" "2014" "2015"
#
#$status
#[1] "active" "archived" "inactive" "removed"
#
length(r1)
#[1] 20
r2 = ar[NULL,,,drop=TRUE]
dimnames(r2)
#$color
#NULL
#
#$year
#[1] "2011" "2012" "2013" "2014" "2015"
#
#$status
#[1] "active" "archived" "inactive" "removed"
#
length(r2)
#[1] 0