\HeaderA{controlledSubsetting}{Subsetting of Arrays}{controlledSubsetting}
\keyword{utilities}{controlledSubsetting}
\begin{Description}\relax
Finer control on the drop argument as in []
\end{Description}
\begin{Usage}
\begin{verbatim}controlledSubsetting(a, ranges, drop)\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{a}] array; required; default: missing.
\item[\code{ranges}] list of vectors; list length must match
dimensionality of a; each element of the
numeric vector specifies
the subset of the corresponding dimension of a;
if is.na(element) the whole corresponding dimension is kept;
required; default: missing.
\item[\code{drop}] optional; specifies each dimension of array a which will
be dropped, the corresponding subset must specify exact one
element; if missing all such subsets are dropped;
default: missing.
\end{ldescription}
\end{Arguments}
\begin{Details}\relax
\end{Details}
\begin{Value}
subsetted array
\end{Value}
\begin{Author}\relax
Andreas Buness <a.buness@dkfz.de>
\end{Author}
\begin{SeeAlso}\relax
\code{\LinkA{controlledApply}{controlledApply}}
\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
            a <- array(1:400, dim=c(2,3,5,6))
            r <- controlledSubsetting(a=a, ranges=list(1,2,3,2), drop=2)
            stopifnot(length(dim(r)) == 3 )
            stopifnot(r == a[1,2,3,2])
            r <- controlledSubsetting(a=a, ranges=list(2,1:2,2,2:3), drop=3)
            stopifnot( all(r[1,,,drop=TRUE] == a[2,1:2,2,2:3]) )
            r <- controlledSubsetting(a=a, ranges=list(1:2,1:2,2,3), drop=3)
            stopifnot( all(r[,,1,drop=TRUE] == a[1:2,1:2,2,3]) )
            r <- controlledSubsetting(a=a, ranges=list(1:2,1:2,2,3), drop=c(3,4))
            stopifnot( all(r == a[1:2,1:2,2,3]) )
            r <- controlledSubsetting(a=a, ranges=list(1:2,1:2,1:5,3), drop=c(4))
            stopifnot( all(r == a[1:2,1:2,1:5,3]) )
            r <- controlledSubsetting(a=a, ranges=list(NA,NA,1:5,3), drop=c(4))
            stopifnot( all(r == a[,,1:5,3]) )

        \end{ExampleCode}
\end{Examples}

