The R Project SVN R

Rev

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

Rev 87770 Rev 87891
Line 116... Line 116...
116
 * We define macros that will be re-used in the other functions,
116
 * We define macros that will be re-used in the other functions,
117
 * and comment the common code here (only):
117
 * and comment the common code here (only):
118
*/
118
*/
119
static void printLogicalMatrix(SEXP sx, int offset, int r_pr, int r, int c,
119
static void printLogicalMatrix(SEXP sx, int offset, int r_pr, int r, int c,
120
			       SEXP rl, SEXP cl, const char *rn, const char *cn,
120
			       SEXP rl, SEXP cl, const char *rn, const char *cn,
121
			       Rboolean print_ij)
121
			       bool print_ij)
122
{
122
{
123
/* initialization; particularly of row labels, rl= dimnames(.)[[1]] and
123
/* initialization; particularly of row labels, rl= dimnames(.)[[1]] and
124
 * rn = names(dimnames(.))[1] : */
124
 * rn = names(dimnames(.))[1] : */
125
#define _PRINT_INIT_rl_rn				\
125
#define _PRINT_INIT_rl_rn				\
126
    int *w = (int *) R_alloc(c, sizeof(int));		\
126
    int *w = (int *) R_alloc(c, sizeof(int));		\
Line 219... Line 219...
219
		   Rprintf("%s", EncodeLogical(x[i + j * (R_xlen_t) r], w[j])));
219
		   Rprintf("%s", EncodeLogical(x[i + j * (R_xlen_t) r], w[j])));
220
}
220
}
221
 
221
 
222
static void printIntegerMatrix(SEXP sx, int offset, int r_pr, int r, int c,
222
static void printIntegerMatrix(SEXP sx, int offset, int r_pr, int r, int c,
223
			       SEXP rl, SEXP cl, const char *rn, const char *cn,
223
			       SEXP rl, SEXP cl, const char *rn, const char *cn,
224
			       Rboolean print_ij)
224
			       bool print_ij)
225
{
225
{
226
    _PRINT_INIT_rl_rn;
226
    _PRINT_INIT_rl_rn;
227
    const int *x = INTEGER_RO(sx) + offset;
227
    const int *x = INTEGER_RO(sx) + offset;
228
 
228
 
229
    _COMPUTE_W_( formatInteger(&x[j * (R_xlen_t) r], (R_xlen_t) r, &w[j]) );
229
    _COMPUTE_W_( formatInteger(&x[j * (R_xlen_t) r], (R_xlen_t) r, &w[j]) );
Line 232... Line 232...
232
		   Rprintf("%s", EncodeInteger(x[i + j * (R_xlen_t) r], w[j])));
232
		   Rprintf("%s", EncodeInteger(x[i + j * (R_xlen_t) r], w[j])));
233
}
233
}
234
 
234
 
235
static void printRealMatrix(SEXP sx, int offset, int r_pr, int r, int c,
235
static void printRealMatrix(SEXP sx, int offset, int r_pr, int r, int c,
236
			    SEXP rl, SEXP cl, const char *rn, const char *cn,
236
			    SEXP rl, SEXP cl, const char *rn, const char *cn,
237
			    Rboolean print_ij)
237
			    bool print_ij)
238
{
238
{
239
    _PRINT_INIT_rl_rn;
239
    _PRINT_INIT_rl_rn;
240
    const double *x = REAL_RO(sx) + offset;
240
    const double *x = REAL_RO(sx) + offset;
241
    int *d = (int *) R_alloc(c, sizeof(int)),
241
    int *d = (int *) R_alloc(c, sizeof(int)),
242
	*e = (int *) R_alloc(c, sizeof(int));
242
	*e = (int *) R_alloc(c, sizeof(int));
Line 249... Line 249...
249
					     w[j], d[j], e[j], OutDec)) );
249
					     w[j], d[j], e[j], OutDec)) );
250
}
250
}
251
 
251
 
