As much as I love R, there are indeed quirks that I think R allows to happen but shouldn't.
For example:
mean(2, 4) # outputs 2
mean(c(2, 4)) # outputs 3
I really don't see why R allows you to enter mean(2,4) without giving an error.Thanks for the explanation. Yes, your second example is something like what I found in R code I was asked to modify.
What I find distasteful is that when calling mean(), the resolution of this name depends NOT on whether the local variable mean has been defined, but whether it has been assigned a function. This is illustrated by your 2nd and 3rd examples.
Of course if you are used to it, it may not catch you by surprise.
Re:R 4.0
by playing_colours on Friday April 24, 2020 @12:45PM
(#22970100)
Can an alias be an option to resolve conflict: “import mypackage.mean as mymean”?
No aliases (afaik), but convention is that you explicitly call mypackage::mean in cases where names might even hint at being ambigous.
Re:R 4.0
by credit_guy on Friday April 24, 2020 @12:55PM
(#22970252)
On a tangent here, but is there a reason to use <- instead of = for assignment?
Actually, to answer my own question (I know google), I found this very informative stackoverflow answer [1]. My TLDR: no difference, other than "<-" is more likely to cause carpal tunnel syndrome.
[1] https://stackoverflow.com/questions/1741820/what-are-the-dif...
Finally, you can use the built-in function "find" to see the order in which R will try to resolve a symbol, e.g.
I'm not sure this is a quirk. What are your options as a namespaced language? 1) Allow users to import multiple functions/variables with the same name across different namespaces and resolve the conflict via some kind of hierarchical order; 2) Don't allow users to import multiple functions/variables with the same name, so you can never use overloading to monkey patch; 3) Always require namespace prefixes at all times; 4) Make function dispatch a blocking operation that asks REPL users which to use? I dunno, it doesn't seem to me like R's approach is any less sane.I guess one thing that is different about R's approach is that "built-ins" have no special priority, they're all part of some namespaces that are attached by default but otherwise exactly like third-party libraries (base, stats, graphics, etc.)
In R, the only reserved words that cannot be overloaded are while, repeat, next, if, function, for, and break. (Note: else does not appear here because of a genuinely baffling quirk about how else is implemented in R)