Unexpected argument-matching when some are missing
On Thu, Nov 29, 2018 at 5:09 AM Emil Bode <emil.bode at dans.knaw.nl> wrote:
When trying out some variations with `[.data.frame` I noticed some (to me) odd behaviour, which I found out has nothing to do with `[.data.frame`, but rather with the way arguments are matched, when mixing named/unnamed and missing/non-missing arguments. Consider the following example:
myfun <- function(x,y,z) {
print(match.call())
cat('x=',if(missing(x)) 'missing' else x, '\n')
cat('y=',if(missing(y)) 'missing' else y, '\n')
cat('z=',if(missing(z)) 'missing' else z, '\n')
}
myfun(x=, y=, "z's value")
gives:
# myfun(x = "z's value")
# x= z's value
# y= missing
# z= missing
This seems very counterintuitive to me, I expect the arguments x and y to be missing, and z to get ?z?s value?.
Interesting. I would expect it to throw an error, since "x=" is not syntactically complete. What does "x=" mean anyway? It looks like R interprets it as "x was not set to anything, i.e., is missing". That seems reasonable, though I think the example itself is pathological and would prefer that it produced an error. --Ista
When I call myfun(,y=,"z's value"), x is missing, and y gets ?z?s value?. Are my expectations wrong or is this a bug? And if my expectations are wrong, where can I find more information on argument-matching? My gut-feeling says to call this a bug, but then I?m surprised no-one else has encountered it before. And I don?t have multiple installations to work from, so could somebody else confirm this (if it?s not my expectations that are wrong) for R-devel/other R-versions/other platforms? My setup: R 3.5.1, MacOS 10.13.6, both Rstudio 1.1.453 and R --vanilla from Bash Best regards, Emil Bode
______________________________________________ R-devel at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel