0

I was wondering about this %>% so I typed ?%>%into the console and got: Error: unexpected SPECIAL in "?%>%". Fair enough. So I typed ?"%>%" and got the following:

%>%                   package:tidyr                    R Documentation

Pipe operator

Description:

     See ‘%>%’ for more details.

Usage:

     lhs %>% rhs

Okay then! Typing ?'%>%', however, lead me to the exact same help page. What's my mistake?
No need to explain the pipe operator, I googled it by now, but what would I have done, was I on a train with no internet?

Edit. I see this question was somewhat misleading, so let me rephrase. How do I find the appropriate documentation for the %>% pipe operator in R's help documentation? What exactly does it mean if a documentation tells me "See ... for more details"? What am I supposed to do then?

Frank
  • 66,179
  • 8
  • 96
  • 180
vanao veneri
  • 970
  • 2
  • 12
  • 31

2 Answers2

8

%>% is an binary infix operator, you need to use it with operands, or you'll recieve an error. Hence the specified usage:

lhs %>% rhs

In you case above, writing ?%>% will attempt to call %>% using ? as your lhs operator. Hence the error ... unexpected SPECIAL .... If you, on the other hand, wrap your operator in '...' or "...", it will use the ? prefix as you intend: showing the help section for that operator.

As an example, try the following in your console:

?<     <-- Error: unexpected '<' in "?<"
?'<'   <-- OK
?"<"   <-- OK

(after first edit of question)

Now, regarding your updated question, where to find appropriate documentation for the pipe operator, I quote this site

Although not required, the tidyr and dplyr packages make use of the pipe operator %>% developed by Stefan Milton Bache in the R package magrittr. Although all the functions in tidyr and dplyr can be used without the pipe operator, one of the great conveniences these packages provide is the ability to string multiple functions together by incorporating %>%.

Hence, an appropriate place to begin would be in the documentation for the magrittr package:


(after second edit of question)

Finally, if we take a look at how the associated tidyr manual page for the pipe operator is generated, we get our answer to your final edit:

% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/utils.R
\name{\%>\%}
\alias{\%>\%}
\title{Pipe operator}
\usage{
lhs \%>\% rhs
}
\description{
See \code{\link[magrittr]{\%>\%}} for more details.
}
\keyword{internal}

Hence, your help page is supposed to contain a link to the magrittr help page for the pipe operator, but if you are running from e.g. terminal (are you?), then you will only be shown plain text, in so loosing (or at least not seeing) the link.

dfrib
  • 70,367
  • 12
  • 127
  • 192
1

%>% originally comes from the matrittr package. You can find documentation about the pipe operator there (Github page).

mrub
  • 501
  • 2
  • 12
  • 30