stringr in R
Consistent argument order: the string first, the pattern second.
library(stringr)
files <- c("r/dp_select.R", "python/pd_merge.py", "go/go_test_basic.go")
print(str_detect(files, "^r/"))
print(str_replace(files, "^[a-z]+/", ""))
print(str_extract(files, "\\.[a-z]+$"))
print(str_split(files, "/", simplify = TRUE))
print(str_pad(c("r", "python"), width = 8, side = "right", pad = "."))
print(str_to_title("language basics"))
lang <- "r"
steps <- 138
print(str_glue("{lang} has {steps} steps"))
How it works
- Every function is
str_plus a verb. str_detect,str_replaceandstr_extractcover most work.str_glueinterpolates, like an f-string.
Keywords and builtins used here
clibraryprintstr_detectstr_extractstr_gluestr_padstr_replacestr_splitstr_to_title
The run, in numbers
- Lines
- 14
- Characters to type
- 431
- Tokens
- 115
- Three-star pace
- 100 tpm
At the three-star pace of 100 tokens a minute, this run takes about 69 seconds.
Step 2 of 3 in stringr, step 6 of 10 in Functional & text tools.