[Rd] format() doesn't propagate the dim and dimnames when underlying type of array is "list"

Hervé Pagès hpages at fredhutch.org
Thu Dec 14 23:05:49 CET 2017


Hi,

Here is how to reproduce:

With a matrix of atomic type
----------------------------

   m1 <- matrix(1:12, ncol=3,
                dimnames=list(letters[1:4], LETTERS[1:3]))

   typeof(m1)
   # [1] "integer"

   m1
   #   A B  C
   # a 1 5  9
   # b 2 6 10
   # c 3 7 11
   # d 4 8 12

   format(m1)
   #   A    B    C
   # a " 1" " 5" " 9"
   # b " 2" " 6" "10"
   # c " 3" " 7" "11"
   # d " 4" " 8" "12"

==> dim and dimnames are propagated.

With a matrix of type "list"
----------------------------

   m2 <- matrix(rep(list(1:5, NULL, "AA"), 4), ncol=3,
                dimnames=list(letters[1:4], LETTERS[1:3]))

   typeof(m2)
   # [1] "list"

   m2
   #   A         B         C
   # a Integer,5 NULL      "AA"
   # b NULL      "AA"      Integer,5
   # c "AA"      Integer,5 NULL
   # d Integer,5 NULL      "AA"

   format(m2)
   # [1] "1, 2, 3, 4, 5" "NULL"          "AA"            "1, 2, 3, 4, 5"
   # [5] "NULL"          "AA"            "1, 2, 3, 4, 5" "NULL"
   # [9] "AA"            "1, 2, 3, 4, 5" "NULL"          "AA"

==> dim and dimnames are dropped!

The same thing seems to happen with arrays of arbitrary dimensions.

Thanks,
H.

-- 
Hervé Pagès

Program in Computational Biology
Division of Public Health Sciences
Fred Hutchinson Cancer Research Center
1100 Fairview Ave. N, M1-B514
P.O. Box 19024
Seattle, WA 98109-1024

E-mail: hpages at fredhutch.org
Phone:  (206) 667-5791
Fax:    (206) 667-1319



More information about the R-devel mailing list