12

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.

andrewH
  • 2,281
  • 2
  • 22
  • 32
  • 15
    `.` can be used as a valid object name (a syntactically valid name): "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." – mt1022 Dec 23 '17 at 08:04
  • 4
    Also note that this is not new. The proto package, on CRAN since 2005, used the convention in the documentation that dot is the current object so that one can compactly refer to variable `x` in the current object using `.$x` . (The user can also use any other name --`this` might be a common alternative. ) – G. Grothendieck Dec 23 '17 at 11:28
  • 4
    I would not call that pipe-like behavior, in the end that is just two commands put on a single line, basically same like having `x <- 2` and `exp(x)` on two separate lines. (and yes, you could also do something like `a <- 2 -> b`, but these are really just assignments) – RolandASc Feb 01 '18 at 15:00
  • @mt1022 can you post as an answer ? – moodymudskipper Mar 24 '18 at 18:23
  • 1
    @Moody_Mudskipper, thanks for the kind reminder. I didn't expect this question will draw so much attention. I did as you suggested and added the corresponding link. Hope this is more helpful now. – mt1022 Mar 25 '18 at 15:30

1 Answers1

3

. 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."

mt1022
  • 16,834
  • 5
  • 48
  • 71