On 07/05/2020 3:46 a.m., Roman Olson wrote:
Dear All,

I am wondering whether function arguments autocomplete causes a bug when 
additional ellipsis arguments are used.

Example:
a = function(robot) {
     cat(robot, "\n")
  }
a(r=5) prints 5, meaning that r is autocompleted to “robot”. Not sure if this 
is normal behavior, but this does not cause problems.

This would be fine, but somehow causes problems when there is an additional 
ellipsis argument that can be used to autocomplete an already existing 
argument. In the example below, when we are calling sens.analysis.all, 
everything starting with q is an additional argument (…). Now, k is missed 
completely. And that is because there is another actual argument that starts 
with k — key.legend.axes (it is assigned to 4 instead). If “k=4” is changed to 
“kk=4” the problem disappears.

sens.analysis.all <- function(func, outgrid, parvec, parmin, parmax,
                               length.pgrid, outvname, zlim, plabs,
                               gridlab, mylog, outlog=FALSE, ytick=NULL,
                               xline=NULL, yline=NULL, mypal=topo.colors,
                               key.legend.axes=NULL, plot.guidance=FALSE, ... ) 
{

    cat(..1, "\n")
    cat(..2, "\n")
    cat(..3, "\n")
out=1
    out
}

out = sens.analysis.all(numer.wait.times.wrps, NA,
      c(5.4, 0.008, 1.5), c(4.9, 0.0079, 2.0), c(5.5, 0.0090, 3.5),
        length.pgrid=10, outvname="cvs", zlim=c(0.3, 2),
        plabs=c("mu", "lambda", "b"), gridlab="Soil Moisture [mm]",
        mylog=FALSE, outlog=FALSE, yline=2, plot.guidance=FALSE, q=3.1, k=4, 
y.c=670,
        realgrid=seq(630, 670, by=4), myseed=0,
        nt=1000000, burnin=300000, bin.cutoff=500,
        bdW.prelim=prec.struct.Mal)

I'm afraid I don't understand what you find surprising here. In your first example, the "r" gets attached to "robot" because of partial matching. In the second example, the "k" gets attached to "key.legend.axes" for the same reason. This is expected behaviour. If you don't want to allow partial matching to arguments, they need to be placed *after* the ellipsis. Those arguments will need to be spelled out in full.

Duncan Murdoch

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to