The R Project SVN R

Rev

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

Rev 73750 Rev 74734
Line 1... Line 1...
1
/*
1
/*
2
 *  R : A Computer Language for Statistical Data Analysis
2
 *  R : A Computer Language for Statistical Data Analysis
3
 *  Copyright (C) 1995, 1996	Robert Gentleman and Ross Ihaka
3
 *  Copyright (C) 1995, 1996	Robert Gentleman and Ross Ihaka
4
 *  Copyright (C) 2000--2016	The R Core Team
4
 *  Copyright (C) 2000--2018	The R Core Team
5
 *  Copyright (C) 2001--2012	The R Foundation
5
 *  Copyright (C) 2001--2012	The R Foundation
6
 *
6
 *
7
 *  This program is free software; you can redistribute it and/or modify
7
 *  This program is free software; you can redistribute it and/or modify
8
 *  it under the terms of the GNU General Public License as published by
8
 *  it under the terms of the GNU General Public License as published by
9
 *  the Free Software Foundation; either version 2 of the License, or
9
 *  the Free Software Foundation; either version 2 of the License, or
Line 211... Line 211...
211
	    MatrixColumnLabel(cl, j, w[j])
211
	    MatrixColumnLabel(cl, j, w[j])
212
 
212
 
213
    _PRINT_INIT_rl_rn;
213
    _PRINT_INIT_rl_rn;
214
    const int *x = LOGICAL_RO(sx) + offset;
214
    const int *x = LOGICAL_RO(sx) + offset;
215
 
215
 
216
    _COMPUTE_W_(formatLogical(&x[j * r], (R_xlen_t) r, &w[j]));
216
    _COMPUTE_W_( formatLogical(&x[j * (R_xlen_t) r], (R_xlen_t) r, &w[j]) );
217
 
217
 
218
    _PRINT_MATRIX_( , STD_ColumnLabels,
218
    _PRINT_MATRIX_( , STD_ColumnLabels,
219
		   Rprintf("%s", EncodeLogical(x[i + j * r], w[j])));
219
		   Rprintf("%s", EncodeLogical(x[i + j * (R_xlen_t) r], w[j])));
220
 
220
 
221
}
221
}
222
 
222
 
223
static void printIntegerMatrix(SEXP sx, int offset, int r_pr, int r, int c,
223
static void printIntegerMatrix(SEXP sx, int offset, int r_pr, int r, int c,
224
			       SEXP rl, SEXP cl, const char *rn, const char *cn,
224
			       SEXP rl, SEXP cl, const char *rn, const char *cn,
225
			       Rboolean print_ij)
225
			       Rboolean print_ij)
226
{
226
{
227
    _PRINT_INIT_rl_rn;
227
    _PRINT_INIT_rl_rn;
228
    const int *x = INTEGER_RO(sx) + offset;
228
    const int *x = INTEGER_RO(sx) + offset;
229
 
229
 
230
    _COMPUTE_W_( formatInteger(&x[j * r], (R_xlen_t) r, &w[j]) );
230
    _COMPUTE_W_( formatInteger(&x[j * (R_xlen_t) r], (R_xlen_t) r, &w[j]) );
231
 
231
 
232
    _PRINT_MATRIX_( , STD_ColumnLabels,
232
    _PRINT_MATRIX_( , STD_ColumnLabels,
233
		   Rprintf("%s", EncodeInteger(x[i + j * r], w[j])));
233
		   Rprintf("%s", EncodeInteger(x[i + j * (R_xlen_t) r], w[j])));
234
}
234
}
235
 
235
 
236
static void printRealMatrix(SEXP sx, int offset, int r_pr, int r, int c,
236
static void printRealMatrix(SEXP sx, int offset, int r_pr, int r, int c,
237
			    SEXP rl, SEXP cl, const char *rn, const char *cn,
237
			    SEXP rl, SEXP cl, const char *rn, const char *cn,
238
			    Rboolean print_ij)
238
			    Rboolean print_ij)
Line 240... Line 240...
240
    _PRINT_INIT_rl_rn;
240
    _PRINT_INIT_rl_rn;
241
    const double *x = REAL_RO(sx) + offset;
241
    const double *x = REAL_RO(sx) + offset;
242
    int *d = (int *) R_alloc(c, sizeof(int)),
242
    int *d = (int *) R_alloc(c, sizeof(int)),
243
	*e = (int *) R_alloc(c, sizeof(int));
243
	*e = (int *) R_alloc(c, sizeof(int));
244
 
244
 
245
    _COMPUTE_W_( formatReal(&x[j * r], (R_xlen_t) r, &w[j], &d[j], &e[j], 0) );
245
    _COMPUTE_W_( formatReal(&x[j * (R_xlen_t) r], (R_xlen_t) r, &w[j],
-
 
246
                            &d[j], &e[j], 0) );
246
 
247
 
247
    _PRINT_MATRIX_( , STD_ColumnLabels,
248
    _PRINT_MATRIX_( , STD_ColumnLabels,
248
		   Rprintf("%s", EncodeReal0(x[i + j * r], w[j], d[j], e[j], OutDec)) );
249
		   Rprintf("%s", EncodeReal0(x[i + j * (R_xlen_t) r],
-
 
250
                                             w[j], d[j], e[j], OutDec)) );
249
}
251
}
250
 
252
 
251
static void printComplexMatrix(SEXP sx, int offset, int r_pr, int r, int c,
253
static void printComplexMatrix(SEXP sx, int offset, int r_pr, int r, int c,
252
			       SEXP rl, SEXP cl, const char *rn, const char *cn,
254
			       SEXP rl, SEXP cl, const char *rn, const char *cn,
253
			       Rboolean print_ij)
255
			       Rboolean print_ij)
Line 260... Line 262...
260
	*di = (int *) R_alloc(c, sizeof(int)),
262
	*di = (int *) R_alloc(c, sizeof(int)),
261
	*ei = (int *) R_alloc(c, sizeof(int)),
263
	*ei = (int *) R_alloc(c, sizeof(int)),
262
	*wi = (int *) R_alloc(c, sizeof(int));
264
	*wi = (int *) R_alloc(c, sizeof(int));
263
 
265
 
264
    /* Determine the column widths */
266
    /* Determine the column widths */
265
    _COMPUTE_W_( formatComplex(&x[j * r], (R_xlen_t) r,
267
    _COMPUTE_W_( formatComplex(&x[j * (R_xlen_t) r], (R_xlen_t) r,
266
			       &wr[j], &dr[j], &er[j],
268
			       &wr[j], &dr[j], &er[j],
267
			       &wi[j], &di[j], &ei[j], 0);
269
			       &wi[j], &di[j], &ei[j], 0);
268
		 w[j] = wr[j] + wi[j] + 2 );
270
		 w[j] = wr[j] + wi[j] + 2 );
269
 
271
 
270
    _PRINT_MATRIX_( , STD_ColumnLabels,
272
    _PRINT_MATRIX_( , STD_ColumnLabels,
-
 
273
		   if (ISNA(x[i + j * (R_xlen_t) r].r) ||
271
		   if (ISNA(x[i + j * r].r) || ISNA(x[i + j * r].i))
274
		       ISNA(x[i + j * (R_xlen_t) r].i))
-
 
275
 
272
		       Rprintf("%s", EncodeReal0(NA_REAL, w[j], 0, 0, OutDec));
276
		       Rprintf("%s", EncodeReal0(NA_REAL, w[j], 0, 0, OutDec));
273
		   else
277
		   else
274
		       /* Note that the label printing may modify w[j], so wr[j] is not 
278
		       /* Note that the label printing may modify w[j], so wr[j] is not 
275
		          necessarily still valid, and we use w[j] - wi[j] - 2  */
279
		          necessarily still valid, and we use w[j] - wi[j] - 2  */
276
		       Rprintf("%s",
280
		       Rprintf("%s",
277
			       EncodeComplex(x[i + j * r],
281
			       EncodeComplex(x[i + j * (R_xlen_t) r],
278
					     w[j] - wi[j] - 2, dr[j], er[j],
282
					     w[j] - wi[j] - 2, dr[j], er[j],
279
					     wi[j], di[j], ei[j], OutDec)) )
283
					     wi[j], di[j], ei[j], OutDec)) )
