Title: | Dependency-Free String Operations |
---|---|
Description: | Provides drop-in replacements for functions from the 'stringr' package, with the same user interface. These functions have no external dependencies and can be copied directly into your package code using the 'staticimports' package. |
Authors: | Alexander Rossell Hayes [aut, cre, cph] , Eli Pousson [ctb] (<https://orcid.org/0000-0001-8280-1706>, str_pad() and str_split() functions), Hadley Wickham [ctb, cph] (stringr package), RStudio [cph] (stringr package) |
Maintainer: | Alexander Rossell Hayes <[email protected]> |
License: | CC0 |
Version: | 0.1.2 |
Built: | 2024-11-24 05:25:02 UTC |
Source: | https://github.com/rossellhayes/stringstatic |
Compare literal bytes in the string
fixed(pattern, ignore_case = FALSE)
fixed(pattern, ignore_case = FALSE)
pattern |
Pattern to modify behavior. |
ignore_case |
Should case differences be ignored in the match? |
An integer vector.
Adapted from the stringr package.
Dependency-free drop-in alternative for stringr::fixed()
.
This is very fast,
but not usually what you want for non-ASCII character sets.
Dependency-free drop-in alternative for stringr::regex()
.
regex( pattern, ignore_case = FALSE, multiline = FALSE, comments = FALSE, dotall = FALSE )
regex( pattern, ignore_case = FALSE, multiline = FALSE, comments = FALSE, dotall = FALSE )
pattern |
Pattern to modify behavior. |
ignore_case |
Should case differences be ignored in the match? |
multiline |
If |
comments |
If |
dotall |
If |
An integer vector.
Adapted from the stringr package.
Dependency-free drop-in alternative for stringr::str_c()
.
str_c(..., sep = "", collapse = NULL)
str_c(..., sep = "", collapse = NULL)
... |
One or more character vectors. Zero length arguments are removed. Short arguments are recycled to the length of the longest. Like most other R functions, missing values are "infectious":
whenever a missing value is combined with another string
the result will always be missing.
Use |
sep |
String to insert between input vectors. |
collapse |
Optional string used to combine input vectors into single string. |
If collapse = NULL
(the default) a character vector
with length equal to the longest input string.
If collapse is non-NULL
, a character vector of length 1.
Adapted from the stringr package.
Dependency-free drop-in alternative for stringr::str_count()
.
str_count(string, pattern = "")
str_count(string, pattern = "")
string |
Input vector. Either a character vector, or something coercible to one. |
pattern |
Pattern to look for. The default interpretation is a regular expression,
as described in base::regex.
Control options with Match a fixed string (i.e. by comparing only bytes), using |
An integer vector.
Adapted from the stringr package.
Dependency-free drop-in alternative for stringr::str_detect()
.
str_detect(string, pattern, negate = FALSE)
str_detect(string, pattern, negate = FALSE)
string |
Input vector. Either a character vector, or something coercible to one. |
pattern |
Pattern to look for. The default interpretation is a regular expression,
as described in base::regex.
Control options with Match a fixed string (i.e. by comparing only bytes), using |
negate |
If |
A logical vector.
Adapted from the stringr package.
Dependency-free drop-in alternative for stringr::str_dup()
.
str_dup(string, times)
str_dup(string, times)
string |
Input character vector. |
times |
Number of times to duplicate each string. |
A character vector.
Adapted from the stringr package.
Dependency-free drop-in alternative for stringr::str_ends()
.
str_ends(string, pattern, negate = FALSE)
str_ends(string, pattern, negate = FALSE)
string |
Input vector. Either a character vector, or something coercible to one. |
pattern |
Pattern to look for. The default interpretation is a regular expression,
as described in base::regex.
Control options with Match a fixed string (i.e. by comparing only bytes), using |
negate |
If |
A logical vector.
Adapted from the stringr package.
Dependency-free drop-in alternative for stringr::str_extract()
.
str_extract(string, pattern)
str_extract(string, pattern)
string |
Input vector. Either a character vector, or something coercible to one. |
pattern |
Pattern to look for. The default interpretation is a regular expression,
as described in base::regex.
Control options with Match a fixed string (i.e. by comparing only bytes), using |
A character matrix. The first column is the complete match, followed by one column for each capture group.
Adapted from the stringr package.
Dependency-free drop-in alternative for stringr::str_extract_all()
.
str_extract_all(string, pattern, simplify = FALSE)
str_extract_all(string, pattern, simplify = FALSE)
string |
Input vector. Either a character vector, or something coercible to one. |
pattern |
Pattern to look for. The default interpretation is a regular expression,
as described in base::regex.
Control options with Match a fixed string (i.e. by comparing only bytes), using |
simplify |
If |
A list of character vectors if simplify = FALSE
,
or a character matrix if simplify = TRUE
.
Adapted from the stringr package.
Dependency-free drop-in alternative for stringr::str_length()
.
str_length(string)
str_length(string)
string |
Input vector. Either a character vector, or something coercible to one. |
A numeric vector the same length as string.
Adapted from the stringr package.
Dependency-free drop-in alternative for stringr::str_match()
.
str_match(string, pattern)
str_match(string, pattern)
string |
Input vector. Either a character vector, or something coercible to one. |
pattern |
Pattern to look for. The default interpretation is a regular expression,
as described in base::regex.
Control options with Match a fixed string (i.e. by comparing only bytes), using |
A character matrix. The first column is the complete match, followed by one column for each capture group.
Adapted from the stringr package.
Dependency-free drop-in alternative for stringr::str_pad()
.
str_pad( string, width, side = c("left", "right", "both"), pad = " ", use_width = TRUE )
str_pad( string, width, side = c("left", "right", "both"), pad = " ", use_width = TRUE )
string |
Input vector. Either a character vector, or something coercible to one. |
width |
Minimum width of padded strings. |
side |
Side on which padding character is added (left, right or both). |
pad |
Single padding character (default is a space). |
use_width |
If |
A character vector.
Eli Pousson [email protected] (ORCID)
Alexander Rossell Hayes [email protected] (ORCID)
Adapted from the stringr package.
Dependency-free drop-in alternative for stringr::str_remove()
.
str_remove(string, pattern)
str_remove(string, pattern)
string |
Input vector. Either a character vector, or something coercible to one. |
pattern |
Pattern to look for. The default interpretation is a regular expression,
as described in base::regex.
Control options with Match a fixed string (i.e. by comparing only bytes), using |
A character vector.
Adapted from the stringr package.
Dependency-free drop-in alternative for stringr::str_remove_all()
.
str_remove_all(string, pattern)
str_remove_all(string, pattern)
string |
Input vector. Either a character vector, or something coercible to one. |
pattern |
Pattern to look for. The default interpretation is a regular expression,
as described in base::regex.
Control options with Match a fixed string (i.e. by comparing only bytes), using |
A character vector.
Adapted from the stringr package.
Dependency-free drop-in alternative for stringr::str_replace()
.
str_replace(string, pattern, replacement)
str_replace(string, pattern, replacement)
string |
Input vector. Either a character vector, or something coercible to one. |
pattern |
Pattern to look for. The default interpretation is a regular expression,
as described in base::regex.
Control options with Match a fixed string (i.e. by comparing only bytes), using |
replacement |
A character vector of replacements.
Should be either length one, or the same length as To replace the complete string with Using a function for |
A character vector.
Adapted from the stringr package.
Dependency-free drop-in alternative for stringr::str_replace_all()
.
str_replace_all(string, pattern, replacement)
str_replace_all(string, pattern, replacement)
string |
Input vector. Either a character vector, or something coercible to one. |
pattern |
Pattern to look for. The default interpretation is a regular expression,
as described in base::regex.
Control options with Match a fixed string (i.e. by comparing only bytes), using |
replacement |
A character vector of replacements.
Should be either length one, or the same length as To perform multiple replacements in each element of To replace the complete string with Using a function for |
A character vector.
Adapted from the stringr package.
Dependency-free drop-in alternative for stringr::str_replace_na()
.
str_replace_na(string, replacement = "NA")
str_replace_na(string, replacement = "NA")
string |
Input vector. Either a character vector, or something coercible to one. |
replacement |
A single string. |
A character vector.
Dependency-free drop-in alternative for stringr::str_split()
.
str_split(string, pattern, n = Inf, simplify = FALSE)
str_split(string, pattern, n = Inf, simplify = FALSE)
string |
Input vector. Either a character vector, or something coercible to one. |
pattern |
Pattern to look for. The default interpretation is a regular expression,
as described in base::regex.
Control options with Match a fixed string (i.e. by comparing only bytes), using |
n |
Maximum number of pieces to return.
Default ( |
simplify |
A boolean.
|
A list the same length as string
/pattern
containing character vectors,
or if simplify = FALSE
, a character matrix with n columns and
the same number of rows as the length of string
/pattern
.
Eli Pousson [email protected] (ORCID)
Alexander Rossell Hayes [email protected] (ORCID)
Adapted from the stringr package.
Dependency-free drop-in alternative for stringr::str_split_fixed()
.
str_split_fixed(string, pattern, n)
str_split_fixed(string, pattern, n)
string |
Input vector. Either a character vector, or something coercible to one. |
pattern |
Pattern to look for. The default interpretation is a regular expression,
as described in base::regex.
Control options with Match a fixed string (i.e. by comparing only bytes), using |
n |
Maximum number of pieces to return.
This determines the number of columns in the output;
if an input is too short, the result will be padded with |
A character matrix with n
columns and
the same number of rows as the length of string
/pattern
.
Eli Pousson [email protected] (ORCID)
Alexander Rossell Hayes [email protected] (ORCID)
Adapted from the stringr package.
Dependency-free drop-in alternative for stringr::str_squish()
.
str_squish(string)
str_squish(string)
string |
Input vector. Either a character vector, or something coercible to one. |
A character vector the same length as string
.
Adapted from the stringr package.
Dependency-free drop-in alternative for stringr::str_starts()
.
str_starts(string, pattern, negate = FALSE)
str_starts(string, pattern, negate = FALSE)
string |
Input vector. Either a character vector, or something coercible to one. |
pattern |
Pattern to look for. The default interpretation is a regular expression,
as described in base::regex.
Control options with Match a fixed string (i.e. by comparing only bytes), using |
negate |
If |
A logical vector.
Dependency-free drop-in alternative for stringr::str_subset()
.
str_subset(string, pattern, negate = FALSE)
str_subset(string, pattern, negate = FALSE)
string |
Input vector. Either a character vector, or something coercible to one. |
pattern |
Pattern to look for. The default interpretation is a regular expression,
as described in base::regex.
Control options with Match a fixed string (i.e. by comparing only bytes), using |
negate |
If |
A character vector.
Adapted from the stringr package.
Dependency-free drop-in alternative for stringr::str_trim()
.
str_trim(string, side = c("both", "left", "right"))
str_trim(string, side = c("both", "left", "right"))
string |
Input vector. Either a character vector, or something coercible to one. |
side |
Side on which to remove whitespace:
|
A character vector the same length as string
.
Adapted from the stringr package.
Dependency-free drop-in alternative for stringr::str_which()
.
str_which(string, pattern, negate = FALSE)
str_which(string, pattern, negate = FALSE)
string |
Input vector. Either a character vector, or something coercible to one. |
pattern |
Pattern to look for. The default interpretation is a regular expression,
as described in base::regex.
Control options with Match a fixed string (i.e. by comparing only bytes), using |
negate |
If |
An integer vector.
Adapted from the stringr package.
Dependency-free drop-in alternative for stringr::str_width()
.
Results for non-ASCII characters may be inaccurate in R < 4.0.
str_width(string)
str_width(string)
string |
Input vector. Either a character vector, or something coercible to one. |
A numeric vector the same length as string.
Adapted from the stringr package.