Skip to content
Permalink
Browse files
Import %>% from magrittr. Closes #330
  • Loading branch information
hadley committed Apr 14, 2014
1 parent 8139dbf commit 89aaa9a8b386d7e3705ffb682d89dc5bebe823c0
Showing with 36 additions and 6 deletions.
  1. +2 −1 DESCRIPTION
  2. +1 −0 NAMESPACE
  3. +20 −0 NEWS.md
  4. +8 −3 R/chain.r
  5. +5 −2 man/chain.Rd
@@ -15,7 +15,8 @@ Imports:
assertthat,
utils,
methods,
Rcpp
Rcpp,
magrittr
Suggests:
hflights,
RSQLite,
@@ -255,6 +255,7 @@ S3method(union,default)
S3method(unique,sql)
S3method(update,tbl_sql)
export("%.%")
export("%>%")
export(.datatable.aware)
export(Progress)
export(anti_join)
20 NEWS.md
@@ -1,5 +1,25 @@
# dplyr 0.1.3.0.99

* dplyr now imports `%>%` from magrittr (#330). I recommend that you use this
instead of `%.%` because it is easy to type (since you can hold down the
shift key) and is more flexible. With you `%>%`, you can control which
argument on the RHS recieves the LHS, by using the pronoun `.`. This makes
`%>%` more useful with base R functions because they don't always take the
data frame as the first argument. For example you could pipe `mtcars` to
`xtabs()` with:

```R
mtcars %>% xtabs( ~ cyl + vs, data = .)
```

Thanks to @smbache for the excellent margrittr package. I recommend
reading `vignette("magrittr")` to learn more. dplyr only provides `%>%`
from magrittr. If you want to use the other useful functions that it
provides, you'll need to load it explicitly with `library(magrittr)`.

`%.%` will be deprecated in a future version of dplyr, but it won't
happen for a while.

* `do()` has been completely overhauled to be more useful. There are now
two ways to use it - either with named or unnamed arguments. If you have
named arguments, you'll get one column in the output for each named
@@ -15,7 +15,7 @@
#' 0.3. It was removed in the interest of making dplyr code more
#' standardised and \code{\%.\%} is much more popular.
#'
#' @param x,y A dataset and function to apply to it
#' @param lhs,rhs A dataset and function to apply to it
#' @param ...,calls A sequence of data transformations, starting with a dataset.
#' The first argument of each call should be omitted - the value of the
#' previous step will be substituted in automatically. Use \code{chain} and
@@ -91,6 +91,11 @@ chain_q <- function(calls, env = parent.frame()) {

#' @export
#' @rdname chain
"%.%" <- function(x, y) {
chain_q(list(substitute(x), substitute(y)), env = parent.frame())
"%.%" <- function(lhs, rhs) {
chain_q(list(substitute(lhs), substitute(rhs)), env = parent.frame())
}

#' @export
#' @rdname chain
`%>%` <- magrittr::`%>%`

@@ -1,6 +1,7 @@
% Generated by roxygen2 (4.0.0): do not edit by hand
\name{chain}
\alias{\%.\%}
\alias{\%>\%}
\alias{chain}
\alias{chain_q}
\title{Chain together multiple operations.}
@@ -9,10 +10,12 @@ chain(..., env = parent.frame())

chain_q(calls, env = parent.frame())

x \%.\% y
lhs \%.\% rhs

lhs \%>\% rhs
}
\arguments{
\item{x,y}{A dataset and function to apply to it}
\item{lhs,rhs}{A dataset and function to apply to it}

\item{...,calls}{A sequence of data transformations, starting with a dataset.
The first argument of each call should be omitted - the value of the

0 comments on commit 89aaa9a

Please sign in to comment.