Skip to content

Commit d7090f2

Browse files
author
maechler
committed
print(<array>, max = <small>) should typically show *some*, compatibly w/ <matrix>
git-svn-id: https://svn.r-project.org/R/trunk@87770 00db46b3-68df-0310-9c12-caf00c1e9a41
1 parent 5294e72 commit d7090f2

File tree

3 files changed

+27
-12
lines changed

3 files changed

+27
-12
lines changed

src/main/printarray.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -444,8 +444,8 @@ void printArray(SEXP x, SEXP dim, int quote, int right, SEXP dimnames)
444444
/* for the last, (nb_pr)th matrix slice, use only nr_last rows;
445445
* using floor(), not ceil(), since 'nc' could be huge: */
446446
ne_last = R_print.max - b * (nb_pr - 1);
447-
nc_last = (ne_last < nc) ? 0: nc;
448-
nr_last = (ne_last < nc) ? 0: ne_last / nc;
447+
nc_last = (ne_last < nc) ? ne_last : nc;
448+
nr_last = (ne_last < nc) ? 1 : ne_last / nc;
449449
if(nr_last == 0) { nb_pr--; nc_last = nc; nr_last = nr;}
450450
} else {
451451
nb_pr = (nb > 0) ? nb : 1; // do print *something* when dim = c(a,b,0)
@@ -511,12 +511,8 @@ void printArray(SEXP x, SEXP dim, int quote, int right, SEXP dimnames)
511511
if (nb_pr < nb)
512512
Rprintf(ngettext(" %d slice", " %d slices", nb - nb_pr), nb - nb_pr);
513513
else if (nb_pr == nb) {
514-
if(nr_last < nr) Rprintf(ngettext(" %d row", " %d rows", nr - nr_last), nr - nr_last);
515-
if(nc_last < nc) Rprintf(ngettext(" %d column", " %d columns", nc - nc_last), nc - nc_last);
516-
/* == MM: replace the above with
517514
if((nr -= nr_last) > 0) Rprintf(ngettext(" %d row", " %d rows", nr), nr);
518515
if((nc -= nc_last) > 0) Rprintf(ngettext(" %d column", " %d columns", nc), nc);
519-
*/
520516
}
521517
Rprintf(" ] \n");
522518
}

tests/print-tests.R

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -348,12 +348,13 @@ print(matrix(nrow = 0, ncol = 4), max = 3) # omitting 1 column
348348
print(matrix(nrow = 10, ncol = 2), max = 5) # omitting rows
349349
print(matrix(nrow = 1, ncol = 6), max = 5) # omitting 1 col, at least one row prints
350350
## ----- "higher" arrays ("rank >= 3"): --------
351-
print(array(dim = c(2, 2, 2)), max = 5) # omit 1 slice
351+
print(array(dim = c(2, 2, 2)), max = 4) # omit 1 slice
352+
print(array(dim = c(2, 2, 2)), max = 5) # omit 1 row + 1 column
352353
print(array(dim = c(2, 2, 2)), max = 6) # omit 1 row
353354
print(array(dim = c(2, 2, 2)), max = 7) # omit 1 row
354355
#
355356
print(array(dim = c(2, 2, 1)), max = 2) # omit 1 row
356-
print(array(dim = c(2, 2, 1)), max = 1) # omit the only slice
357+
print(array(dim = c(2, 2, 1)), max = 1) # omit 1 row + 1 column
357358

358359

359360

tests/print-tests.Rout.save

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
R Under development (unstable) (2025-02-20 r87760) -- "Unsuffered Consequences"
2+
R Under development (unstable) (2025-02-20 r87768) -- "Unsuffered Consequences"
33
Copyright (C) 2025 The R Foundation for Statistical Computing
44
Platform: x86_64-pc-linux-gnu
55

@@ -974,14 +974,27 @@ NULL
974974
[1,] NA NA NA NA NA
975975
[ reached 'max' / getOption("max.print") -- omitted 1 column ]
976976
> ## ----- "higher" arrays ("rank >= 3"): --------
977-
> print(array(dim = c(2, 2, 2)), max = 5) # omit 1 slice
977+
> print(array(dim = c(2, 2, 2)), max = 4) # omit 1 slice
978978
, , 1
979979

980980
[,1] [,2]
981981
[1,] NA NA
982982
[2,] NA NA
983983

984984
[ reached 'max' / getOption("max.print") -- omitted 1 slice ]
985+
> print(array(dim = c(2, 2, 2)), max = 5) # omit 1 row + 1 column
986+
, , 1
987+
988+
[,1] [,2]
989+
[1,] NA NA
990+
[2,] NA NA
991+
992+
, , 2
993+
994+
[,1]
995+
[1,] NA
996+
997+
[ reached 'max' / getOption("max.print") -- omitted 1 row 1 column ]
985998
> print(array(dim = c(2, 2, 2)), max = 6) # omit 1 row
986999
, , 1
9871000

@@ -1016,8 +1029,13 @@ NULL
10161029
[1,] NA NA
10171030

10181031
[ reached 'max' / getOption("max.print") -- omitted 1 row ]
1019-
> print(array(dim = c(2, 2, 1)), max = 1) # omit the only slice
1020-
[ reached 'max' / getOption("max.print") -- omitted 1 slice ]
1032+
> print(array(dim = c(2, 2, 1)), max = 1) # omit 1 row + 1 column
1033+
, , 1
1034+
1035+
[,1]
1036+
[1,] NA
1037+
1038+
[ reached 'max' / getOption("max.print") -- omitted 1 row 1 column ]
10211039
>
10221040
>
10231041
>

0 commit comments

Comments
 (0)