Skip to content
Prev 57159 / 63421 Next

Format printing inside a matrix

generic
I had some difficulty understanding this question.
So, I'm going to paraphrase it.

R, to the best of my knowledge, does not support object arrays, as such.
(Or if it does, I've certainly missed the memo on this one).

The closest option, is to create an (S3) list of (S3 or S4) objects.
This is sufficient in the one-dimension case.
However, to provide functionality of two- or three-dimensional object
arrays, one can create a matrix (or array) from the list.

It's desirable to print such matrices and arrays.
This is possible but the output contains an array of question marks, which
isn't helpful.

Would it be possible for the print method for both matrices and arrays
(conditional on having a list type), call the format method for each
object, possibly creating a character matrix?
Presumably there are other approaches, but the main thing is that the
output is useful and it's easy for R users to control the way objects (in
matrices and arrays) are printed.
S3 class?

In theory, the simplest approach is to redefine the print method for
matrices.
However, that would be unacceptable in a CRAN package, probably...

So, unless R Core change the print method, you may have to create a matrix
subclass.


Abs