Add dev version caveats

This commit is contained in:
Hadley Wickham 2022-11-07 08:53:17 -06:00
parent 23b9caa7ae
commit 45353e0a58
2 changed files with 29 additions and 7 deletions

View File

@ -22,6 +22,11 @@ We'll finish up with a survey of other places in stringr, the tidyverse, and bas
### Prerequisites
::: callout-important
This chapter relies on features only found in stringr 1.5.0 and tidyr 1.3.0 which are still in development.
If you want to live life on the edge you can get the dev versions with `devtools::install_github(c("tidyverse/stringr", "tidyverse/tidyr"))`.
:::
In this chapter, we'll use regular expression functions from stringr and tidyr, both core members of the tidyverse, as well as data from the babynames package.
```{r}

View File

@ -18,6 +18,11 @@ The chapter finishes up with functions that work with individual letters and a b
### Prerequisites
::: callout-important
This chapter relies on features only found in stringr 1.5.0 and tidyr 1.3.0 which are still in development.
If you want to live life on the edge you can get the dev versions with `devtools::install_github(c("tidyverse/stringr", "tidyverse/tidyr"))`.
:::
In this chapter, we'll use functions from the stringr package which is part of the core tidyverse.
We'll also use the babynames data since it provides some fun strings to manipulate.
@ -173,10 +178,11 @@ df |> mutate(greeting = str_c("Hi ", name, "!"))
If you want missing values to display in some other way, use `coalesce()` either inside or outside of `str_c()`:
```{r}
df |> mutate(
greeting1 = str_c("Hi ", coalesce(name, "you"), "!"),
greeting2 = coalesce(str_c("Hi ", name, "!"), "Hi!")
)
df |>
mutate(
greeting1 = str_c("Hi ", coalesce(name, "you"), "!"),
greeting2 = coalesce(str_c("Hi ", name, "!"), "Hi!")
)
```
### `str_glue()` {#sec-glue}
@ -305,7 +311,11 @@ They are more complicated that their `by` equivalents because you need to name t
```{r}
df3 <- tibble(x = c("a,1,2022", "b,2,2011", "e,5,2015"))
df3 |>
separate_wider_delim(x, delim = ",", names = c("letter", "number", "year"))
separate_wider_delim(
x,
delim = ",",
names = c("letter", "number", "year")
)
```
If a specific value is not useful you can use `NA` to omit it from the results:
@ -313,7 +323,11 @@ If a specific value is not useful you can use `NA` to omit it from the results:
```{r}
df3 <- tibble(x = c("a,1,2022", "b,2,2011", "e,5,2015"))
df3 |>
separate_wider_delim(x, delim = ",", names = c("letter", NA, "year"))
separate_wider_delim(
x,
delim = ",",
names = c("letter", NA, "year")
)
```
Alternatively, you can provide `names_sep` and `separate_wider_delim()` will use that separator to name automatically:
@ -330,7 +344,10 @@ You can omit values from the output by not naming them:
```{r}
df4 <- tibble(x = c("202215TX", "202122LA", "202325CA"))
df4 |>
separate_wider_position(x, c(year = 4, age = 2, state = 2))
separate_wider_position(
x,
c(year = 4, age = 2, state = 2)
)
```
### Case studies