Copy edits
This commit is contained in:
parent
fba7109975
commit
adac82ba3f
|
@ -403,7 +403,7 @@ Embracing a variable means to wrap it in braces so (e.g.) `var` becomes `{{ var
|
|||
Embracing a variable tells dplyr to use the value stored inside the argument, not the argument as the literal variable name.
|
||||
One way to remember what's happening is to think of `{{ }}` as looking down a tunnel --- `{{ var }}` will make a dplyr function look inside of `var` rather than looking for a variable called `var`.
|
||||
|
||||
So to make grouped_mean`()` work, we need to surround `group_var` and `mean_var` with `{{ }}`:
|
||||
So to make `grouped_mean()` work, we need to surround `group_var` and `mean_var` with `{{ }}`:
|
||||
|
||||
```{r}
|
||||
grouped_mean <- function(df, group_var, mean_var) {
|
||||
|
@ -819,7 +819,7 @@ Additionally, `function()` should always be followed by squiggly brackets (`{}`)
|
|||
This makes it easier to see the hierarchy in your code by skimming the left-hand margin.
|
||||
|
||||
```{r}
|
||||
# missing extra two spaces
|
||||
# Missing extra two spaces
|
||||
density <- function(color, facets, binwidth = 0.1) {
|
||||
diamonds |>
|
||||
ggplot(aes(x = carat, y = after_stat(density), color = {{ color }})) +
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
```{r}
|
||||
#| results: "asis"
|
||||
#| echo: false
|
||||
|
||||
source("_common.R")
|
||||
status("complete")
|
||||
```
|
||||
|
@ -17,7 +18,7 @@ In most other languages, you'd need to explicitly double each element of `x` usi
|
|||
This book has already given you a small but powerful number of tools that perform the same action for multiple "things":
|
||||
|
||||
- `facet_wrap()` and `facet_grid()` draws a plot for each subset.
|
||||
- `group_by()` plus `summarize()` computes a summary statistics for each subset.
|
||||
- `group_by()` plus `summarize()` computes summary statistics for each subset.
|
||||
- `unnest_wider()` and `unnest_longer()` create new rows and columns for each element of a list-column.
|
||||
|
||||
Now it's time to learn some more general tools, often called **functional programming** tools because they are built around functions that take other functions as inputs.
|
||||
|
@ -283,7 +284,7 @@ df_miss |> filter(if_all(a:d, is.na))
|
|||
### `across()` in functions
|
||||
|
||||
`across()` is particularly useful to program with because it allows you to operate on multiple columns.
|
||||
For example, [Jacob Scott](https://twitter.com/_wurli/status/1571836746899283969) uses this little helper which wraps a bunch of lubridate function to expand all date columns into year, month, and day columns:
|
||||
For example, [Jacob Scott](https://twitter.com/_wurli/status/1571836746899283969) uses this little helper which wraps a bunch of lubridate functions to expand all date columns into year, month, and day columns:
|
||||
|
||||
```{r}
|
||||
expand_dates <- function(df) {
|
||||
|
|
|
@ -551,6 +551,7 @@ For example here are two inline CSVs with unusual encodings[^strings-7]:
|
|||
|
||||
```{r}
|
||||
#| message: false
|
||||
|
||||
x1 <- "text\nEl Ni\xf1o was particularly bad this year"
|
||||
read_csv(x1)
|
||||
|
||||
|
|
Loading…
Reference in New Issue