[Rd] Format printing inside a matrix

Abby Spurdle @purd|e@@ @end|ng |rom gm@||@com
Mon Jul 8 01:43:59 CEST 2019

> I am not sure if there is an existing solution to this, but I want my S4
> objects inside a list matrix showing correctly.
> R> matrix(lst, 2)
>      [,1] [,2] [,3] [,4] [,5]
> [1,] ?    ?    ?    ?    ?
> [2,] ?    ?    ?    ?    ?
> Is it possible that the print method for matrix can call some type of
> such as `as.character` or `format` when it encounters such cases?

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.

> Or is there any other place that I can override without introducing a new
S3 class?

In theory, the simplest approach is to redefine the print method for
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


	[[alternative HTML version deleted]]

More information about the R-devel mailing list