The R Project SVN R

Rev

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

Rev 22883 Rev 24735
Line 223... Line 223...
223
static SEXP logicalSubscript(SEXP s, int ns, int nx, int *stretch)
223
static SEXP logicalSubscript(SEXP s, int ns, int nx, int *stretch)
224
{
224
{
225
    int canstretch, count, i, nmax;
225
    int canstretch, count, i, nmax;
226
    SEXP indx;
226
    SEXP indx;
227
    canstretch = *stretch;
227
    canstretch = *stretch;
228
#ifdef OLD
-
 
229
    if (ns > nx)
-
 
230
	error("subscript (%d) out of bounds, should be at most %d",
-
 
231
	      ns, nx);
-
 
232
#else
-
 
233
    if (!canstretch && ns > nx)
228
    if (!canstretch && ns > nx)
234
	error("(subscript) logical subscript too long");
229
	error("(subscript) logical subscript too long");
235
    nmax = (ns > nx) ? ns : nx;
230
    nmax = (ns > nx) ? ns : nx;
236
    *stretch = (ns > nx) ? ns : 0;
231
    *stretch = (ns > nx) ? ns : 0;
237
#endif
-
 
238
    if (ns == 0)
232
    if (ns == 0)
239
	return(allocVector(INTSXP, 0));
233
	return(allocVector(INTSXP, 0));
240
    count = 0;
234
    count = 0;
241
#ifdef BROKEN
-
 
242
    for (i = 0; i < nx; i++)
-
 
243
#else
-
 
244
    for (i = 0; i < nmax; i++)
235
    for (i = 0; i < nmax; i++)
245
#endif
-
 
246
	if (LOGICAL(s)[i%ns])
236
	if (LOGICAL(s)[i%ns])
247
	    count++;
237
	    count++;
248
    indx = allocVector(INTSXP, count);
238
    indx = allocVector(INTSXP, count);
249
    count = 0;
239
    count = 0;
250
#ifdef OLD
-
 
251
    for (i = 0; i < nx; i++)
-
 
252
#else
-
 
253
    for (i = 0; i < nmax; i++)
240
    for (i = 0; i < nmax; i++)
254
#endif
-
 
255
	if (LOGICAL(s)[i%ns]) {
241
	if (LOGICAL(s)[i%ns]) {
256
	    if (LOGICAL(s)[i%ns] == NA_LOGICAL)
242
	    if (LOGICAL(s)[i%ns] == NA_LOGICAL)
257
		INTEGER(indx)[count++] = NA_INTEGER;
243
		INTEGER(indx)[count++] = NA_INTEGER;
258
	    else
244
	    else
259
		INTEGER(indx)[count++] = i + 1;
245
		INTEGER(indx)[count++] = i + 1;