The R Project SVN R

Rev

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

Rev 49990 Rev 50896
Line 318... Line 318...
318
    }
318
    }
319
    UNPROTECT(1);
319
    UNPROTECT(1);
320
    return (rvec);
320
    return (rvec);
321
}
321
}
322
 
322
 
-
 
323
/*
-
 
324
Special Matrix Subscripting: For the case x[i] where x is an n-way
-
 
325
array and i is a character matrix with n columns, this code converts i
-
 
326
to an integer matrix by matching against the dimnames of x. NA values
-
 
327
in any row of i propagate to the result.  Unmatched entries result in
-
 
328
a subscript out of bounds error.  */
-
 
329
 
-
 
330
SEXP attribute_hidden strmat2intmat(SEXP s, SEXP dnamelist, SEXP call)
-
 
331
{
-
 
332
    /* XXX: assumes all args are protected */
-
 
333
    int nr = nrows(s), i, j, v, idx;
-
 
334
    SEXP dnames, snames, si, sicol, s_elt;
-
 
335
    PROTECT(snames = allocVector(STRSXP, nr));
-
 
336
    PROTECT(si = allocVector(INTSXP, length(s)));
-
 
337
    dimgets(si, getAttrib(s, R_DimSymbol));
-
 
338
    for (i = 0; i < length(dnamelist); i++) {
-
 
339
        dnames = VECTOR_ELT(dnamelist, i);
-
 
340
        for (j = 0; j < nr; j++) {
-
 
341
            SET_STRING_ELT(snames, j, STRING_ELT(s, j + (i * nr)));
-
 
342
        }
-
 
343
        PROTECT(sicol = match(dnames, snames, 0));
-
 
344
        for (j = 0; j < nr; j++) {
-
 
345
            v = INTEGER(sicol)[j];
-
 
346
            idx = j + (i * nr);
-
 
347
            s_elt = STRING_ELT(s, idx);
-
 
348
            if (s_elt == NA_STRING) v = NA_INTEGER;
-
 
349
            if (!CHAR(s_elt)[0]) v = 0; /* disallow "" match */
-
 
350
            if (v == 0) errorcall(call, _("subscript out of bounds"));
-
 
351
            INTEGER(si)[idx] = v;
-
 
352
        }
-
 
353
        UNPROTECT(1);
-
 
354
    }
-
 
355
    UNPROTECT(2);
-
 
356
    return si;
-
 
357
}
-
 
358
 
323
static SEXP nullSubscript(int n)
359
static SEXP nullSubscript(int n)
324
{
360
{
325
    int i;
361
    int i;
326
    SEXP indx;
362
    SEXP indx;
327
    indx = allocVector(INTSXP, n);
363
    indx = allocVector(INTSXP, n);