The R Project SVN R

Rev

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

Rev 24516 Rev 27544
Line 41... Line 41...
41
	return lunary(call, op, CAR(args));
41
	return lunary(call, op, CAR(args));
42
    case 2:
42
    case 2:
43
	return lbinary(call, op, args);
43
	return lbinary(call, op, args);
44
    default:
44
    default:
45
	error("binary operations require two arguments");
45
	error("binary operations require two arguments");
46
	return R_NilValue;/* for -Wall */
46
	return R_NilValue;	/* for -Wall */
47
    }
47
    }
48
}
48
}
49
 
49
 
50
static SEXP lbinary(SEXP call, SEXP op, SEXP args)
50
static SEXP lbinary(SEXP call, SEXP op, SEXP args)
51
{
51
{
Line 142... Line 142...
142
static SEXP lunary(SEXP call, SEXP op, SEXP arg)
142
static SEXP lunary(SEXP call, SEXP op, SEXP arg)
143
{
143
{
144
    SEXP x, dim, dimnames, names;
144
    SEXP x, dim, dimnames, names;
145
    int i, len;
145
    int i, len;
146
 
146
 
-
 
147
    len = LENGTH(arg);
-
 
148
    if(len == 0) return(allocVector(LGLSXP, 0));
147
    if (!isLogical(arg) && !isNumeric(arg))
149
    if (!isLogical(arg) && !isNumeric(arg))
148
	errorcall(call, "invalid argument type");
150
	errorcall(call, "invalid argument type");
149
    len = LENGTH(arg);
-
 
150
    PROTECT(names = getAttrib(arg, R_NamesSymbol));
151
    PROTECT(names = getAttrib(arg, R_NamesSymbol));
151
    PROTECT(dim = getAttrib(arg, R_DimSymbol));
152
    PROTECT(dim = getAttrib(arg, R_DimSymbol));
152
    PROTECT(dimnames = getAttrib(arg, R_DimNamesSymbol));
153
    PROTECT(dimnames = getAttrib(arg, R_DimNamesSymbol));
153
    PROTECT(x = allocVector(LGLSXP, len));
154
    PROTECT(x = allocVector(LGLSXP, len));    
154
    switch(TYPEOF(arg)) {
155
    switch(TYPEOF(arg)) {
155
    case LGLSXP:
156
    case LGLSXP:
156
	for (i = 0; i < len; i++)
157
	for (i = 0; i < len; i++)
157
	    LOGICAL(x)[i] = (LOGICAL(arg)[i] == NA_LOGICAL) ?
158
	    LOGICAL(x)[i] = (LOGICAL(arg)[i] == NA_LOGICAL) ?
158
		NA_LOGICAL : LOGICAL(arg)[i] == 0;
159
		NA_LOGICAL : LOGICAL(arg)[i] == 0;