Add dev version caveats
This commit is contained in:
parent
23b9caa7ae
commit
45353e0a58
|
@ -22,6 +22,11 @@ We'll finish up with a survey of other places in stringr, the tidyverse, and bas
|
||||||
|
|
||||||
### Prerequisites
|
### 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.
|
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}
|
```{r}
|
||||||
|
|
27
strings.qmd
27
strings.qmd
|
@ -18,6 +18,11 @@ The chapter finishes up with functions that work with individual letters and a b
|
||||||
|
|
||||||
### Prerequisites
|
### 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.
|
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.
|
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()`:
|
If you want missing values to display in some other way, use `coalesce()` either inside or outside of `str_c()`:
|
||||||
|
|
||||||
```{r}
|
```{r}
|
||||||
df |> mutate(
|
df |>
|
||||||
|
mutate(
|
||||||
greeting1 = str_c("Hi ", coalesce(name, "you"), "!"),
|
greeting1 = str_c("Hi ", coalesce(name, "you"), "!"),
|
||||||
greeting2 = coalesce(str_c("Hi ", name, "!"), "Hi!")
|
greeting2 = coalesce(str_c("Hi ", name, "!"), "Hi!")
|
||||||
)
|
)
|
||||||
```
|
```
|
||||||
|
|
||||||
### `str_glue()` {#sec-glue}
|
### `str_glue()` {#sec-glue}
|
||||||
|
@ -305,7 +311,11 @@ They are more complicated that their `by` equivalents because you need to name t
|
||||||
```{r}
|
```{r}
|
||||||
df3 <- tibble(x = c("a,1,2022", "b,2,2011", "e,5,2015"))
|
df3 <- tibble(x = c("a,1,2022", "b,2,2011", "e,5,2015"))
|
||||||
df3 |>
|
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:
|
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}
|
```{r}
|
||||||
df3 <- tibble(x = c("a,1,2022", "b,2,2011", "e,5,2015"))
|
df3 <- tibble(x = c("a,1,2022", "b,2,2011", "e,5,2015"))
|
||||||
df3 |>
|
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:
|
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}
|
```{r}
|
||||||
df4 <- tibble(x = c("202215TX", "202122LA", "202325CA"))
|
df4 <- tibble(x = c("202215TX", "202122LA", "202325CA"))
|
||||||
df4 |>
|
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
|
### Case studies
|
||||||
|
|
Loading…
Reference in New Issue