Skip to content

Commit

Permalink
Update 03-dplyr.Rmd
Browse files Browse the repository at this point in the history
Added information on the native R pipe, since only the Magritte pipe was shown here. A brief introduction to the native pipe and a link to more details on the comparison between the pipes were added.
  • Loading branch information
griffindoc authored Sep 6, 2023
1 parent c4ae092 commit 9e72536
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions episodes/03-dplyr.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -202,17 +202,21 @@ selecting).

The last option, *pipes*, are a recent addition to R. Pipes let you take the
output of one function and send it directly to the next, which is useful when
you need to do many things to the same dataset. Pipes in R look like `%>%` and
are made available via the **`magrittr`** package, installed automatically with
**`dplyr`**. If you use RStudio, you can type the pipe with:
you need to do many things to the same dataset. There are two Pipes in R: 1) `%>%` (called magrittr pipe; made available via the **`magrittr`** package, installed automatically with
**`dplyr`**) or 2) `|>` (called native R pipe and it comes preinstalled with R v4.1.0 onwards). Both the pipes are, by and large, function similarly with a few differences (For more information, check: https://www.tidyverse.org/blog/2023/04/base-vs-magrittr-pipe/). The choice of which pipe to be used can be changed in the Global settings in R studio and once that is done, you can type the pipe with:

- <kbd>Ctrl</kbd> + <kbd>Shift</kbd> + <kbd>M</kbd> if you have a PC or <kbd>Cmd</kbd> +
<kbd>Shift</kbd> + <kbd>M</kbd> if you have a Mac.

```{r, purl=FALSE}
# the following example is run using magrittr pipe but the output will be same with the native pipe
interviews %>%
filter(village == "Chirodzo") %>%
select(village:respondent_wall_type)
#interviews |>
# filter(village == "Chirodzo") |>
# select(village:respondent_wall_type)
```

In the above code, we use the pipe to send the `interviews` dataset first
Expand Down

0 comments on commit 9e72536

Please sign in to comment.