Search code examples
rpipeoperatorsnaming-conventionspipeline

I see it, but I don't believe it. Legal names in R, piping operations, and the dot


In trying to understand the base R "Bizarro pipe" as described in the Win Vector blog, I confirmed that simple examples produce pipelike behavior in R with no packages installed. For example:

> 2  ->.; exp(.)
[1] 7.389056

I found that the dot is used as an operator in plyr and magrittr. I spent a couple of hours looking in base R for every synonym I could think of for dot operator, with every help tool I knew of; I even ran some ridiculous regex searches. Finally, in desperation, I tried this:

>. <- 27
>.
[1] 27

So far, I have failed to disconfirm that a naked dot, without even a ` ` to its name, is a valid variable name in R. But I am still hoping that this is merely a side-effect from some more sensible behavior, documented somewhere.

Is it? And if so, where?

I acknowledge that in its first appearance in the Win Vector blog, the authors identified it as a joke.


Solution

  • . can be used as a valid object name (a syntactically valid name) and documented here:

    A syntactically valid name consists of letters, numbers and the dot or underline characters and starts with a letter or the dot not followed by a number." (from manual of make.names).

    The single dot satisfies "the dot not followed by a number."