252
static void printComplexMatrix(SEXP sx, int offset, int r_pr, int r, int c,
252
static void printComplexMatrix(SEXP sx, int offset, int r_pr, int r, int c,
253
			       SEXP rl, SEXP cl, const char *rn, const char *cn,
253
			       SEXP rl, SEXP cl, const char *rn, const char *cn,
254
			       Rboolean print_ij)
254
			       bool print_ij)
255
{
255
{
256
    _PRINT_INIT_rl_rn;
256
    _PRINT_INIT_rl_rn;
257
    const Rcomplex *x = COMPLEX_RO(sx) + offset;
257
    const Rcomplex *x = COMPLEX_RO(sx) + offset;
258
    int *dr = (int *) R_alloc(c, sizeof(int)),
258
    int *dr = (int *) R_alloc(c, sizeof(int)),
259
	*er = (int *) R_alloc(c, sizeof(int)),
259
	*er = (int *) R_alloc(c, sizeof(int)),
Line 282... Line 282...
282
					     wi[j], di[j], ei[j], OutDec)) )
282
					     wi[j], di[j], ei[j], OutDec)) )
283
}
283
}
284
 
284
 
285
static void printStringMatrix(SEXP sx, int offset, int r_pr, int r, int c,
285
static void printStringMatrix(SEXP sx, int offset, int r_pr, int r, int c,
286
			      int quote, int right, SEXP rl, SEXP cl,
286
			      int quote, int right, SEXP rl, SEXP cl,
287
			      const char *rn, const char *cn, Rboolean print_ij)
287
			      const char *rn, const char *cn, bool print_ij)
288
{
288
{
289
    _PRINT_INIT_rl_rn;
289
    _PRINT_INIT_rl_rn;
290
    const SEXP *x = STRING_PTR_RO(sx)+offset;
290
    const SEXP *x = STRING_PTR_RO(sx)+offset;
291
 
291
 
292
    _COMPUTE_W2_( formatString(&x[j * (R_xlen_t) r], (R_xlen_t) r,
292
    _COMPUTE_W2_( formatString(&x[j * (R_xlen_t) r], (R_xlen_t) r,
Line 308... Line 308...
308
		                        w[j], quote, right)) );
308
		                        w[j], quote, right)) );
309
}
309
}
310
 
310
 
311
static void printRawMatrix(SEXP sx, int offset, int r_pr, int r, int c,
311
static void printRawMatrix(SEXP sx, int offset, int r_pr, int r, int c,
312
			   SEXP rl, SEXP cl, const char *rn, const char *cn,
312
			   SEXP rl, SEXP cl, const char *rn, const char *cn,
313
			   Rboolean print_ij)
313
			   bool print_ij)
