From adac82ba3f6bc2211ae260020f9bbd91147efe4b Mon Sep 17 00:00:00 2001 From: mine-cetinkaya-rundel Date: Tue, 9 May 2023 16:46:39 -0400 Subject: [PATCH] Copy edits --- functions.qmd | 4 ++-- iteration.qmd | 5 +++-- strings.qmd | 1 + 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/functions.qmd b/functions.qmd index ce58e37..0418432 100644 --- a/functions.qmd +++ b/functions.qmd @@ -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 }})) + diff --git a/iteration.qmd b/iteration.qmd index 9e66636..8e1f3ad 100644 --- a/iteration.qmd +++ b/iteration.qmd @@ -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) { diff --git a/strings.qmd b/strings.qmd index 5c614a7..0c23578 100644 --- a/strings.qmd +++ b/strings.qmd @@ -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)