The R Project SVN R

Rev

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

Rev 5458 Rev 5731
Line 52... Line 52...
52
 
52
 
53
    /* Check the arguments */
53
    /* Check the arguments */
54
 
54
 
55
    x = CAR(args);
55
    x = CAR(args);
56
    if (!isVectorList(x))
56
    if (!isVectorList(x))
57
	errorcall(call, "invalid first argument\n");
57
	errorcall(call, "invalid first argument");
58
 
58
 
59
    sep = CADR(args);
59
    sep = CADR(args);
60
    if (!isString(sep) || LENGTH(sep) <= 0)
60
    if (!isString(sep) || LENGTH(sep) <= 0)
61
	errorcall(call, "invalid separator\n");
61
	errorcall(call, "invalid separator");
62
    sep = STRING(sep)[0];
62
    sep = STRING(sep)[0];
63
    sepw = LENGTH(sep);
63
    sepw = LENGTH(sep);
64
 
64
 
65
    collapse = CADDR(args);
65
    collapse = CADDR(args);
66
    if (!isNull(collapse))
66
    if (!isNull(collapse))
67
	if(!isString(collapse) || LENGTH(collapse) <= 0)
67
	if(!isString(collapse) || LENGTH(collapse) <= 0)
68
	    errorcall(call, "invalid collapse argument\n");
68
	    errorcall(call, "invalid collapse argument");
69
 
69
 
70
    /* Maximum argument length and */
70
    /* Maximum argument length and */
71
    /* check for arguments of list type */
71
    /* check for arguments of list type */
72
 
72
 
73
    nx = length(x);
73
    nx = length(x);
74
    maxlen = 0;
74
    maxlen = 0;
75
    for (j = 0; j < nx; j++) {
75
    for (j = 0; j < nx; j++) {
76
	if (!isString(VECTOR(x)[j]))
76
	if (!isString(VECTOR(x)[j]))
77
	    error("non-string argument to Internal paste\n");
77
	    error("non-string argument to Internal paste");
78
	if(length(VECTOR(x)[j]) > maxlen)
78
	if(length(VECTOR(x)[j]) > maxlen)
79
	    maxlen = length(VECTOR(x)[j]);
79
	    maxlen = length(VECTOR(x)[j]);
80
    }
80
    }
81
    if(maxlen == 0)
81
    if(maxlen == 0)
82
	return mkString("");
82
	return mkString("");
Line 153... Line 153...
153
	trim = 0;
153
	trim = 0;
154
	break;
154
	break;
155
    case 2:
155
    case 2:
156
	trim = asLogical(CADR(args));
156
	trim = asLogical(CADR(args));
157
	if (trim == NA_INTEGER)
157
	if (trim == NA_INTEGER)
158
	    errorcall(call, "invalid \"trim\" argument\n");
158
	    errorcall(call, "invalid \"trim\" argument");
159
	break;
159
	break;
160
    default:
160
    default:
161
	errorcall(call, "incorrect number of arguments\n");
161
	errorcall(call, "incorrect number of arguments");
162
    }
162
    }
163
 
163
 
164
    if (!isVector(x = CAR(args)))
164
    if (!isVector(x = CAR(args)))
165
	errorcall(call, "first argument must be atomic\n");
165
	errorcall(call, "first argument must be atomic");
166
 
166
 
167
    if ((n = LENGTH(x)) <= 0)
167
    if ((n = LENGTH(x)) <= 0)
168
	return allocVector(STRSXP, 0);
168
	return allocVector(STRSXP, 0);
169
 
169
 
170
    switch (TYPEOF(x)) {
170
    switch (TYPEOF(x)) {
Line 224... Line 224...
224
	    STRING(y)[i] = mkChar(strp);
224
	    STRING(y)[i] = mkChar(strp);
225
	}
225
	}
226
	UNPROTECT(1);
226
	UNPROTECT(1);
227
	break;
227
	break;
228
    default:
228
    default:
229
	errorcall(call, "Impossible mode ( x )\n"); y = R_NilValue;/* -Wall */
229
	errorcall(call, "Impossible mode ( x )"); y = R_NilValue;/* -Wall */
230
    }
230
    }
231
    PROTECT(y);
231
    PROTECT(y);
232
    if((l = getAttrib(x, R_DimSymbol)) != R_NilValue)
232
    if((l = getAttrib(x, R_DimSymbol)) != R_NilValue)
233
	setAttrib(y, R_DimSymbol, l);
233
	setAttrib(y, R_DimSymbol, l);
234
    if((l = getAttrib(x, R_DimNamesSymbol)) != R_NilValue)
234
    if((l = getAttrib(x, R_DimNamesSymbol)) != R_NilValue)
Line 280... Line 280...
280
    case STRSXP:
280
    case STRSXP:
281
	formatString(STRING(x), n, &w, 0);
281
	formatString(STRING(x), n, &w, 0);
282
	break;
282
	break;
283
 
283
 
284
    default:
284
    default:
285
	errorcall(call, "vector arguments only\n");
285
	errorcall(call, "vector arguments only");
286
    }
286
    }
287
    x = allocVector(INTSXP, (n >= 0) ? 3 : 6);
287
    x = allocVector(INTSXP, (n >= 0) ? 3 : 6);
288
    INTEGER(x)[0] = w;
288
    INTEGER(x)[0] = w;
289
    INTEGER(x)[1] = d;
289
    INTEGER(x)[1] = d;
290
    INTEGER(x)[2] = e;
290
    INTEGER(x)[2] = e;