Roman Olson
2020-May-07 07:46 UTC
[R] Bug in function arguments autocomplete and ellipsis?
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)
Duncan Murdoch
2020-May-08 16:22 UTC
[R] Bug in function arguments autocomplete and ellipsis?
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
Bert Gunter
2020-May-08 16:24 UTC
[R] Bug in function arguments autocomplete and ellipsis?
It would help if you consulted the docs, in this case, **The R Language Definition** and, in particular, 4.3.2 on argument matching. I won't repeat what it is there, but I believe it will suffice to dispel your confusion. Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) On Fri, May 8, 2020 at 7:49 AM Roman Olson <romanolson at yonsei.ac.kr> 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) > ______________________________________________ > R-help at 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.
Roman Olson
2020-May-09 02:38 UTC
[R] Bug in function arguments autocomplete and ellipsis?
Dear All, Thanks for clarifying this. Now I know that this is expected behavior, and will try to place ? before the rest of the arguments. Stay home and stay safe! -Roman> 2020. 5. 9. ?? 1:24, Bert Gunter <bgunter.4567 at gmail.com> ??: > > The R > Language Definition[[alternative HTML version deleted]]