The R Project SVN R

Rev

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

Rev 60314 Rev 63166
Line 19... Line 19...
19
 *
19
 *
20
 * EXPORTS:
20
 * EXPORTS:
21
 *
21
 *
22
 *  OneIndex()        -- used for "[[<-" in ./subassign.c
22
 *  OneIndex()        -- used for "[[<-" in ./subassign.c
23
 *  get1index()       -- used for "[["   in ./subassign.c & subset.c
23
 *  get1index()       -- used for "[["   in ./subassign.c & subset.c
24
 *  vectorIndex()     -- used for "[[" with a vector arg
24
 *  vectorIndex()     -- used for "[[" and "[[<-" with a vector arg
25
 
25
 
26
 *  mat2indsub()      -- for "mat[i]"     "    "            "
26
 *  mat2indsub()      -- for "mat[i]"     "    "            "
27
 
27
 
28
 *  makeSubscript()   -- for "[" and "[<-" in ./subset.c and ./subassign.c,
28
 *  makeSubscript()   -- for "[" and "[<-" in ./subset.c and ./subassign.c,
29
 *			 and "[[<-" with a scalar in ./subassign.c
29
 *			 and "[[<-" with a scalar in ./subassign.c
Line 271... Line 271...
271
}
271
}
272
 
272
 
273
/* This is used for [[ and [[<- with a vector of indices of length > 1 .
273
/* This is used for [[ and [[<- with a vector of indices of length > 1 .
274
   x is a list or pairlist, and it is indexed recusively from 
274
   x is a list or pairlist, and it is indexed recusively from 
275
   level start to level stop-1.  ( 0...len-1 or 0..len-2 then len-1).
275
   level start to level stop-1.  ( 0...len-1 or 0..len-2 then len-1).
-
 
276
   For [[<- it needs to duplicate if substructure has NAMED > 1.
276
 */
277
 */
277
SEXP attribute_hidden
278
SEXP attribute_hidden
278
vectorIndex(SEXP x, SEXP thesub, int start, int stop, int pok, SEXP call) 
279
vectorIndex(SEXP x, SEXP thesub, int start, int stop, int pok, SEXP call,
-
 
280
	    Rboolean dup) 
279
{
281
{
280
    int i;
282
    int i;
281
    R_xlen_t offset;
283
    R_xlen_t offset;
-
 
284
    SEXP cx;
-
 
285
 
-
 
286
    /* sanity check */
-
 
287
    if (dup && NAMED(x) > 1)
-
 
288
	error("should only be called in an assignment context.");
282
 
289
 
283
    for(i = start; i < stop; i++) {
290
    for(i = start; i < stop; i++) {
284
	if(!isVectorList(x) && !isPairList(x)) {
291
	if(!isVectorList(x) && !isPairList(x)) {
285
	    if (i)
292
	    if (i)
286
		errorcall(call, _("recursive indexing failed at level %d\n"), i+1);
293
		errorcall(call, _("recursive indexing failed at level %d\n"), i+1);
Line 294... Line 301...
294
	if(isPairList(x)) {
301
	if(isPairList(x)) {
295
#ifdef LONG_VECTOR_SUPPORT
302
#ifdef LONG_VECTOR_SUPPORT
296
	    if (offset > R_SHORT_LEN_MAX)
303
	    if (offset > R_SHORT_LEN_MAX)
297
		error("invalid subscript for pairlist");
304
		error("invalid subscript for pairlist");
298
#endif
305
#endif
299
	    x = CAR(nthcdr(x, (int) offset));
306
	    cx = nthcdr(x, (int) offset);
-
 
307
	    x = CAR(cx);
-
 
308
	    if (dup && NAMED(x) > 1) {
-
 
309
		x = duplicate(x);
-
 
310
		nthcdr(x, (int) offset);
-
 
311
	    }
300
	} else {
312
	} else {
-
 
313
	    cx = x;
301
	    x = VECTOR_ELT(x, offset);
314
	    x = VECTOR_ELT(x, offset);
-
 
315
	    if (dup && NAMED(x) > 1) {
-
 
316
		x = duplicate(x);
-
 
317
		SET_VECTOR_ELT(cx, offset, x);
-
 
318
	    }
302
    	}
319
    	}
303
    }
320
    }
304
    return x;
321
    return x;
305
}
322
}
306
 
323