280
}
284
}
281
 
285
 
282
static void printStringMatrix(SEXP sx, int offset, int r_pr, int r, int c,
286
static void printStringMatrix(SEXP sx, int offset, int r_pr, int r, int c,
Line 284... Line 288...
284
			      const char *rn, const char *cn, Rboolean print_ij)
288
			      const char *rn, const char *cn, Rboolean print_ij)
285
{
289
{
286
    _PRINT_INIT_rl_rn;
290
    _PRINT_INIT_rl_rn;
287
    const SEXP *x = STRING_PTR_RO(sx)+offset;
291
    const SEXP *x = STRING_PTR_RO(sx)+offset;
288
 
292
 
289
    _COMPUTE_W2_( formatString(&x[j * r], (R_xlen_t) r, &w[j], quote), );
293
    _COMPUTE_W2_( formatString(&x[j * (R_xlen_t) r], (R_xlen_t) r,
-
 
294
                               &w[j], quote), );
290
 
295
 
291
    _PRINT_MATRIX_( + R_print.gap,
296
    _PRINT_MATRIX_( + R_print.gap,
292
	           /* DO_COLUMN_LABELS = */
297
	           /* DO_COLUMN_LABELS = */
293
		   if (right) {
298
		   if (right) {
294
		       for (j = jmin; j < jmax ; j++)
299
		       for (j = jmin; j < jmax ; j++)
Line 298... Line 303...
298
		       for (j = jmin; j < jmax ; j++)
303
		       for (j = jmin; j < jmax ; j++)
299
			   LeftMatrixColumnLabel(cl, j, w[j]);
304
			   LeftMatrixColumnLabel(cl, j, w[j]);
300
		   },
305
		   },
301
		   /* ENCODE_I = */
306
		   /* ENCODE_I = */
302
		   Rprintf("%*s%s", R_print.gap, "",
307
		   Rprintf("%*s%s", R_print.gap, "",
-
 
308
			   EncodeString(x[i + j * (R_xlen_t) r],
303
			   EncodeString(x[i + j * r], w[j], quote, right)) );
309
		                        w[j], quote, right)) );
304
}
310
}
305
 
311
 
306
static void printRawMatrix(SEXP sx, int offset, int r_pr, int r, int c,
312
static void printRawMatrix(SEXP sx, int offset, int r_pr, int r, int c,
307
			   SEXP rl, SEXP cl, const char *rn, const char *cn,
313
			   SEXP rl, SEXP cl, const char *rn, const char *cn,
308
			   Rboolean print_ij)
314
			   Rboolean print_ij)
309
{
315
{
310
    _PRINT_INIT_rl_rn;
316
    _PRINT_INIT_rl_rn;
311
    const Rbyte *x = RAW_RO(sx) + offset;
317
    const Rbyte *x = RAW_RO(sx) + offset;
312
 
318
 
313
    _COMPUTE_W_( formatRaw(&x[j * r], (R_xlen_t) r, &w[j]) )
319
    _COMPUTE_W_( formatRaw(&x[j * (R_xlen_t) r], (R_xlen_t) r, &w[j]) )
314
 
320
 
315
    _PRINT_MATRIX_( , STD_ColumnLabels,
321
    _PRINT_MATRIX_( , STD_ColumnLabels,
316
		   Rprintf("%*s%s", w[j]-2, "", EncodeRaw(x[i + j * r], "")) );
322
		   Rprintf("%*s%s", w[j]-2, "",
-
 
323
		   EncodeRaw(x[i + j * (R_xlen_t) r], "")) );
317
}
324
}
318
 
325
 
319
/* rm and cn are found by GetMatrixDimnames so in native encoding */
326
/* rm and cn are found by GetMatrixDimnames so in native encoding */
320
attribute_hidden
327
attribute_hidden
321
void printMatrix(SEXP x, int offset, SEXP dim, int quote, int right,
328
void printMatrix(SEXP x, int offset, SEXP dim, int quote, int right,