[Rd] round() and signif() do not check argument names when a single argument is given

Martin Maechler m@ech|er @end|ng |rom @t@t@m@th@ethz@ch
Tue May 26 18:33:08 CEST 2020


>>>>> Shane Mueller 
>>>>>     on Sat, 23 May 2020 00:37:57 -0400 writes:

    > On Fri, May 22, 2020 at 9:55 PM David Winsemius <dwinsemius using comcast.net>
    > wrote:

    >> The premise in the first few lines of your preamble is at odds (in the
    >> logical sense) with my understanding of primitive function behavior. Try:
    >> 
    >> data.frame(x=1:2,y=letters[1:2])[j=2, i=1]
    >> 
    >> David
    >> 

    > I had never seen naming indexes of the [] operator.  The documentation of
    > [] indicates that it does argument matching in a non-standard way,
    > recommends against doing it, and states the [.data.frame behavior used in
    > this example is 'undocumented'.  In the example above a warning is thrown
    > as well.

    > Here is the [] documentation:

    > Argument matching
    >> Note that these operations do not match their index arguments in the
    >> standard way: argument names are ignored and positional matching only is
    >> used. So m[j = 2, i = 1] is equivalent to m[2, 1] and not to m[1, 2].
    >> 
    >> This may not be true for methods defined for them; for example it is not
    >> true for the data.frame methods described in [.data.frame which warn if i
    >> or j is named and have undocumented behaviour in that case.
    >> 
    >> To avoid confusion, do not name index arguments (but drop and exact must
    >> be named).
    >> 


    > For the data frames operator [], i and j appear to be named and used
    > arguments, as the following causes an unused argument error for k:
    > data.frame(x=1:2,y=letters[1:2])[j=2, k=1]

    > The analog for round() would be indexing with something like  [k=1,] alone,
    > which causes an unused argument error error for data frames, which is what
    > I'm suggesting round(banana=3.5) should do.   (note it works for matrix as
    > documented).

    > Best,
    > Shane

I agree with Shane.

I think this is a small "wart" that we should remove, ...
and I have been testing a version of your code addition,
and plan to commit that (once I've added regression tests etc).

Martin



More information about the R-devel mailing list