Re: [Rd] Format printing inside a matrix

2019-07-07 Thread Jialin Ma
Hi Hervé, > Is it? One could argue that a more sensible behavior would be that > things like `[`(..., drop=FALSE), rbind(), cbind(), etc... preserve > the class attribute. > > Interestingly t() does that > > So if it makes sense for t() and reshaping, it's not clear why it > wouldn't for [, aper

Re: [Rd] Format printing inside a matrix

2019-07-07 Thread Pages, Herve
On 7/7/19 17:41, Jialin Ma wrote: > 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

Re: [Rd] Format printing inside a matrix

2019-07-07 Thread Abby Spurdle
> This works fine but no longer work after we do some simple operations. > myArray[1:2, 1:2, 2] > # [,1] [,2] > # [1,] ?? > # [2,] ?? OK, that's a good point. I didn't think of that. Michael Lawrence was probably correct in his comment: >However, as soon as you start > treat

Re: [Rd] Format printing inside a matrix

2019-07-07 Thread Jialin Ma
Hi Michael, 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 li

Re: [Rd] Format printing inside a matrix

2019-07-07 Thread Jialin Ma
Hi Abby, > > It is not desirable if a > > simple matrix subsetting will remove the class attributes of the object. > > I'm assuming by "the object" you are referring to the matrix. > And by "class attribute"-"s" you are referring to all the attributes. > This is a completely separate discussion fr

Re: [Rd] Format printing inside a matrix

2019-07-07 Thread Michael Lawrence via R-devel
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 mat

Re: [Rd] Format printing inside a matrix

2019-07-07 Thread Abby Spurdle
> 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. False, sorry. Wrapping != Defining a New Class. And you don't have to define a

Re: [Rd] Format printing inside a matrix

2019-07-07 Thread Jialin Ma
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

Re: [Rd] Format printing inside a matrix

2019-07-07 Thread Abby Spurdle
> 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