library(microbenchmark)
library(gutenbergr)
gutenberg_works(stringr::str_detect(author, "Brontë"))
## # A tibble: 8 × 8
## gutenberg_id title author guten…¹ langu…² guten…³ rights has_t…⁴
## <int> <chr> <chr> <int> <chr> <chr> <chr> <lgl>
## 1 767 Agnes Grey Bront… 404 en <NA> Publi… TRUE
## 2 768 Wuthering Heights Bront… 405 en Gothic… Publi… TRUE
## 3 969 The Tenant of Wild… Bront… 404 en <NA> Publi… TRUE
## 4 1028 The Professor Bront… 408 en <NA> Publi… TRUE
## 5 1260 Jane Eyre: An Auto… Bront… 408 en <NA> Publi… TRUE
## 6 9182 Villette Bront… 408 en <NA> Publi… TRUE
## 7 17081 Cottage Poems Bront… 7125 en <NA> Publi… TRUE
## 8 30486 Shirley Bront… 408 en Histor… Publi… TRUE
## # … with abbreviated variable names ¹gutenberg_author_id, ²language,
## # ³gutenberg_bookshelf, ⁴has_text
book <- gutenberg_download(1260, mirror = "http://mirrors.xmission.com/gutenberg/")
jane_eyre <- book$text
a <- "Jane"
mbm <- microbenchmark("grep" = {
grepl(a, jane_eyre)},
"str_detect" = {
stringr::str_detect(jane_eyre, a)
})
mbm
## Unit: milliseconds
## expr min lq mean median uq max neval
## grep 89.0550 93.8966 103.34324 96.82550 108.8927 155.2216 100
## str_detect 4.3868 5.4578 10.05431 7.31475 11.9436 35.4976 100
ggplot2::autoplot(mbm)
## Coordinate system already present. Adding new coordinate system, which will replace the existing one.