314
{
314
{
315
    _PRINT_INIT_rl_rn;
315
    _PRINT_INIT_rl_rn;
316
    const Rbyte *x = RAW_RO(sx) + offset;
316
    const Rbyte *x = RAW_RO(sx) + offset;
317
 
317
 
318
    _COMPUTE_W_( formatRaw(&x[j * (R_xlen_t) r], (R_xlen_t) r, &w[j]) )
318
    _COMPUTE_W_( formatRaw(&x[j * (R_xlen_t) r], (R_xlen_t) r, &w[j]) )
Line 354... Line 354...
354
    /* Display at least one row in case of truncation */
354
    /* Display at least one row in case of truncation */
355
    if (c > c_pr && r_pr < 1 && r > 0)
355
    if (c > c_pr && r_pr < 1 && r > 0)
356
	r_pr = 1;
356
	r_pr = 1;
357
    switch (TYPEOF(x)) {
357
    switch (TYPEOF(x)) {
358
    case LGLSXP:
358
    case LGLSXP:
359
	printLogicalMatrix(x, offset, r_pr, r, c_pr, rl, cl, rn, cn, TRUE);
359
	printLogicalMatrix(x, offset, r_pr, r, c_pr, rl, cl, rn, cn, true);
360
	break;
360
	break;
361
    case INTSXP:
361
    case INTSXP:
362
	printIntegerMatrix(x, offset, r_pr, r, c_pr, rl, cl, rn, cn, TRUE);
362
	printIntegerMatrix(x, offset, r_pr, r, c_pr, rl, cl, rn, cn, true);
363
	break;
363
	break;
364
    case REALSXP:
364
    case REALSXP:
365
	printRealMatrix	  (x, offset, r_pr, r, c_pr, rl, cl, rn, cn, TRUE);
365
	printRealMatrix	  (x, offset, r_pr, r, c_pr, rl, cl, rn, cn, true);
366
	break;
366
	break;
367
    case CPLXSXP:
367
    case CPLXSXP:
368
	printComplexMatrix(x, offset, r_pr, r, c_pr, rl, cl, rn, cn, TRUE);
368
	printComplexMatrix(x, offset, r_pr, r, c_pr, rl, cl, rn, cn, true);
369
	break;
369
	break;
370
    case STRSXP:
370
    case STRSXP:
371
	if (quote) quote = '"';
371
	if (quote) quote = '"';
372
	printStringMatrix (x, offset, r_pr, r, c_pr, quote, right, rl, cl, rn, cn, TRUE);
372
	printStringMatrix (x, offset, r_pr, r, c_pr, quote, right, rl, cl, rn, cn, true);
373
	break;
373
	break;
374
    case RAWSXP:
374
    case RAWSXP:
375
	printRawMatrix	  (x, offset, r_pr, r, c_pr, rl, cl, rn, cn, TRUE);
375
	printRawMatrix	  (x, offset, r_pr, r, c_pr, rl, cl, rn, cn, true);
376
	break;
376
	break;
377
    default:
377
    default:
378
	UNIMPLEMENTED_TYPE("printMatrix", x);
378
	UNIMPLEMENTED_TYPE("printMatrix", x);
379
    }
379
    }
380
    if (r_pr < r || c_pr < c) {
380
    if (r_pr < r || c_pr < c) {
Line 410... Line 410...
410
	SEXP dn, dnn, dn0, dn1;
410
	SEXP dn, dnn, dn0, dn1;
411
	const int *dims = INTEGER_RO(dim);
411
	const int *dims = INTEGER_RO(dim);
412
	int i, j, nb, nb_pr, ne_last, nc_last, nr_last,
412
	int i, j, nb, nb_pr, ne_last, nc_last, nr_last,
413
	    nr = dims[0], nc = dims[1],
413
	    nr = dims[0], nc = dims[1],
414
	    b = nr * nc;
414
	    b = nr * nc;
415
	Rboolean max_reached, has_dimnames = (dimnames != R_NilValue),
415
	bool max_reached, has_dimnames = (dimnames != R_NilValue),
416
	    has_dnn = has_dimnames;
416
	    has_dnn = has_dimnames;
417
 
417
 
418
	if (!has_dimnames) {
418
	if (!has_dimnames) {
419
	    dn0 = R_NilValue;
419
	    dn0 = R_NilValue;
420
	    dn1 = R_NilValue;
420
	    dn1 = R_NilValue;
Line 452... Line 452...
452
	    ne_last = b;
452
	    ne_last = b;
453
	    nc_last = nc;
453
	    nc_last = nc;
454
	    nr_last = nr;
454
	    nr_last = nr;
455
	}
455
	}
456
	for (i = 0; i < nb_pr; i++) {
456
	for (i = 0; i < nb_pr; i++) {
457
	    Rboolean do_ij = nb > 0,
457
	    bool do_ij = nb > 0,
458
		i_last = (i == nb_pr - 1); /* for the last slice */
458
		i_last = (i == nb_pr - 1); /* for the last slice */
459
	    int	use_nc = i_last ? nc_last : nc,
459
	    int	use_nc = i_last ? nc_last : nc,
460
		use_nr = i_last ? nr_last : nr;
460
		use_nr = i_last ? nr_last : nr;
461
	    if(do_ij) {
461
	    if(do_ij) {
462
		int k = 1;
462
		int k = 1;