The R Project SVN R

Rev

Rev 10921 | Rev 15317 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 10921 Rev 14913
Line 375... Line 375...
375
	*stretch = extra;
375
	*stretch = extra;
376
    UNPROTECT(4);
376
    UNPROTECT(4);
377
    return indx;
377
    return indx;
378
}
378
}
379
 
379
 
-
 
380
/* Array Subscripts.  
380
/* Array Subscripts.  dim is the dimension (0 to k-1), s is */
381
    dim is the dimension (0 to k-1)
-
 
382
    s is the subscript list, 
-
 
383
    dims is the dimensions of x
-
 
384
    dng is a function (usually getAttrib) that obtains the dimnames
381
/* the subscript list, x is the array to be subscripted. */
385
    x is the array to be subscripted. 
-
 
386
*/
382
 
387
 
-
 
388
typedef SEXP DimNamesGetter(SEXP x, SEXP data);
-
 
389
 
383
SEXP arraySubscript(int dim, SEXP s, SEXP x)
390
SEXP arraySubscript(int dim, SEXP s, SEXP dims, DimNamesGetter dng, SEXP x)
384
{
391
{
385
    int nd, ns, stretch = 0;
392
    int nd, ns, stretch = 0;
386
    SEXP dims, dnames, tmp;
393
    SEXP dnames, tmp;
387
    ns = length(s);
394
    ns = length(s);
388
    dims = getAttrib(x, R_DimSymbol);
-
 
389
    nd = INTEGER(dims)[dim];
395
    nd = INTEGER(dims)[dim];
390
 
396
 
391
    switch (TYPEOF(s)) {
397
    switch (TYPEOF(s)) {
392
    case NILSXP:
398
    case NILSXP:
393
	return allocVector(INTSXP, 0);
399
	return allocVector(INTSXP, 0);
Line 399... Line 405...
399
    	PROTECT(tmp = coerceVector(s, INTSXP));
405
    	PROTECT(tmp = coerceVector(s, INTSXP));
400
	tmp = integerSubscript(tmp, ns, nd, &stretch);
406
	tmp = integerSubscript(tmp, ns, nd, &stretch);
401
    	UNPROTECT(1);
407
    	UNPROTECT(1);
402
	return tmp;
408
	return tmp;
403
    case STRSXP:
409
    case STRSXP:
404
	dnames = getAttrib(x, R_DimNamesSymbol);
410
	dnames = dng(x, R_DimNamesSymbol);
405
	if (dnames == R_NilValue)
411
	if (dnames == R_NilValue)
406
	    error("no dimnames attribute for array");
412
	    error("no dimnames attribute for array");
407
	dnames = VECTOR_ELT(dnames, dim);
413
	dnames = VECTOR_ELT(dnames, dim);
408
	return stringSubscript(s, ns, nd, dnames, &stretch);
414
	return stringSubscript(s, ns, nd, dnames, &stretch);
409
    case SYMSXP:
415
    case SYMSXP: