[Rd] Format printing inside a matrix
m@r||n- @end|ng |rom gmx@cn
Mon Jul 8 04:48:48 CEST 2019
Thanks for your reply. I suppose using a new S3/S4 class wrapping the list
could solve my problem, but again I think it brings too much cost for
maintaining the expected behavior. I was aware that Rmpfr package takes this
approach and uses a similar structure (a S4 class wrapping a list of S4
objects) to represent the matrix or higher-order array with arbitrary
And yes S4Vectors was a great package -- one can easily extend a class defined
in S4Vectors and get expected behavior. However, in my case I was hoping my
particular data structure could play well with matrix, data frame, etc.
On Sunday, July 7, 2019 7:04:03 PM PDT Michael Lawrence wrote:
> A generic for displaying an object in a cell would be a reasonable
> solution for this particular problem. However, as soon as you start
> treating these objects as data (like putting them into a matrix),
> you're likely going to want vectorized operations over them, which
> means formalized vector and matrix classes. S4Vectors in Bioconductor
> facilitates this for vectors, but not for higher-order arrays.
> On Sun, Jul 7, 2019 at 4:44 PM Abby Spurdle <spurdle.a using gmail.com> wrote:
> > > 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
> > generic
> > > 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
> > 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
> > [[alternative HTML version deleted]]
> > ______________________________________________
> > R-devel using r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-devel
More information about the R-devel