stringr v1.0.0

0

Monthly downloads

0th

Percentile

by Hadley Wickham

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.

Readme

stringr

Build Status

Strings are not glamorous, high-profile components of R, but they do play a big role in many data cleaning and preparations tasks. R provides a solid set of string operations, but because they have grown organically over time, they can be inconsistent and a little hard to learn. Additionally, they lag behind the string operations in other programming languages, so that some things that are easy to do in languages like Ruby or Python are rather hard to do in R.

The stringr package aims to remedy these problems by providing a clean, modern interface to common string operations. More concretely, stringr:

  • Uses consistent functions and argument names.

  • Simplifies string operations by eliminating options that you don't need 95% of the time.

  • Produces outputs than can easily be used as inputs. This includes ensuring that missing inputs result in missing outputs, and zero length inputs result in zero length outputs.

  • Is built on top of stringi which uses the ICU library to provide fast, correct implementations of common string manipulations

Installation

To get the current released version from CRAN:

install.packages("stringr")

To get the current development version from github:

# install.packages("devtools")
devtools::install_github("Rexamine/stringi")
devtools::install_github("hadley/stringr")

Piping

stringr provides the pipe, %>%, from magrittr to make it easy to string together sequences of string operations:

letters %>%
  str_pad(5, "right") %>%
  str_c(letters)

Functions in stringr

Name Description
str_subset Keep strings matching a pattern.
str_replace Replace matched patterns in a string.
str_c Join multiple strings into a single string.
str_length The length of a string.
str_wrap Wrap strings into nicely formatted paragraphs.
str_match Extract matched groups from a string.
word Extract words from a sentence.
str_dup Duplicate and concatenate strings within a character vector.
str_pad Pad a string.
stringr Fast and friendly string manipulation.
str_order Order or sort a character vector.
str_trim Trim whitespace from start and end of string.
str_split Split up a string into pieces.
modifier-deprecated Deprecated modifier functions.
str_sub Extract and replace substrings from a character vector.
modifiers Control matching behaviour with modifier functions.
invert_match Switch location of matches to location of non-matches.
str_count Count the number of matches in a string.
case Convert case of a string.
str_locate Locate the position of patterns in a string.
%>% Pipe operator
str_detect Detect the presence or absence of a pattern in a string.
str_conv Specify the encoding of a string.
str_extract Extract matching patterns from a string.
str_replace_na Turn NA into "NA"
No Results!

Last month downloads

Details

License GPL-2
VignetteBuilder knitr
NeedsCompilation no
Packaged 2015-04-29 12:46:34 UTC; hadley
Repository CRAN
Date/Publication 2015-04-30 11:48:24

Include our badge in your README

[![Rdoc](http://www.rdocumentation.org/badges/version/stringr)](http://www.rdocumentation.org/packages/stringr)