[R] Bug in function arguments autocomplete and ellipsis?
Duncan Murdoch
murdoch@dunc@n @end|ng |rom gm@||@com
Fri May 8 18:22:24 CEST 2020
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
More information about the R-help
mailing list