-
Notifications
You must be signed in to change notification settings - Fork 7
/
index.qmd
77 lines (51 loc) · 2.14 KB
/
index.qmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
---
title: "Seal of Approval: dtplyr"
author: "Kelly Bodwin"
date: "May 07, 2024"
categories: [seal of approval, bridge package]
image: "hex.png"
draft: true
---
## [`dtplyr`](https://github.com/tidyverse/dtplyr)
::::{.columns}
:::{.column width="40%"}
![dtplyr hex sticker](hex.png)
:::
:::{.column width="60%"}
*Author(s):* Hadley Wickham, Maximilian Girlich, Mark Fairbanks, Ryan Dickerson, Posit Software PBC
*Maintainer:* Hadley Wickham (hadley\@posit.co)
[Seal of Approval](<link to approval>)
Provides a `data.table` backend for `dplyr`. The goal of `dtplyr` is to allow you to write `dplyr` code that is automatically translated to the equivalent, but usually much faster, `data.table` code.
:::
::::
## Relationship with `data.table`
`dtplyr` is a bridge for users who are more comfortable with the `dplyr` syntax, but who want to take advantage of the speed and efficiency benefits of `data.table`. This package exactly duplicates the core functions of `dplyr`, but replaces the back-end source code (originally in Base R) with `data.table` operations.
## Overview
*Excerpted from the [`dtplyr` vignette](https://dtplyr.tidyverse.org/)*
To use `dtplyr`, you must at least load `dtplyr` and `dplyr`. You may also want to load `data.table` so you can access the other goodies that it provides:
```{r}
library(data.table)
library(dtplyr)
library(dplyr, warn.conflicts = FALSE)
```
Then use `lazy_dt()` to create a “lazy” `data.table` object that tracks the operations performed on it.
```{r}
mtcars2 <- lazy_dt(mtcars)
```
You can preview the transformation (including the generated `data.table` code) by printing the result:
```{r}
mtcars2 %>%
filter(wt < 5) %>%
mutate(l100k = 235.21 / mpg) %>% # liters / 100 km
group_by(cyl) %>%
summarise(l100k = mean(l100k))
```
But generally you should reserve this only for debugging, and use `as.data.table()`, `as.data.frame()`, or `as_tibble()` to indicate that you’re done with the transformation and want to access the results:
```{r}
mtcars2 %>%
filter(wt < 5) %>%
mutate(l100k = 235.21 / mpg) %>% # liters / 100 km
group_by(cyl) %>%
summarise(l100k = mean(l100k)) %>%
as_tibble()
```