[Rd] Format printing inside a matrix

Michael Lawrence |@wrence@m|ch@e| @end|ng |rom gene@com
Mon Jul 8 04:04:03 CEST 2019


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.

Michael

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



-- 
Michael Lawrence
Scientist, Bioinformatics and Computational Biology
Genentech, A Member of the Roche Group
Office +1 (650) 225-7760
michafla using gene.com

Join Genentech on LinkedIn | Twitter | Facebook | Instagram | YouTube



More information about the R-devel mailing list