Re: [Rd] Allowing S3 methods of rounding functions to take `...`

2021-01-31 Thread /əˈbi/
I've used S4 objects but with mostly S3 methods.
Currently, with two different versions.
(One extending a general purpose ObjectArray object, and the other
with partitioning information).

Sample below.

However, I'd really like to get back the suggestion(s) of adding
"dots" to the S3 methods.
I know I've said similar things before, but I think minimizing
constraints on object oriented programming is a good thing...
That principle applies to both S3 and S4...

#mono-fonts req. to read this
> x <- matrix (1:256, 8, 8)
> pm <- as.PartMatrix (x, c (2, 6), c (2, 6) )

> as.NestMatrix (pm)
 [,1][,2][,3]
[1,]   
[2,]   
[3,]   

> headt (pm, 4, c (1, 4) )
 [,1] [,2][,3]   [,6][,7] [,8]
[1,]  19   |  17   . 41   |  49   57
[2,]  2   10   |  18   . 42   |  50   58
 --   --   +  --   . --   +  --   --
[3,]  3   11   |  19   . 43   |  51   59
 ..   ..   .. ..   . ..   .. ..   ..
[8,]  8   16   |  24   . 48   |  56   64


On Sat, Jan 30, 2021 at 7:51 AM David Winsemius  wrote:
>
>
> On 1/28/21 10:56 PM, Abby Spurdle wrote:
> > I've been writing functions for block matrices and more generally,
> > arrays of matrices.
> >
> > Presumably, the default transpose operation would transpose everything.
> > But there are situations where one might want to transpose the
> > top-level matrix (of submatrices) but not the submatrices, themselves.
> > Or vice versa.
>
>
> You could construct a matrix of lists and have the lists hold the
> sub-matrices.
>
>
> --
>
> David.
>
> >
> > On a side note, the help file for base::aperm is entitled "Array 
> > Transposition".
> > So, this topic is not quite as simple as it may sound.
> >
> > Interestingly, the aperm generic function *does* have dots.
> >
> >
> > On Fri, Jan 29, 2021 at 3:37 PM Gabriel Becker  
> > wrote:
> >> Out of my naive curiosity, what arguments are you hoping a method for t() 
> >> will take?
> >>
> >> I mean honestly an argument could be made that all S3 generics should take 
> >>  I don't think its an overwhelmingly compelling one, but I d see some 
> >> merit to it given what an s3 generic is at its core.
> >>
> >> ~G
> >>
> >> On Thu, Jan 28, 2021 at 5:27 PM Abby Spurdle  wrote:
> >>> That's a great suggestion Davis.
> >>>
> >>> While, we're on the topic...
> >>> Could we have a "dots" argument in base::t, the transpose function?
> >>>
> >>>
> >>> On Fri, Jan 29, 2021 at 4:48 AM Davis Vaughan  wrote:
>  I should also say that I would be willing to attempt a patch for this, if
>  others agree that this would be useful.
> 
>  - Davis
> 
>  On Thu, Jan 28, 2021 at 9:14 AM Davis Vaughan  wrote:
> 
> > Hi all,
> >
> > I would like to propose adding `...` to the signatures of the following
> > rounding functions:
> >
> > - floor(x)
> > - ceiling(x)
> > - round(x, digits = 0)
> > - And possibly signif(x, digits = 6)
> >
> > The purpose would be to allow S3 methods to add additional arguments as
> > required.
> >
> > A few arguments in favor of this change:
> >
> > `trunc(x, ...)` already takes dots, which sets a precedent for the 
> > others
> > to do so as well. It is documented in the same help file as the other
> > rounding functions.
> >
> > Internally at the C level, a check is done to ensure that there is 
> > exactly
> > 1 arg for floor() and ceiling(), and either 1 or 2 args for round(). The
> > actual names of those arguments are not checked, however, and I believe
> > this is what allows `round.Date(x, ...)` and `round.POSIXt(x, unit)` to
> > exist, solely because they have 2 arguments. It seems like this is a 
> > bit of
> > a hack, since you couldn't create something similar for floor, like
> > `floor.POSIXt(x, unit)` (not saying this should exist, it is just for
> > argument's sake), because the 1 argument check would error on this. I 
> > think
> > adding `...` to the signature of the generics would better support what 
> > is
> > being done here.
> >
> > Additionally, I have a custom date-like S3 class of my own that I would
> > like to write floor(), ceiling(), and round() methods for, and they 
> > would
> > require passing additional arguments.
> >
> > If R core would like to make this change, they could probably tweak
> > `do_trunc()` to be a bit more general, and use it for floor() and
> > ceiling(), since it already allows `...`.
> >
> > A few references:
> >
> > Check for 1 arg in do_math1(), used by floor() and ceiling()
> >
> > https://github.com/wch/r-source/blob/fe82da3baf849fcd3cc7dbc31c6abc72b57aa083/src/main/arithmetic.c#L1270
> >
> > Check for 2 args in do_Math2(), used by round()
> >
> > https://github.com/wch/r-source/blob/fe82da3baf849fcd3cc7dbc31c6abc72b57aa083/src/main/arithmetic.c#L1655
> >
> > do_trunc() definition that allows `...`
> >
> > htt

Re: [Rd] Allowing S3 methods of rounding functions to take `...`

2021-01-31 Thread /əˈbi/
#correction to first line
x <- matrix (1:64, 8, 8)

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


[Rd] surprised matrix (1:256, 8, 8) doesn't cause error/warning

2021-01-31 Thread /əˈbi/
I'm a little surprised that the following doesn't trigger an error or a warning.

matrix (1:256, 8, 8)

The help file says that the main argument is recycled, if it's too short.
But doesn't say what happens if it's too long.

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel