[Rd] Format printing inside a matrix
Jialin Ma
m@r||n- @end|ng |rom gmx@cn
Mon Jul 8 02:41:05 CEST 2019
Hi Abby,
Thanks a lot for your paraphrasing and your suggestion!
The problem of wrapping the list into a S3/S4 object, i.e. subclassing array
or matrix, is that one also has to define a bunch of methods for subsetting,
joining, etc, in order to make it behave like a list array. The reason is that
most R functions for subsetting, joining, etc. do not preserve class
attributes of the input, which is possibly by design. It is not desirable if a
simple matrix subsetting will remove the class attributes of the object.
There are also many other common functions that are meant to drop the
attributes of the input, e.g. lapply, apply -- they are not generics and it is
not wise to override them.
Overall, introducing a new S3/S4 class often brings some extra price in order
to maintain the correct behavior, which is why I tend to avoid them unless it
is necessary.
Best regards,
Jialin
On Sunday, July 7, 2019 4:43:59 PM PDT Abby Spurdle wrote:
> 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.
More information about the R-devel
mailing list