Package: stringr

Hadley Wickham

stringr: Simple, Consistent Wrappers for Common String Operations

A consistent, simple and easy to use set of wrappers around the fantastic 'stringi' package. All function and argument names (and positions) are consistent, all functions deal with "NA"'s and zero length vectors in the same way, and the output from one function is easy to feed into the input of another.

Authors:Hadley Wickham [aut, cre, cph], Posit Software, PBC [cph, fnd]

stringr.pdf |stringr.html
stringr/json (API)

# Install stringr in R:
install.packages('stringr', repos = c('', ''))

Peer review:

Bug tracker:

  • fruit - Sample character vectors for practicing string manipulations
  • sentences - Sample character vectors for practicing string manipulations
  • words - Sample character vectors for practicing string manipulations



59 exports 577 stars 21.12 score 7 dependencies 12930 dependents

Last updated 7 months agofrom:a64b8f1ccc2506cfa4b7af7b9fa7766200eb71ac



From base R

Rendered fromfrom-base.Rmdusingknitr::rmarkdownon May 13 2024.

Last update: 2022-12-07
Started: 2019-05-14

Introduction to stringr

Rendered fromstringr.Rmdusingknitr::rmarkdownon May 13 2024.

Last update: 2018-08-28
Started: 2014-11-28

Regular expressions

Rendered fromregular-expressions.Rmdusingknitr::rmarkdownon May 13 2024.

Last update: 2022-10-31
Started: 2016-10-16

Readme and manuals

Help Manual

Help pageTopics
Convert string to upper case, lower case, title case, or sentence casecase str_to_lower str_to_sentence str_to_title str_to_upper
Switch location of matches to location of non-matchesinvert_match
Control matching behaviour with modifier functionsboundary coll fixed modifiers regex
Join multiple strings into one stringstr_c
Specify the encoding of a stringstr_conv
Count number of matchesstr_count
Detect the presence/absence of a matchstr_detect
Duplicate a stringstr_dup
Determine if two strings are equivalentstr_equal
Escape regular expression metacharactersstr_escape
Extract the complete matchstr_extract str_extract_all
Flatten a stringstr_flatten str_flatten_comma
Interpolation with gluestr_glue str_glue_data
Compute the length/widthstr_length str_width
Detect a pattern in the same way as 'SQL''s 'LIKE' operatorstr_like
Find location of matchstr_locate str_locate_all
Extract components (capturing groups) from a matchstr_match str_match_all
Order, rank, or sort a character vectorstr_order str_rank str_sort
Pad a string to minimum widthstr_pad
Remove matched patternsstr_remove str_remove_all
Replace matches with new textstr_replace str_replace_all
Turn NA into "NA"str_replace_na
Split up a string into piecesstr_split str_split_1 str_split_fixed str_split_i
Detect the presence/absence of a match at the start/endstr_ends str_starts
Get and set substrings using their positionsstr_sub str_sub<- str_sub_all
Find matching elementsstr_subset
Remove whitespacestr_squish str_trim
Truncate a string to maximum widthstr_trunc
Remove duplicated stringsstr_unique
View strings and matchesstr_view str_view_all
Find matching indicesstr_which
Wrap words into nicely formatted paragraphsstr_wrap
Sample character vectors for practicing string manipulationsfruit sentences stringr-data words
Extract words from a sentenceword