diff --git a/regexps.qmd b/regexps.qmd index bd2583c..64f1353 100644 --- a/regexps.qmd +++ b/regexps.qmd @@ -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} diff --git a/strings.qmd b/strings.qmd index 3079870..0b861a4 100644 --- a/strings.qmd +++ b/strings.qmd @@ -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