The R Project SVN R-packages

Rev

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

Rev 4160 Rev 4590
Line 85... Line 85...
85
    else if (strcmp(class, "ordered") == 0) return "int";
85
    else if (strcmp(class, "ordered") == 0) return "int";
86
    
86
    
87
    return NULL;
87
    return NULL;
88
}
88
}
89
 
89
 
-
 
90
int _get_r_type(const char *decl_type) {
-
 
91
    if (strcmp(decl_type, "int") == 0) return INTSXP;
-
 
92
    else if (strcmp(decl_type, "double") == 0) return REALSXP;
-
 
93
    else if (strcmp(decl_type, "text") == 0) return STRSXP;
-
 
94
    else if (strcmp(decl_type, "bit") == 0) return LGLSXP;
-
 
95
    return -1;
-
 
96
}
-
 
97
 
90
const char *_get_r_class(const char *db, const char *type) {
98
const char *_get_r_class(const char *db, const char *type) {
91
    return NULL;
99
    return NULL;
92
}
100
}
93
 
101
 
94
int _get_row_count2(const char *table, int quote) {
102
int _get_row_count2(const char *table, int quote) {
Line 344... Line 352...
344
    int i;
352
    int i;
345
    for (i = 0; ref[i]; i++) out[i] = tolower(ref[i]);
353
    for (i = 0; ref[i]; i++) out[i] = tolower(ref[i]);
346
    out[i] = 0;
354
    out[i] = 0;
347
    return out;
355
    return out;
348
}
356
}
-
 
357
 
-
 
358
/* note that *plen must be initialized with the # of rows of the indexed
-
 
359
 * vector. this is used win idx is a boolean, so that we can recycle it to
-
 
360
 * span the whole vector.
-
 
361
 * NOTE: index returned is 1-based */
-
 
362
int *_make_row_index(SEXP idx, int *plen) {
-
 
363
    int idxlen = LENGTH(idx), len = *plen, i, k;
-
 
364
    int *ret;
-
 
365
 
-
 
366
    if (IS_NUMERIC(idx)) {
-
 
367
        double tmp;
-
 
368
        ret = (int *)R_alloc(idxlen, sizeof(int));
-
 
369
        for (i = k = 0; i < idxlen; i++) {
-
 
370
            tmp = REAL(idx)[i];
-
 
371
            if (!(tmp == NA_REAL || tmp < 1)) ret[k++] = (int) tmp;
-
 
372
 
-
 
373
            /*
-
 
374
            if (tmp == NA_REAL) ret[i] = NA_INTEGER;
-
 
375
            else if (tmp < 1) ret[i] = NA_INTEGER;
-
 
376
            else ret[i] = (int) tmp;
-
 
377
            */
-
 
378
        }
-
 
379
        *plen = k;
-
 
380
    } else if (IS_INTEGER(idx)) {
-
 
381
        int tmp;
-
 
382
        ret = (int *)R_alloc(idxlen, sizeof(int));
-
 
383
        for (i = k = 0; i < idxlen; i++) {
-
 
384
            tmp = INTEGER(idx)[i];
-
 
385
            if (!(tmp == NA_REAL || tmp < 1)) ret[k++] = (int) tmp;
-
 
386
            /*
-
 
387
            if (tmp < 1) ret[i] = NA_INTEGER;
-
 
388
            else ret[i] = tmp;
-
 
389
            */
-
 
390
        }
-
 
391
        *plen = k;
-
 
392
    } else if (IS_LOGICAL(idx)) {
-
 
393
        int k, tmp;  /* to deal with recycling */
-
 
394
        ret = (int *)R_alloc(len, sizeof(int));
-
 
395
        for (i = k = 0; i < len; i++) {
-
 
396
            /* i index the values, j the index sexp, k the output index */
-
 
397
            if (LOGICAL(idx)[i%idxlen]) ret[k++] = i+1;
-
 
398
            /* ret[k++] = (LOGICAL(idx)[j%idxlen]) ? i : NA_INTEGER; */
-
 
399
        }
-
 
400
        *plen = k;
-
 
401
    }
-
 
402
 
-
 
403
    return ret;
-
 
404
}