tdsmith / aRrgh

A newcomer's (angry) guide to data types in R
Other
307 stars 14 forks source link

Dot names #20

Open jonocarroll opened 8 years ago

jonocarroll commented 8 years ago

Dots in identifier names are just part of the identifier. They are not scope operators. They are not operators at all. They are just a legal character to use in the names of things. They are often used where a normal human being would use underscores, since underscores were assignment operators in S, which I promise you don’t even want to think about.

I'm not sure if you're still updating, or what your understanding is at this point, but this bit is slightly off. Dots are used in function names for method overloading (by class), so print(x) dispatches differently depending on the class of x.

For example, print(data.frame(x)) actually calls print.data.frame(x), but you may want to call print.default() explicitly.

tdsmith commented 8 years ago

It's still true that they are not any sort of operator; the method overloading code just understands certain magical names that happen to use . as a separator and dispatches to them at runtime.

I should really add a section on the different class systems!

dwinsemius commented 4 years ago

Also a leading dot in a name will make it "special" in some sense, e.g., ls will not return its name unless 'all.names' is set to TRUE. Also isolated dots have been taken over as meaningful in tidyverse syntax. Arguably this does require consideration of scope.