From emil@bode @ending from d@n@@kn@w@nl  Mon Dec  3 11:14:16 2018
From: emil@bode @ending from d@n@@kn@w@nl (Emil Bode)
Date: Mon, 3 Dec 2018 10:14:16 +0000
Subject: [Rd] Unexpected argument-matching when some are missing
In-Reply-To: <23556.64918.936383.30460@stat.math.ethz.ch>
References: <AA681EA4-D0C7-4A2F-A719-01E510635C45@dans.knaw.nl>
 <2ffdc3d61fcd4b098fa37a35a5cdffc9@GBDCVPEXC08.corp.lgc-group.com>
 <CA+vqiLFUYr5-OzJ7FmrjhT5owEiTJ2Q9x-O5mbv-tx=9c8iCaA@mail.gmail.com>
 <f29d8c1252094e82a30ef8c92b8808d4@GBDCVPEXC08.corp.lgc-group.com>
 <CA+vqiLF8DLiYx8Fp=QiHRtqA9_cNdxGWKe-SxVGq1QatZaCqnQ@mail.gmail.com>
 <b42a529f59634ed282821ddd23608e26@GBDCVPEXC08.corp.lgc-group.com>
 <F12950C3-65ED-457A-82BF-310F90EF9609@dans.knaw.nl>
 <CAOQ5Nydwa1CqaA2oYmDwcVaWpg8Z6gRqDC2Ze4RG-Jcb-z_uWQ@mail.gmail.com>
 <23556.64918.936383.30460@stat.math.ethz.ch>
Message-ID: <369F346B-3A55-461B-BD8E-1F257F991734@dans.knaw.nl>

Thanks as well!
I'm now getting how it's exactly matched, but it still "feels wrong".
Martins rewording is exactly what I meant/was concerned about.
My intuition would say that anyone using ff(x=, ...) would not intent x to be matched to something else, but maybe I'm overlooking certain cases.
Anyway, I agree that throwing a warning would probably be the best solution.
I don't exactly know how to test for compatibility for such changes (never really worked with CRAN/extensive testing), but if I can do something to help I'd be glad to.
And if it turns out to be too disruptive, maybe we can write Patrick Burns (the R-inferno) ; - )

Best regards, 
Emil Bode
 
?On 03/12/2018, 10:57, "Martin Maechler" <maechler at stat.math.ethz.ch> wrote:

    >>>>> Michael Lawrence 
    >>>>>     on Fri, 30 Nov 2018 08:24:31 -0800 writes:
    
        > Argument matching is by name first, then the still missing
        > arguments are filled positionally. Unnamed missing
        > arguments are thus left missing. Does that help?
    
    Thank you, Michael!
    Unfortunately, it may not help sufficiently notably once this
    thread will be forgotten, even though I had thought so exactly
    as well.  Of course we two may find R's matching algorithm
    entirely intuitive, but e.g., Ista expected R even "to throw an
    error" in this case, and there are about 99% of R users less savvy than
    him, so let me think loudly a bit further ...
    IIUC, Emil's case is mostly about this
    
      > ff <- function(x,y,z,...) list(sysC=sys.call(), match=match.call())
      > str( ff(x=, z=pi, "foo") )
      List of 2
       $ sysC : language ff(x = , z = pi, "foo")
       $ match: language ff(x = "foo", z = pi)
      > 
    
    where the argument matching rule above would have suggested to him that the
    matched call should have become
      ff(y = "foo", z = pi)  rather than
      ff(x = "foo", z = pi)
    
    because he'd expected the empty 'x =' to be matched by name and
    hence *not* be matched again later when all the missing
    arguments are matched positionally in the end.
    NB because of the rule Michael cited above *of course*,
    ", ," (in your example below) is not equivalent to
    "y = ," because the former leads to positional matching at position 2.
    
    Now R's matching argument algorithm has therefore been consistent with
    the above simple matching rule ((which did not include the exact vs
    partial matching but that was not the topic here anyway))
    that had been documented as that forever and AFAIK the same as S had.
    
    What may be possible (and suggested in this thread ?) would be
    to start signalling a warning when named empty arguments (the
    " y = , "  in the example) are matched(*), i.e., it would give a
    warning in match.call() but not sys.call(), and hence utilities
    such as  alist()  would continue to work unchanged.
    
    I have no idea (and no time currently to investigate) if such
    warnings would be too disruptive for the current R code base or not.
    
    Martin
    
    ----
    *) "matched" in that case effectively means "dropped" as we have
        seen in the examples.
        
    
        > On Fri, Nov 30, 2018 at 8:18 AM Emil Bode <emil.bode at dans.knaw.nl> wrote:
        >> 
        >> But the main point is where arguments are mixed together:
        >> 
        >> > debugonce(plot.default)
        >> > plot(x=1:10, y=, 'l')
        >> ...
        >> Browse[2]> missing(y)
        >> [1] FALSE
        >> Browse[2]> y
        >> [1] "l"
        >> Browse[2]> type
        >> [1] "p"
        >> 
        >> I think that's what I fall over mostly: that named, empty arguments behave entirely different from omitting them (", ,")
        >> 
        >> And I definitely agree we need a guru to explain it all to us (
        >> 
        >> Cheers, Emil Bode
        >> 
        >> 
        >> On 30/11/2018, 15:35, "S Ellison" <S.Ellison at LGCGroup.com> wrote:
        >> 
        >> > Yes, I think all of that is correct. But y _is_ missing in this sense:
        >> > > plot(1:10, y=)
        >> > > ...
        >> > Browse[2]> missing(y)
        >> 
        >> Although I said what I meant by 'missing' vs 'not present', it wasn't exactly what missing() means. My bad.
        >> missing() returns TRUE if an argument is not specified in the call _whether or not_ it has a default, hence the behaviour of missing(y) in debug(plot).
        >> 
        >> But we can easily find out whether a default has been assigned:
        >> plot(1:10, y=, type=)
        >> Browse[2]> y
        >> NULL
        >> Browse[2]> type
        >> "p"
        >> 
        >> ... which is consistent with silent omission of 'y=' and 'type='
        >> 
        >> 
        >> Still waiting for a guru...
        >> 
        >> Steve E
     
    


[Rd] Unexpected argument-matching when some are missing
Emil Bode