The R Project SVN R

Rev

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

Rev 6191 Rev 6994
Line 111... Line 111...
111
   Check that only one index is being selected. */
111
   Check that only one index is being selected. */
112
 
112
 
113
int get1index(SEXP s, SEXP names, int len, int pok)
113
int get1index(SEXP s, SEXP names, int len, int pok)
114
{
114
{
115
    int index, i;
115
    int index, i;
-
 
116
    double dblind;
116
 
117
 
117
    if (length(s) > 1)
118
    if (length(s) > 1)
118
	error("attempt to select more than one element");
119
	error("attempt to select more than one element");
119
    if (length(s) < 1)
120
    if (length(s) < 1)
120
	error("attempt to select less than one element");
121
	error("attempt to select less than one element");
121
 
122
 
122
    index = -1;
123
    index = -1;
123
    switch (TYPEOF(s)) {
124
    switch (TYPEOF(s)) {
124
    case LGLSXP:
125
    case LGLSXP:
125
    case INTSXP:
126
    case INTSXP:
-
 
127
	i = INTEGER(s)[0];
-
 
128
	if(i == NA_INTEGER) 
-
 
129
	    index = -1;
-
 
130
	else
126
	index = integerOneIndex(INTEGER(s)[0], len);
131
	    index = integerOneIndex(i, len);
127
	break;
132
	break;
128
    case REALSXP:
133
    case REALSXP:
-
 
134
	dblind = REAL(s)[0];
-
 
135
	if(ISNAN(dblind)) 
-
 
136
	    index = -1;
-
 
137
	else
129
	index = integerOneIndex(REAL(s)[0], len);
138
	    index = integerOneIndex((int)dblind, len);
130
	break;
139
	break;
131
    case STRSXP:
140
    case STRSXP:
132
	/* Try for exact match */
141
	/* Try for exact match */
133
	for (i = 0; i < length(names); i++)
142
	for (i = 0; i < length(names); i++)
134
	    if (streql(CHAR(STRING(names)[i]), CHAR(STRING(s)[0]))) {
143
	    if (streql(CHAR(STRING(names)[i]), CHAR(STRING(s)[0]))) {