Skip to content

Commit b9ffee0

Browse files
committed
Formatting fixes
1 parent daa4227 commit b9ffee0

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

episodes/08-r-regexs.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,15 @@ library(tidyverse)
3838
~~~
3939

4040
The grep equivalent in 'stringr' is `str_detect`. It's intended for use in searching vectors of strings.
41+
4142
```str_detect( string.vector, 'pattern' )```
43+
4244
Basic use returns a list of TRUE/FALSE for which vector entries matched the search pattern.
4345

44-
Note that you'll need to use double-backslashes in place of any single backslash in R.
46+
**Note that you'll need to use double-backslashes in place of any single backslash in R.**
4547

4648
For example, find words where the same letter is repeated consecutively:
49+
4750
~~~r
4851
words <- c("apple", "banana", "carrot")
4952
str_detect( words, '(\\w)\\1' )
@@ -54,7 +57,8 @@ str_detect( words, '(\\w)\\1' )
5457
~~~
5558

5659

57-
Applying the output of str_detect back to the original string vector, as indices, allows access to the actual matched entries:
60+
Applying the output of str_detect back to the original string vector, as indices, allows access to the actual matched entries:
61+
5862
~~~r
5963
words[ str_detect( words, '(\\w)\\1' ) ]
6064
~~~
@@ -132,9 +136,12 @@ framed_fruit %>%
132136

133137

134138
---
139+
135140

136141
Substitution in R is enabled through the 'str_replace' or 'str_replace_all' functions.
142+
137143
```str_replace( string.vector, 'pattern', 'replacement' )```
144+
138145
These functions will complete substitutions in all matching entries in a string vector.
139146
The difference is that 'str_replace_all' will also perform greedy matching and replacing within
140147
individual vector entries, where 'str_replace' will only replace the first match in each vector

0 commit comments

Comments
 (0)