grapes-DT-greater-than-grapes: Pipe a data.table one liner

Description Usage Arguments Details Examples

Description

Inspired by magrittr::`%>%` , allows one to use data.table syntax on a non data.table data frame and return an object of the same class as the input. It is especially useful when used in a in a magrittr / tidyverse pipe chain.

Usage

1
lhs %DT>% rhs

Arguments

lhs

A data.frame

rhs

A data.table call starting with "."

Details

Unlike with magrittr only the first dot is subtituted, so .() can still be used in the call.

%DT>% is more efficient than withDT, their use cases overlap but they are different in that %DT>% will allow data.table syntax on a single table while an expression fed to withDT() can contain several data frames that we all be treated as data.table objects.

Examples

1
2
3
4
5
6
7
8
9
## Not run: 
  library(tidyverse)
  iris %>%
    as_tibble() %DT>%
    .[, .(meanSW = mean(Sepal.Width)), by = Species][
      ,Species := as.character(Species)] %>%
    filter(startsWith(Species,"v"))

## End(Not run)

moodymudskipper/withDT documentation built on Nov. 4, 2019, 7:29 p.m.