/** * Returns the selection array or vector. * * <p>The selSizes array contains sizes of the selectors (number of elements that will be * returned by it). The idx array contains the indices returned by the selectors (that is the * indices used to compute the source offset). * * <p>The selIdx array contains the position in the selector (when this is equal to the selector * size the selector has overflown). */ public Object execute(RArray source, boolean drop, int exact) throws UnexpectedResultException { int[] sourceDim = source.dimensions(); boolean mayHaveNA = Selector.initialize(offsets, selectorVals, sourceDim, selSizes, ast); int[] destDim = Selector.calculateDestinationDimensions(selSizes, !subset || drop); int destSize = Selector.calculateSizeFromSelectorSizes(selSizes); RArray dest = Utils.createArray(source, destSize, destDim, null, null); // drop attributes if (destSize == 0) { return dest; } int offset = 0; for (; ; ) { int sourceOffset = offsets[0]; if (sourceOffset == RInt.NA) { Utils.setNA(dest, offset); } else { dest.set(offset, source.getRef(sourceOffset)); } offset++; if (offset < destSize) { if (!mayHaveNA) { Selector.advanceNoNA(offsets, sourceDim, selectorVals, ast); } else { Selector.advance(offsets, sourceDim, selectorVals, ast); } } else { break; } } return dest; }