stringr (development version) Unreleased

Breaking changes

  • stringr functions now consistently implement the tidyverse recycling rules (#372). Overall this is a fairly minor change as stringi was already very close to the tidyverse rules. There are only two major changes:

    Additionally, many more non-vectorised arguments now throw errors, rather than warnings, if supplied a vector.

  • str_split_fixed() now pads with NA rather than " " (#195).

New features

  • str_view() will use ANSI colouring if available (#370). This works in more places than HTML widgets and requires fewer dependencies. str_view() also no longer requires a pattern so you can use it to display strings with special characters. It now highlights whitespace characters apart from space since otherwise they are often confusing.

  • New vignette("from-base") by @sastoudt provides a comprehensive comparison between base R functions and their stringr equivalents. It’s designed to help you move to stringr if you’re already familiar with base R string functions (#266).

  • New str_equal() compares two character vectors using unicode rules, and optionally ignores case (#381).

  • New str_split_n() function to extract only a single piece from a string (#278, @bfgray3).

  • New str_like() function which allows the use of SQL wildcards (#280, @rjpat).

  • New str_unique() is a wrapper around stri_unique() and returns unique string values in a character vector (#249, @seasmith).

  • stringr is now licensed as MIT (#351).

Minor improvements and bug fixes

  • Better error message if you supply a non-string pattern (#378).

  • Many typos in sentences have been fixed (@romatik, #299)

  • str_flatten() gains a last argument that optionally override the final separator (#377).

  • str_pad() gains use_length argument to control whether to use the total code point width or the number of code points as “width” of a string (#190).

  • str_replace() and str_replace_all() can use standard tidyverse formula shorthand for replacement function (#331).

  • str_starts() and str_ends() now correctly respect regex operator precedence (@carlganz).

  • str_wrap() breaks only at whitespace by default; set whitespace_only = FALSE to return to the previous behaviour (#335, @rjpat).

  • word() now returns all the sentence when using a negative start parameter that is greater or equal than the number of words. (@pdelboca, #245)

stringr 1.4.0 2019-02-10

stringr 1.3.1 2018-05-10

  • str_replace_all() with a named vector now respects modifier functions (#207)

  • str_trunc() is once again vectorised correctly (#203, @austin3dickey).

  • str_view() handles NA values more gracefully (#217). I’ve also tweaked the sizing policy so hopefully it should work better in notebooks, while preserving the existing behaviour in knit documents (#232).

stringr 1.3.0 2018-02-19

API changes

  • During package build, you may see Error : object ‘’ is not exported by 'namespace:stringr'. This is because the long deprecated str_join(), and perl() have now been removed.

New features

Bug fixes and minor improvements

stringr 1.2.0 2017-02-18

API changes

  • str_match_all() now returns NA if an optional group doesn’t match (previously it returned ""). This is more consistent with str_match() and other match failures (#134).

New features

Minor improvements and bug fixes

  • str_order() and str_sort() gain explicit numeric argument for sorting mixed numbers and strings.

  • str_replace_all() now throws an error if replacement is not a character vector. If replacement is NA_character_ it replaces the complete string with replaces with NA (#124).

  • All functions that take a locale (e.g. str_to_lower() and str_sort()) default to “en” (English) to ensure that the default is consistent across platforms.

stringr 1.1.0 2016-08-19

stringr 1.0.0 2015-04-30

  • stringr is now powered by stringi instead of base R regular expressions. This improves unicode and support, and makes most operations considerably faster. If you find stringr inadequate for your string processing needs, I highly recommend looking at stringi in more detail.

  • stringr gains a vignette, currently a straight forward update of the article that appeared in the R Journal.

  • str_c() now returns a zero length vector if any of its inputs are zero length vectors. This is consistent with all other functions, and standard R recycling rules. Similarly, using str_c("x", NA) now yields NA. If you want "xNA", use str_replace_na() on the inputs.

  • str_replace_all() gains a convenient syntax for applying multiple pairs of pattern and replacement to the same vector:

    input <- c("abc", "def")
    str_replace_all(input, c("[ad]" = "!", "[cf]" = "?"))
  • str_match() now returns NA if an optional group doesn’t match (previously it returned ""). This is more consistent with str_extract() and other match failures.

  • New str_subset() keeps values that match a pattern. It’s a convenient wrapper for x[str_detect(x)] (#21, @jiho).

  • New str_order() and str_sort() allow you to sort and order strings in a specified locale.

  • New str_conv() to convert strings from specified encoding to UTF-8.

  • New modifier boundary() allows you to count, locate and split by character, word, line and sentence boundaries.

  • The documentation got a lot of love, and very similar functions (e.g. first and all variants) are now documented together. This should hopefully make it easier to locate the function you need.

  • has been deprecated in favour of fixed|regex|coll(x, = TRUE), perl(x) has been deprecated in favour of regex(x).

  • str_join() is deprecated, please use str_c() instead.

stringr 0.6.2 2012-12-06

  • fixed path in str_wrap example so works for more R installations.

  • remove dependency on plyr

stringr 0.6.1 2012-07-25

  • Zero input to str_split_fixed returns 0 row matrix with n columns

  • Export str_join

stringr 0.6 2011-12-08

  • new modifier perl that switches to Perl regular expressions

  • str_match now uses new base function regmatches to extract matches - this should hopefully be faster than my previous pure R algorithm

stringr 0.5 2011-06-30

  • new str_wrap function which gives strwrap output in a more convenient format

  • new word function extract words from a string given user defined separator (thanks to suggestion by David Cooper)

  • str_locate now returns consistent type when matching empty string (thanks to Stavros Macrakis)

  • new str_count counts number of matches in a string.

  • str_pad and str_trim receive performance tweaks - for large vectors this should give at least a two order of magnitude speed up

  • str_length returns NA for invalid multibyte strings

  • fix small bug in internal recyclable function

stringr 0.4 2010-08-24

  • all functions now vectorised with respect to string, pattern (and where appropriate) replacement parameters
  • fixed() function now tells stringr functions to use fixed matching, rather than escaping the regular expression. Should improve performance for large vectors.
  • new modifier tells stringr functions to ignore case of pattern.
  • str_replace renamed to str_replace_all and new str_replace function added. This makes str_replace consistent with all functions.
  • new str_sub<- function (analogous to substring<-) for substring replacement
  • str_sub now understands negative positions as a position from the end of the string. -1 replaces Inf as indicator for string end.
  • str_pad side argument can be left, right, or both (instead of center)
  • str_trim gains side argument to better match str_pad
  • stringr now has a namespace and imports plyr (rather than requiring it)

stringr 0.3 2010-02-15

  • fixed() now also escapes |
  • str_join() renamed to str_c()
  • all functions more carefully check input and return informative error messages if not as expected.
  • add invert_match() function to convert a matrix of location of matches to locations of non-matches
  • add fixed() function to allow matching of fixed strings.

stringr 0.2 2009-11-16

  • str_length now returns correct results when used with factors
  • str_sub now correctly replaces Inf in end argument with length of string
  • new function str_split_fixed returns fixed number of splits in a character matrix
  • str_split no longer uses strsplit to preserve trailing breaks