Use str_view htmlwidget
This commit is contained in:
parent
4ca5cdbaab
commit
5e65371942
|
@ -23,7 +23,7 @@ install:
|
|||
# Install R packages
|
||||
- ./travis-tool.sh r_binary_install knitr png
|
||||
- ./travis-tool.sh r_install ggplot2 dplyr tidyr pryr stringr
|
||||
- ./travis-tool.sh github_package hadley/bookdown garrettgman/DSR hadley/readr gaborcsardi/rcorpora
|
||||
- ./travis-tool.sh github_package hadley/bookdown garrettgman/DSR hadley/readr gaborcsardi/rcorpora hadley/stringr
|
||||
|
||||
script: jekyll build
|
||||
|
||||
|
|
10
strings.Rmd
10
strings.Rmd
|
@ -176,7 +176,7 @@ common <- rcorpora::corpora("words/common")$commonWords
|
|||
### Match anything and escaping
|
||||
|
||||
```{r}
|
||||
str_subset(c("abc", "adc", "bef"), "a.c")
|
||||
str_view(c("abc", "adc", "bef"), "a.c")
|
||||
```
|
||||
|
||||
But if "`.`" matches any character, how do you match an actual "`.`"? You need to use an "escape" to tell the regular expression you want to match it exactly, not use the special behaviour. The escape character used by regular expressions is `\`. Unfortunately, that's also the escape character used by strings, so to match a literal "`.`" you need to use `\\.`.
|
||||
|
@ -189,7 +189,7 @@ dot <- "\\."
|
|||
cat(dot, "\n")
|
||||
|
||||
# And this tells R to look for explicit .
|
||||
str_subset(c("abc", "a.c", "bef"), "a\\.c")
|
||||
str_view(c("abc", "a.c", "bef"), "a\\.c")
|
||||
```
|
||||
|
||||
If `\` is used an escape character, how do you match a literal `\`? Well you need to escape it, creating the regular expression `\\`. And in R that needs to be in a string, so you need to write `"\\\\"` - that's right, you need four backslashes to match one!
|
||||
|
@ -218,7 +218,7 @@ Regular expressions can also match things that are not characters. The most impo
|
|||
To force a regular expression to only match a complete string, anchor it with both `^` and `$`.:
|
||||
|
||||
```{r}
|
||||
str_detect(c("abcdef", "bcd"), "^bcd$")
|
||||
str_view(c("abcdef", "bcd"), "^bcd$")
|
||||
```
|
||||
|
||||
My favourite mneomic for rememember which is which (from [Evan Misshula](https://twitter.com/emisshula/status/323863393167613953): begin with power (`^`), end with money (`$`).
|
||||
|
@ -246,13 +246,13 @@ Remember, to create a regular expression containing `\d` or `\s`, you'll need to
|
|||
A similar idea is alternation: `x|y` matches either x or y. Note that the precedence for `|` is low, so that `abc|xyz` matches either `abc` or `xyz` not `abcyz` or `abxyz`:
|
||||
|
||||
```{r}
|
||||
str_detect(c("abc", "xyz"), "abc|xyz")
|
||||
str_view(c("abc", "xyz"), "abc|xyz")
|
||||
```
|
||||
|
||||
Like with mathematical expression, if precedence ever gets confusing, use parentheses to make it clear what you want:
|
||||
|
||||
```{r}
|
||||
str_detect(c("grey", "gray"), "gr(e|a)y")
|
||||
str_view(c("grey", "gray"), "gr(e|a)y")
|
||||
```
|
||||
|
||||
Practice these by finding:
|
||||
|
|
|
@ -1,3 +1 @@
|
|||
bootstrap-2.3.2/
|
||||
highlight/
|
||||
jquery-1.11.0/
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue