From f55997b9619b4edff8f739510821fa3ad3b59ea4 Mon Sep 17 00:00:00 2001 From: Floris Vanderhaeghe Date: Sat, 2 Mar 2024 02:12:26 +0100 Subject: [PATCH] Some fixes for chapters regexps & factors (#1636) * regexps.qmd: fix name of 'too_few' arg * regexps.qmd: fix typo * factors.qmd: update argument names to .f, .x, .y * factors.qmd: fix language --- factors.qmd | 12 ++++++------ regexps.qmd | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/factors.qmd b/factors.qmd index a98871e..5e78ba7 100644 --- a/factors.qmd +++ b/factors.qmd @@ -177,9 +177,9 @@ It is hard to read this plot because there's no overall pattern. We can improve it by reordering the levels of `relig` using `fct_reorder()`. `fct_reorder()` takes three arguments: -- `f`, the factor whose levels you want to modify. -- `x`, a numeric vector that you want to use to reorder the levels. -- Optionally, `fun`, a function that's used if there are multiple values of `x` for each value of `f`. The default value is `median`. +- `.f`, the factor whose levels you want to modify. +- `.x`, a numeric vector that you want to use to reorder the levels. +- Optionally, `.fun`, a function that's used if there are multiple values of `.x` for each value of `.f`. The default value is `median`. ```{r} #| fig-alt: | @@ -231,7 +231,7 @@ Reserve `fct_reorder()` for factors whose levels are arbitrarily ordered. However, it does make sense to pull "Not applicable" to the front with the other special levels. You can use `fct_relevel()`. -It takes a factor, `f`, and then any number of levels that you want to move to the front of the line. +It takes a factor, `.f`, and then any number of levels that you want to move to the front of the line. ```{r} #| fig-alt: | @@ -247,7 +247,7 @@ ggplot(rincome_summary, aes(x = age, y = fct_relevel(rincome, "Not applicable")) Why do you think the average age for "Not applicable" is so high? Another type of reordering is useful when you are coloring the lines on a plot. -`fct_reorder2(f, x, y)` reorders the factor `f` by the `y` values associated with the largest `x` values. +`fct_reorder2(.f, .x, .y)` reorders the factor `.f` by the `.y` values associated with the largest `.x` values. This makes the plot easier to read because the colors of the line at the far right of the plot will line up with the legend. ```{r} @@ -287,7 +287,7 @@ Combine it with `fct_rev()` if you want them in increasing frequency so that in ```{r} #| fig-alt: | -#| A bar char of marital status ordered in from least to most common: +#| A bar char of marital status ordered from least to most common: #| no answer (~0), separated (~1,000), widowed (~2,000), divorced #| (~3,000), never married (~5,000), married (~10,000). gss_cat |> diff --git a/regexps.qmd b/regexps.qmd index c34dc7c..66b7872 100644 --- a/regexps.qmd +++ b/regexps.qmd @@ -265,7 +265,7 @@ df |> ) ``` -If the match fails, you can use `too_short = "debug"` to figure out what went wrong, just like `separate_wider_delim()` and `separate_wider_position()`. +If the match fails, you can use `too_few = "debug"` to figure out what went wrong, just like `separate_wider_delim()` and `separate_wider_position()`. ### Exercises @@ -336,7 +336,7 @@ That lets you avoid one layer of escaping: str_view(x, r"{\\}") ``` -If you're trying to match a literal `.`, `$`, `|`, `*`, `+`, `?`, `{`, `}`, `(`, `)`, there's an alternative to using a backslash escape: you can use a character class: `[.]`, `[$]`, `[|]`, \... +If you're trying to match a literal `.`, `$`, `|`, `*`, `+`, `?`, `{`, `}`, `(`, `)`, there's an alternative to using a backslash escape: you can use a character class: `[.]`, `[$]`, `[|]`, ... all match the literal values. ```{r}