diff --git a/NEWS.md b/NEWS.md index 158b0a1b..04c107ae 100644 --- a/NEWS.md +++ b/NEWS.md @@ -85,7 +85,7 @@ * New `str_split_1()` is tailored for the special case of splitting up a single string (#409). -* New `str_split_i()` extract a single piece from a string (#278, @bfgray3). +* New `str_split_i()` extracts a single piece from a string (#278, @bfgray3). * New `str_like()` allows the use of SQL wildcards (#280, @rjpat). @@ -103,7 +103,7 @@ * It no longer requires a pattern so you can use it to display strings with special characters. * It highlights unusual whitespace characters. - * It's vectorised over both string` and `pattern` (#407). + * It's vectorised over both `string` and `pattern` (#407). * It defaults to displaying all matches, making `str_view_all()` redundant (and hence deprecated) (#455). @@ -117,10 +117,10 @@ * A new data source for `sentences` has fixed many small errors. -* `str_extract()` and `str_exctract_all()` now work correctly when `pattern` +* `str_extract()` and `str_extract_all()` now work correctly when `pattern` is a `boundary()`. -* `str_flatten()` gains a `last` argument that optionally override the +* `str_flatten()` gains a `last` argument that optionally overrides the final separator (#377). It gains a `na.rm` argument to remove missing values (since it's a summary function) (#439). @@ -137,7 +137,7 @@ `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) + that is greater than or equal to the number of words. (@pdelboca, #245) # stringr 1.4.1 @@ -145,7 +145,7 @@ Hot patch release to resolve R CMD check failures. # stringr 1.4.0 -* `str_interp()` now renders lists consistently independent on the presence of +* `str_interp()` now renders lists consistently independently of the presence of additional placeholders (@amhrasmussen). * New `str_starts()` and `str_ends()` functions to detect patterns at the @@ -191,7 +191,7 @@ Hot patch release to resolve R CMD check failures. (@Shians, #178) * `str_squish()` removes spaces from both the left and right side of strings, - and also converts multiple space (or space-like characters) to a single + and also converts multiple spaces (or space-like characters) to a single space within strings (@stephlocke, #197). * `str_sub()` gains `omit_na` argument for ignoring `NA`. Accordingly, @@ -235,7 +235,7 @@ Hot patch release to resolve R CMD check failures. * `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). + 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 @@ -280,7 +280,7 @@ Hot patch release to resolve R CMD check failures. 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 +* stringr gains a vignette, currently a straightforward update of the article that appeared in the R Journal. * `str_c()` now returns a zero length vector if any of its inputs are @@ -323,7 +323,7 @@ Hot patch release to resolve R CMD check failures. # stringr 0.6.2 -* fixed path in `str_wrap` example so works for more R installations. +* fixed path in `str_wrap` example so it works for more R installations. * remove dependency on plyr @@ -345,7 +345,7 @@ Hot patch release to resolve R CMD check failures. * new `str_wrap` function which gives `strwrap` output in a more convenient format -* new `word` function extract words from a string given user defined +* new `word` function extracts 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 diff --git a/R/c.R b/R/c.R index 332f1fbc..b946fffa 100644 --- a/R/c.R +++ b/R/c.R @@ -5,7 +5,7 @@ #' vector. It's very similar to [paste0()] but uses tidyverse recycling and #' `NA` rules. #' -#' One way to understand how `str_c()` works is picture a 2d matrix of strings, +#' One way to understand how `str_c()` works is to picture a 2d matrix of strings, #' where each argument forms a column. `sep` is inserted between each column, #' and then each row is combined together into a single string. If `collapse` #' is set, it's inserted between each row, and then the result is again @@ -21,8 +21,8 @@ #' be missing. Use [dplyr::coalesce()] or [str_replace_na()] to convert to #' the desired value. #' @param sep String to insert between input vectors. -#' @param collapse Optional string used to combine output into single -#' string. Generally better to use [str_flatten()] if you needed this +#' @param collapse Optional string used to combine output into a single +#' string. Generally better to use [str_flatten()] if you need this #' behaviour. #' @return If `collapse = NULL` (the default) a character vector with #' length equal to the longest input. If `collapse` is a string, a character @@ -41,7 +41,7 @@ #' # Missing inputs give missing outputs #' str_c(c("a", NA, "b"), "-d") #' paste0(c("a", NA, "b"), "-d") -#' # Use str_replace_NA to display literal NAs: +#' # Use str_replace_na to display literal NAs: #' str_c(str_replace_na(c("a", NA, "b")), "-d") #' #' # Uses tidyverse recycling rules diff --git a/R/case.R b/R/case.R index c20dc8e4..f5027a0a 100644 --- a/R/case.R +++ b/R/case.R @@ -4,8 +4,8 @@ #' * `str_to_lower()` converts to lower case. #' * `str_to_title()` converts to title case, where only the first letter of #' each word is capitalized. -#' * `str_to_sentence()` convert to sentence case, where only the first letter -#' of sentence is capitalized. +#' * `str_to_sentence()` converts to sentence case, where only the first letter +#' of each sentence is capitalized. #' #' @inheritParams str_detect #' @inheritParams coll @@ -121,7 +121,7 @@ to_words <- function(string) { "(?<=\\p{L})(?=\\p{N})", # number followed by letter "(?<=\\p{N})(?=\\p{L})", - # uppercase followed uppercase then lowercase (i.e. end of acronym) + # uppercase followed by uppercase then lowercase (i.e. end of acronym) "(?<=\\p{Lu})(?=\\p{Lu}\\p{Ll})", sep = "|" ) diff --git a/R/count.R b/R/count.R index b193decb..aea60119 100644 --- a/R/count.R +++ b/R/count.R @@ -1,7 +1,7 @@ #' Count number of matches #' #' Counts the number of times `pattern` is found within each element -#' of `string.` +#' of `string`. #' #' @inheritParams str_detect #' @param pattern Pattern to look for. @@ -21,8 +21,8 @@ #' @return An integer vector the same length as `string`/`pattern`. #' @seealso [stringi::stri_count()] which this function wraps. #' -#' [str_locate()]/[str_locate_all()] to locate position -#' of matches +#' [str_locate()]/[str_locate_all()] to locate the position +#' of matches. #' #' @export #' @examples diff --git a/R/data.R b/R/data.R index 9f1f6786..013f1a13 100644 --- a/R/data.R +++ b/R/data.R @@ -4,7 +4,7 @@ #' written by Gabor Csardi; the data was collected by Darius Kazemi #' and made available at \url{https://github.com/dariusk/corpora}. #' `sentences` is a collection of "Harvard sentences" used for -#' standardised testing of voice. +#' standardized testing of voice. #' #' @format Character vectors. #' @name stringr-data diff --git a/R/detect.R b/R/detect.R index 1510eb63..b133a974 100644 --- a/R/detect.R +++ b/R/detect.R @@ -17,7 +17,7 @@ #' for matching human text, you'll want [coll()] which #' respects character matching rules for the specified locale. #' -#' You can not match boundaries, including `""`, with this function. +#' You cannot match boundaries, including `""`, with this function. #' #' @param negate If `TRUE`, inverts the resulting boolean vector. #' @return A logical vector the same length as `string`/`pattern`. @@ -36,7 +36,7 @@ #' # Also vectorised over pattern #' str_detect("aecfg", letters) #' -#' # Returns TRUE if the pattern do NOT match +#' # Returns TRUE if the pattern does NOT match #' str_detect(fruit, "^p", negate = TRUE) str_detect <- function(string, pattern, negate = FALSE) { check_lengths(string, pattern) diff --git a/R/equal.R b/R/equal.R index a8393ed0..79024b96 100644 --- a/R/equal.R +++ b/R/equal.R @@ -1,11 +1,11 @@ #' Determine if two strings are equivalent #' -#' This uses Unicode canonicalisation rules, and optionally ignores case. +#' This uses Unicode canonicalization rules, and optionally ignores case. #' #' @param x,y A pair of character vectors. #' @inheritParams str_order #' @param ignore_case Ignore case when comparing strings? -#' @return An logical vector the same length as `x`/`y`. +#' @return A logical vector the same length as `x`/`y`. #' @seealso [stringi::stri_cmp_equiv()] for the underlying implementation. #' @export #' @examples diff --git a/R/escape.R b/R/escape.R index ed409330..431f39cb 100644 --- a/R/escape.R +++ b/R/escape.R @@ -1,9 +1,9 @@ #' Escape regular expression metacharacters #' -#' This function escapes metacharacter, the characters that have special +#' This function escapes metacharacters, the characters that have special #' meaning to the regular expression engine. In most cases you are better #' off using [fixed()] since it is faster, but `str_escape()` is useful -#' if you are composing user provided strings into a pattern. +#' if you are composing user-provided strings into a pattern. #' #' @inheritParams str_detect #' @return A character vector the same length as `string`. diff --git a/R/flatten.R b/R/flatten.R index d9094b8b..0bad5b40 100644 --- a/R/flatten.R +++ b/R/flatten.R @@ -1,12 +1,12 @@ #' Flatten a string -# +#' #' @description #' `str_flatten()` reduces a character vector to a single string. This is a #' summary function because regardless of the length of the input `x`, it #' always returns a single string. #' #' `str_flatten_comma()` is a variation designed specifically for flattening -#' with commas. It automatically recognises if `last` uses the Oxford comma +#' with commas. It automatically recognizes if `last` uses the Oxford comma #' and handles the special case of 2 elements. #' #' @inheritParams str_detect diff --git a/R/glue.R b/R/glue.R index e4bf6111..1dd64d86 100644 --- a/R/glue.R +++ b/R/glue.R @@ -9,7 +9,7 @@ #' `glue_data()` directly from glue for more control. #' #' @inheritParams glue::glue -#' @return A character vector with same length as the longest input. +#' @return A character vector with the same length as the longest input. #' @export #' @examples #' name <- "Fred" @@ -24,7 +24,7 @@ #' # single braces can be inserted by doubling them #' str_glue("My name is {name}, not {{name}}.") #' -#' # You can also used named arguments +#' # You can also use named arguments #' str_glue( #' "My name is {name}, ", #' "and my age next year is {age + 1}.", diff --git a/R/interp.R b/R/interp.R index 0d9fb30e..13e0c0a0 100644 --- a/R/interp.R +++ b/R/interp.R @@ -72,9 +72,9 @@ str_interp <- function(string, env = parent.frame()) { } } -#' Match String Interpolation Placeholders +#' Match string interpolation placeholders #' -#' Given a character string a set of expression placeholders are matched. They +#' Given a character string, a set of expression placeholders is matched. They #' are of the form \code{${...}} or optionally \code{$[f]{...}} where `f` #' is a valid format for [sprintf()]. #' @@ -117,8 +117,6 @@ interp_placeholders <- function(string, error_call = caller_env()) { # Identify the positions within the parts of the matching closing braces. # These are the lengths of the placeholder matches. lengths <- mapply(match_brace, opens, closes) - - # Update the `starts` match data with the attr(starts, "match.length") <- lengths # Return both the indices (regex match data) and the actual placeholder @@ -129,7 +127,7 @@ interp_placeholders <- function(string, error_call = caller_env()) { ) } -#' Evaluate String Interpolation Matches +#' Evaluate string interpolation matches #' #' The expression part of string interpolation matches are evaluated in a #' specified environment and formatted for replacement in the original string. @@ -162,7 +160,7 @@ eval_interp_matches <- function(matches, env, error_call = caller_env()) { mapply(sprintf, formats, values, SIMPLIFY = FALSE) } -#' Extract Expression Objects from String Interpolation Matches +#' Extract expression objects from string interpolation matches #' #' An interpolation match object will contain both its wrapping \code{${ }} part #' and possibly a format. This extracts the expression parts and parses them to @@ -198,11 +196,11 @@ extract_expressions <- function(matches, error_call = caller_env()) { } -#' Extract String Interpolation Formats from Matched Placeholders +#' Extract string interpolation formats from matched placeholders #' #' An expression placeholder for string interpolation may optionally contain a -#' format valid for [sprintf()]. This function will extract such or -#' default to "s" the format for strings. +#' format valid for [sprintf()]. This function extracts such formats, or +#' defaults to `"s"`, the format for strings. #' #' @param matches Match data #' @@ -218,7 +216,7 @@ extract_formats <- function(matches) { paste0("%", ifelse(formats == "", "s", formats)) } -#' Utility Function for Matching a Closing Brace +#' Utility function for matching a closing brace #' #' Given positions of opening and closing braces `match_brace` identifies #' the closing brace matching the first opening brace. @@ -227,7 +225,7 @@ extract_formats <- function(matches) { #' #' @param closing integer: Vector with positions of closing braces. #' -#' @return Integer with the posision of the matching brace. +#' @return Integer with the position of the matching brace. #' #' @noRd #' @author Stefan Milton Bache @@ -235,7 +233,7 @@ match_brace <- function(opening, closing) { # maximum index for the matching closing brace max_close <- max(closing) - # "path" for mapping opening and closing breaces + # "path" for mapping opening and closing braces path <- numeric(max_close) # Set openings to 1, and closings to -1 diff --git a/R/locate.R b/R/locate.R index 4e55e357..c7a5f989 100644 --- a/R/locate.R +++ b/R/locate.R @@ -14,7 +14,7 @@ #' gives the position at the start of the match, and the second column, `end`, #' gives the position of the end. #' -#'* `str_locate_all()` returns a list of integer matrices with the same +#' * `str_locate_all()` returns a list of integer matrices with the same #' length as `string`/`pattern`. The matrices have columns `start` and `end` #' as above, and one row for each match. #' @seealso @@ -99,7 +99,7 @@ str_locate_all <- function(string, pattern) { #' previously matched. #' #' @param loc matrix of match locations, as from [str_locate_all()] -#' @return numeric match giving locations of non-matches +#' @return numeric matrix giving locations of non-matches #' @export #' @examples #' numbers <- "1 and 2 and 4 and 456" diff --git a/R/match.R b/R/match.R index 32123fef..0ea01b19 100644 --- a/R/match.R +++ b/R/match.R @@ -5,17 +5,17 @@ #' named, `(?pattern)` capture groups. #' #' Use a non-capturing group, `(?:pattern)`, if you need to override default -#' operate precedence but don't want to capture the result. +#' operator precedence but don't want to capture the result. #' #' @inheritParams str_detect #' @param pattern Unlike other stringr functions, `str_match()` only supports -#' regular expressions, as described `vignette("regular-expressions")`. +#' regular expressions, as described in `vignette("regular-expressions")`. #' The pattern should contain at least one capturing group. #' @return #' * `str_match()`: a character matrix with the same number of rows as the #' length of `string`/`pattern`. The first column is the complete match, #' followed by one column for each capture group. The columns will be named -#' if you used "named captured groups", i.e. `(?pattern')`. +#' if you used "named capture groups", i.e. `(?pattern)`. #' #' * `str_match_all()`: a list of the same length as `string`/`pattern` #' containing character matrices. Each matrix has columns as described above diff --git a/R/ord.R b/R/ord.R new file mode 100644 index 00000000..e69de29b diff --git a/R/pad.R b/R/pad.R index c3a07835..d018a677 100644 --- a/R/pad.R +++ b/R/pad.R @@ -9,7 +9,7 @@ #' @param pad Single padding character (default is a space). #' @param use_width If `FALSE`, use the length of the string instead of the #' width; see [str_width()]/[str_length()] for the difference. -#' @return A character vector the same length as `stringr`/`width`/`pad`. +#' @return A character vector the same length as `string`/`width`/`pad`. #' @seealso [str_trim()] to remove whitespace; #' [str_trunc()] to decrease the maximum width of a string. #' @export diff --git a/R/rap.R b/R/rap.R new file mode 100644 index 00000000..e69de29b diff --git a/R/replace.R b/R/replace.R index 059e31c6..9ae01a59 100644 --- a/R/replace.R +++ b/R/replace.R @@ -19,9 +19,9 @@ #' for matching human text, you'll want [coll()] which #' respects character matching rules for the specified locale. #' -#' You can not match boundaries, including `""`, with this function. +#' You cannot match boundaries, including `""`, with this function. #' @param replacement The replacement value, usually a single string, -#' but it can be the a vector the same length as `string` or `pattern`. +#' but it can be a vector the same length as `string` or `pattern`. #' References of the form `\1`, `\2`, etc will be replaced with #' the contents of the respective matched group (created by `()`). #' diff --git a/R/sort.R b/R/sort.R index a6a5f232..59fc12f9 100644 --- a/R/sort.R +++ b/R/sort.R @@ -1,9 +1,9 @@ #' Order, rank, or sort a character vector #' #' * `str_sort()` returns the sorted vector. -#' * `str_order()` returns an integer vector that returns the desired +#' * `str_order()` returns an integer vector that gives the desired #' order when used for subsetting, i.e. `x[str_order(x)]` is the same -#' as `str_sort()` +#' as `str_sort()`. #' * `str_rank()` returns the ranks of the values, i.e. #' `arrange(df, str_rank(x))` is the same as `str_sort(df$x)`. #' @@ -17,7 +17,7 @@ #' @param ... Other options used to control collation. Passed on to #' [stringi::stri_opts_collator()]. #' @inheritParams coll -#' @return A character vector the same length as `string`. +#' @return A character vector the same length as `x`. #' @seealso [stringi::stri_order()] for the underlying implementation. #' @export #' @examples diff --git a/R/split.R b/R/split.R index dfccbe41..0c3d52bb 100644 --- a/R/split.R +++ b/R/split.R @@ -48,7 +48,7 @@ #' # Specify n to restrict the number of possible matches #' str_split(fruits, " and ", n = 3) #' str_split(fruits, " and ", n = 2) -#' # If n greater than number of pieces, no padding occurs +#' # If n is greater than the number of pieces, no padding occurs #' str_split(fruits, " and ", n = 5) #' #' # Use fixed to return a character matrix diff --git a/R/sub.R b/R/sub.R index 60897594..73bf20f9 100644 --- a/R/sub.R +++ b/R/sub.R @@ -1,8 +1,8 @@ #' Get and set substrings using their positions #' #' `str_sub()` extracts or replaces the elements at a single position in each -#' string. `str_sub_all()` allows you to extract strings at multiple elements -#' in every string. +#' string. `str_sub_all()` allows you to extract substrings at multiple +#' positions in every string. #' #' @inheritParams str_detect #' @param start,end A pair of integer vectors defining the range of characters diff --git a/R/trunc.R b/R/trunc.R index 46bab09b..c7b35e2d 100644 --- a/R/trunc.R +++ b/R/trunc.R @@ -1,6 +1,6 @@ #' Truncate a string to maximum width #' -#' Truncate a string to a fixed of characters, so that +#' Truncate a string to a fixed number of characters, so that #' `str_length(str_trunc(x, n))` is always less than or equal to `n`. #' #' @inheritParams str_detect diff --git a/R/view.R b/R/view.R index e31a65c0..abcda91e 100644 --- a/R/view.R +++ b/R/view.R @@ -5,7 +5,7 @@ #' to see how a `pattern` matches. #' #' Matches are surrounded by `<>` and unusual whitespace (i.e. all whitespace -#' apart from `" "` and `"\n"`) are surrounded by `{}` and escaped. Where +#' apart from `" "` and `"\n"`) is surrounded by `{}` and escaped. Where #' possible, matches and unusual whitespace are coloured blue and `NA`s red. #' #' @inheritParams str_detect @@ -124,7 +124,7 @@ str_view_highlighter <- function(html = TRUE) { function(x) { out <- cli::col_cyan("<", x, ">") - # Ensure styling is starts and ends within each line + # Ensure styling starts and ends within each line out <- cli::ansi_strsplit(out, "\n", fixed = TRUE) out <- map_chr(out, str_flatten, "\n") diff --git a/R/word.R b/R/word.R index 49421154..0b286b05 100644 --- a/R/word.R +++ b/R/word.R @@ -1,10 +1,10 @@ #' Extract words from a sentence #' #' @inheritParams str_detect -#' @param start,end Pair of integer vectors giving range of words (inclusive) +#' @param start,end Pair of integer vectors giving the range of words (inclusive) #' to extract. If negative, counts backwards from the last word. #' -#' The default value select the first word. +#' The default value selects the first word. #' @param sep Separator between words. Defaults to single space. #' @return A character vector with the same length as `string`/`start`/`end`. #' @export diff --git a/R/wrap.R b/R/wrap.R index 0c65be7b..3a26544b 100644 --- a/R/wrap.R +++ b/R/wrap.R @@ -1,7 +1,7 @@ #' Wrap words into nicely formatted paragraphs #' #' Wrap words into paragraphs, minimizing the "raggedness" of the lines -#' (i.e. the variation in length line) using the Knuth-Plass algorithm. +#' (i.e. the variation in line length) using the Knuth-Plass algorithm. #' #' @inheritParams str_detect #' @param width Positive integer giving target line width (in number of diff --git a/README.Rmd b/README.Rmd index 0b2e5021..cbde89b5 100644 --- a/README.Rmd +++ b/README.Rmd @@ -109,7 +109,7 @@ As well as regular expressions (the default), there are three other pattern matc * `coll()`: match human letters * `boundary()`: match boundaries -## RStudio Addin +## RStudio addin The [RegExplain RStudio addin](https://www.garrickadenbuie.com/project/regexplain/) provides a friendly interface for working with regular expressions and functions from stringr. This addin allows you to interactively build your regexp, check the output of common string matching functions, consult the interactive help pages, or use the included resources to learn regular expressions. @@ -138,7 +138,7 @@ R provides a solid set of string operations, but because they have grown organic * 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 +* Produces outputs that 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. diff --git a/README.md b/README.md index 42bf59d6..fb3c76ee 100644 --- a/README.md +++ b/README.md @@ -158,7 +158,7 @@ pattern matching engines: - `coll()`: match human letters - `boundary()`: match boundaries -## RStudio Addin +## RStudio addin The [RegExplain RStudio addin](https://www.garrickadenbuie.com/project/regexplain/) provides a @@ -198,7 +198,7 @@ languages like Ruby or Python are rather hard to do in R. - 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 +- Produces outputs that 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. diff --git a/cran-comments.md b/cran-comments.md index 23ccf356..c3caecd5 100644 --- a/cran-comments.md +++ b/cran-comments.md @@ -1,6 +1,6 @@ ## R CMD check results -0 errors | 0 warnings | 0 note +0 errors | 0 warnings | 0 notes ## revdepcheck results diff --git a/man/case.Rd b/man/case.Rd index b557e192..8f39eb92 100644 --- a/man/case.Rd +++ b/man/case.Rd @@ -34,8 +34,8 @@ A character vector the same length as \code{string}. \item \code{str_to_lower()} converts to lower case. \item \code{str_to_title()} converts to title case, where only the first letter of each word is capitalized. -\item \code{str_to_sentence()} convert to sentence case, where only the first letter -of sentence is capitalized. +\item \code{str_to_sentence()} converts to sentence case, where only the first letter +of each sentence is capitalized. } } \examples{ diff --git a/man/invert_match.Rd b/man/invert_match.Rd index dd3360ec..a6708403 100644 --- a/man/invert_match.Rd +++ b/man/invert_match.Rd @@ -10,7 +10,7 @@ invert_match(loc) \item{loc}{matrix of match locations, as from \code{\link[=str_locate_all]{str_locate_all()}}} } \value{ -numeric match giving locations of non-matches +numeric matrix giving locations of non-matches } \description{ Invert a matrix of match locations to match the opposite of what was diff --git a/man/str_c.Rd b/man/str_c.Rd index 24568746..388a3014 100644 --- a/man/str_c.Rd +++ b/man/str_c.Rd @@ -19,8 +19,8 @@ the desired value.} \item{sep}{String to insert between input vectors.} -\item{collapse}{Optional string used to combine output into single -string. Generally better to use \code{\link[=str_flatten]{str_flatten()}} if you needed this +\item{collapse}{Optional string used to combine output into a single +string. Generally better to use \code{\link[=str_flatten]{str_flatten()}} if you need this behaviour.} } \value{ @@ -33,7 +33,7 @@ vector of length 1. vector. It's very similar to \code{\link[=paste0]{paste0()}} but uses tidyverse recycling and \code{NA} rules. -One way to understand how \code{str_c()} works is picture a 2d matrix of strings, +One way to understand how \code{str_c()} works is to picture a 2d matrix of strings, where each argument forms a column. \code{sep} is inserted between each column, and then each row is combined together into a single string. If \code{collapse} is set, it's inserted between each row, and then the result is again @@ -52,7 +52,7 @@ str_c(letters, collapse = ", ") # Missing inputs give missing outputs str_c(c("a", NA, "b"), "-d") paste0(c("a", NA, "b"), "-d") -# Use str_replace_NA to display literal NAs: +# Use str_replace_na to display literal NAs: str_c(str_replace_na(c("a", NA, "b")), "-d") # Uses tidyverse recycling rules diff --git a/man/str_count.Rd b/man/str_count.Rd index 3b83028d..2f9edbc3 100644 --- a/man/str_count.Rd +++ b/man/str_count.Rd @@ -30,7 +30,7 @@ An integer vector the same length as \code{string}/\code{pattern}. } \description{ Counts the number of times \code{pattern} is found within each element -of \code{string.} +of \code{string}. } \examples{ fruit <- c("apple", "banana", "pear", "pineapple") @@ -45,6 +45,6 @@ str_count(c("a.", "...", ".a.a"), fixed(".")) \seealso{ \code{\link[stringi:stri_count]{stringi::stri_count()}} which this function wraps. -\code{\link[=str_locate]{str_locate()}}/\code{\link[=str_locate_all]{str_locate_all()}} to locate position -of matches +\code{\link[=str_locate]{str_locate()}}/\code{\link[=str_locate_all]{str_locate_all()}} to locate the position +of matches. } diff --git a/man/str_detect.Rd b/man/str_detect.Rd index 27c7a2f3..23ff8f8c 100644 --- a/man/str_detect.Rd +++ b/man/str_detect.Rd @@ -21,7 +21,7 @@ Match a fixed string (i.e. by comparing only bytes), using for matching human text, you'll want \code{\link[=coll]{coll()}} which respects character matching rules for the specified locale. -You can not match boundaries, including \code{""}, with this function.} +You cannot match boundaries, including \code{""}, with this function.} \item{negate}{If \code{TRUE}, inverts the resulting boolean vector.} } @@ -44,7 +44,7 @@ str_detect(fruit, "[aeiou]") # Also vectorised over pattern str_detect("aecfg", letters) -# Returns TRUE if the pattern do NOT match +# Returns TRUE if the pattern does NOT match str_detect(fruit, "^p", negate = TRUE) } \seealso{ diff --git a/man/str_equal.Rd b/man/str_equal.Rd index d92f9bf0..1236b29e 100644 --- a/man/str_equal.Rd +++ b/man/str_equal.Rd @@ -20,10 +20,10 @@ consistent across platforms.} \code{\link[stringi:stri_opts_collator]{stringi::stri_opts_collator()}}.} } \value{ -An logical vector the same length as \code{x}/\code{y}. +A logical vector the same length as \code{x}/\code{y}. } \description{ -This uses Unicode canonicalisation rules, and optionally ignores case. +This uses Unicode canonicalization rules, and optionally ignores case. } \examples{ # These two strings encode "a" with an accent in two different ways diff --git a/man/str_escape.Rd b/man/str_escape.Rd index 2a7b85ac..c9379c97 100644 --- a/man/str_escape.Rd +++ b/man/str_escape.Rd @@ -14,10 +14,10 @@ coercible to one.} A character vector the same length as \code{string}. } \description{ -This function escapes metacharacter, the characters that have special +This function escapes metacharacters, the characters that have special meaning to the regular expression engine. In most cases you are better off using \code{\link[=fixed]{fixed()}} since it is faster, but \code{str_escape()} is useful -if you are composing user provided strings into a pattern. +if you are composing user-provided strings into a pattern. } \examples{ str_detect(c("a", "."), ".") diff --git a/man/str_flatten.Rd b/man/str_flatten.Rd index 497021a5..16f95cd8 100644 --- a/man/str_flatten.Rd +++ b/man/str_flatten.Rd @@ -29,7 +29,7 @@ summary function because regardless of the length of the input \code{x}, it always returns a single string. \code{str_flatten_comma()} is a variation designed specifically for flattening -with commas. It automatically recognises if \code{last} uses the Oxford comma +with commas. It automatically recognizes if \code{last} uses the Oxford comma and handles the special case of 2 elements. } \examples{ diff --git a/man/str_glue.Rd b/man/str_glue.Rd index 23cc428f..fefc8ec1 100644 --- a/man/str_glue.Rd +++ b/man/str_glue.Rd @@ -32,7 +32,7 @@ with. If \code{NULL} missing values are propagated, that is an \code{NA} result cause \code{NA} output. Otherwise the value is replaced by the value of \code{.na}.} } \value{ -A character vector with same length as the longest input. +A character vector with the same length as the longest input. } \description{ These functions are wrappers around \code{\link[glue:glue]{glue::glue()}} and \code{\link[glue:glue_data]{glue::glue_data()}}, @@ -55,7 +55,7 @@ str_glue( # single braces can be inserted by doubling them str_glue("My name is {name}, not {{name}}.") -# You can also used named arguments +# You can also use named arguments str_glue( "My name is {name}, ", "and my age next year is {age + 1}.", diff --git a/man/str_match.Rd b/man/str_match.Rd index 35f1f0e6..e1530a81 100644 --- a/man/str_match.Rd +++ b/man/str_match.Rd @@ -14,7 +14,7 @@ str_match_all(string, pattern) coercible to one.} \item{pattern}{Unlike other stringr functions, \code{str_match()} only supports -regular expressions, as described \code{vignette("regular-expressions")}. +regular expressions, as described in \code{vignette("regular-expressions")}. The pattern should contain at least one capturing group.} } \value{ @@ -22,7 +22,7 @@ The pattern should contain at least one capturing group.} \item \code{str_match()}: a character matrix with the same number of rows as the length of \code{string}/\code{pattern}. The first column is the complete match, followed by one column for each capture group. The columns will be named -if you used "named captured groups", i.e. \verb{(?pattern')}. +if you used "named capture groups", i.e. \verb{(?pattern)}. \item \code{str_match_all()}: a list of the same length as \code{string}/\code{pattern} containing character matrices. Each matrix has columns as described above and one row for each match. @@ -33,7 +33,7 @@ Extract any number of matches defined by unnamed, \code{(pattern)}, and named, \verb{(?pattern)} capture groups. Use a non-capturing group, \verb{(?:pattern)}, if you need to override default -operate precedence but don't want to capture the result. +operator precedence but don't want to capture the result. } \examples{ strings <- c(" 219 733 8965", "329-293-8753 ", "banana", "595 794 7569", diff --git a/man/str_order.Rd b/man/str_order.Rd index b01c4767..a8139745 100644 --- a/man/str_order.Rd +++ b/man/str_order.Rd @@ -47,14 +47,14 @@ of as strings.} \code{\link[stringi:stri_opts_collator]{stringi::stri_opts_collator()}}.} } \value{ -A character vector the same length as \code{string}. +A character vector the same length as \code{x}. } \description{ \itemize{ \item \code{str_sort()} returns the sorted vector. -\item \code{str_order()} returns an integer vector that returns the desired +\item \code{str_order()} returns an integer vector that gives the desired order when used for subsetting, i.e. \code{x[str_order(x)]} is the same -as \code{str_sort()} +as \code{str_sort()}. \item \code{str_rank()} returns the ranks of the values, i.e. \code{arrange(df, str_rank(x))} is the same as \code{str_sort(df$x)}. } diff --git a/man/str_pad.Rd b/man/str_pad.Rd index 16464a9b..4d787a30 100644 --- a/man/str_pad.Rd +++ b/man/str_pad.Rd @@ -26,7 +26,7 @@ coercible to one.} width; see \code{\link[=str_width]{str_width()}}/\code{\link[=str_length]{str_length()}} for the difference.} } \value{ -A character vector the same length as \code{stringr}/\code{width}/\code{pad}. +A character vector the same length as \code{string}/\code{width}/\code{pad}. } \description{ Pad a string to a fixed width, so that diff --git a/man/str_remove.Rd b/man/str_remove.Rd index a5eceb25..83b82f37 100644 --- a/man/str_remove.Rd +++ b/man/str_remove.Rd @@ -24,7 +24,7 @@ Match a fixed string (i.e. by comparing only bytes), using for matching human text, you'll want \code{\link[=coll]{coll()}} which respects character matching rules for the specified locale. -You can not match boundaries, including \code{""}, with this function.} +You cannot match boundaries, including \code{""}, with this function.} } \value{ A character vector the same length as \code{string}/\code{pattern}. diff --git a/man/str_replace.Rd b/man/str_replace.Rd index 87db6bcc..77e15c8b 100644 --- a/man/str_replace.Rd +++ b/man/str_replace.Rd @@ -28,10 +28,10 @@ Match a fixed string (i.e. by comparing only bytes), using for matching human text, you'll want \code{\link[=coll]{coll()}} which respects character matching rules for the specified locale. -You can not match boundaries, including \code{""}, with this function.} +You cannot match boundaries, including \code{""}, with this function.} \item{replacement}{The replacement value, usually a single string, -but it can be the a vector the same length as \code{string} or \code{pattern}. +but it can be a vector the same length as \code{string} or \code{pattern}. References of the form \verb{\\1}, \verb{\\2}, etc will be replaced with the contents of the respective matched group (created by \verb{()}). diff --git a/man/str_split.Rd b/man/str_split.Rd index 11352d59..6aecf85e 100644 --- a/man/str_split.Rd +++ b/man/str_split.Rd @@ -94,7 +94,7 @@ str_split_1(fruits[[1]], " and ") # Specify n to restrict the number of possible matches str_split(fruits, " and ", n = 3) str_split(fruits, " and ", n = 2) -# If n greater than number of pieces, no padding occurs +# If n is greater than the number of pieces, no padding occurs str_split(fruits, " and ", n = 5) # Use fixed to return a character matrix diff --git a/man/str_sub.Rd b/man/str_sub.Rd index 9e5b62ba..4b2429da 100644 --- a/man/str_sub.Rd +++ b/man/str_sub.Rd @@ -43,8 +43,8 @@ then the corresponding output will be the empty string. } \description{ \code{str_sub()} extracts or replaces the elements at a single position in each -string. \code{str_sub_all()} allows you to extract strings at multiple elements -in every string. +string. \code{str_sub_all()} allows you to extract substrings at multiple +positions in every string. } \examples{ hw <- "Hadley Wickham" diff --git a/man/str_subset.Rd b/man/str_subset.Rd index a720e625..6306997e 100644 --- a/man/str_subset.Rd +++ b/man/str_subset.Rd @@ -21,7 +21,7 @@ Match a fixed string (i.e. by comparing only bytes), using for matching human text, you'll want \code{\link[=coll]{coll()}} which respects character matching rules for the specified locale. -You can not match boundaries, including \code{""}, with this function.} +You cannot match boundaries, including \code{""}, with this function.} \item{negate}{If \code{TRUE}, inverts the resulting boolean vector.} } diff --git a/man/str_trunc.Rd b/man/str_trunc.Rd index cd366e1e..9bb3442b 100644 --- a/man/str_trunc.Rd +++ b/man/str_trunc.Rd @@ -19,7 +19,7 @@ content has been removed.} A character vector the same length as \code{string}. } \description{ -Truncate a string to a fixed of characters, so that +Truncate a string to a fixed number of characters, so that \code{str_length(str_trunc(x, n))} is always less than or equal to \code{n}. } \examples{ diff --git a/man/str_view.Rd b/man/str_view.Rd index bf0e1767..bc84fa9c 100644 --- a/man/str_view.Rd +++ b/man/str_view.Rd @@ -28,7 +28,7 @@ Match a fixed string (i.e. by comparing only bytes), using for matching human text, you'll want \code{\link[=coll]{coll()}} which respects character matching rules for the specified locale. -You can not match boundaries, including \code{""}, with this function.} +You cannot match boundaries, including \code{""}, with this function.} \item{match}{If \code{pattern} is supplied, which elements should be shown? \itemize{ @@ -51,7 +51,7 @@ values are stored in the string.} to see how a \code{pattern} matches. Matches are surrounded by \verb{<>} and unusual whitespace (i.e. all whitespace -apart from \code{" "} and \code{"\\n"}) are surrounded by \code{{}} and escaped. Where +apart from \code{" "} and \code{"\\n"}) is surrounded by \code{{}} and escaped. Where possible, matches and unusual whitespace are coloured blue and \code{NA}s red. } \examples{ diff --git a/man/str_which.Rd b/man/str_which.Rd index bdb6f296..fb8b661b 100644 --- a/man/str_which.Rd +++ b/man/str_which.Rd @@ -21,7 +21,7 @@ Match a fixed string (i.e. by comparing only bytes), using for matching human text, you'll want \code{\link[=coll]{coll()}} which respects character matching rules for the specified locale. -You can not match boundaries, including \code{""}, with this function.} +You cannot match boundaries, including \code{""}, with this function.} \item{negate}{If \code{TRUE}, inverts the resulting boolean vector.} } diff --git a/man/str_wrap.Rd b/man/str_wrap.Rd index 2a0aed02..fd907eba 100644 --- a/man/str_wrap.Rd +++ b/man/str_wrap.Rd @@ -28,7 +28,7 @@ A character vector the same length as \code{string}. } \description{ Wrap words into paragraphs, minimizing the "raggedness" of the lines -(i.e. the variation in length line) using the Knuth-Plass algorithm. +(i.e. the variation in line length) using the Knuth-Plass algorithm. } \examples{ thanks_path <- file.path(R.home("doc"), "THANKS") diff --git a/man/stringr-data.Rd b/man/stringr-data.Rd index 057be667..9d81844c 100644 --- a/man/stringr-data.Rd +++ b/man/stringr-data.Rd @@ -22,7 +22,7 @@ words written by Gabor Csardi; the data was collected by Darius Kazemi and made available at \url{https://github.com/dariusk/corpora}. \code{sentences} is a collection of "Harvard sentences" used for -standardised testing of voice. +standardized testing of voice. } \examples{ length(sentences) diff --git a/man/word.Rd b/man/word.Rd index 7beca09a..ebb38a1f 100644 --- a/man/word.Rd +++ b/man/word.Rd @@ -10,10 +10,10 @@ word(string, start = 1L, end = start, sep = fixed(" ")) \item{string}{Input vector. Either a character vector, or something coercible to one.} -\item{start, end}{Pair of integer vectors giving range of words (inclusive) +\item{start, end}{Pair of integer vectors giving the range of words (inclusive) to extract. If negative, counts backwards from the last word. -The default value select the first word.} +The default value selects the first word.} \item{sep}{Separator between words. Defaults to single space.} } diff --git a/tests/testthat/_snaps/detect.md b/tests/testthat/_snaps/detect.md index 571828c3..b804ed4b 100644 --- a/tests/testthat/_snaps/detect.md +++ b/tests/testthat/_snaps/detect.md @@ -1,4 +1,4 @@ -# can't empty/boundary +# can't use empty/boundary Code str_detect("x", "") diff --git a/tests/testthat/_snaps/split.md b/tests/testthat/_snaps/split.md index 6b00f942..2a30fabc 100644 --- a/tests/testthat/_snaps/split.md +++ b/tests/testthat/_snaps/split.md @@ -20,7 +20,7 @@ `string` must be a single string, not a character vector. -# str_split_fixed check its inputs +# str_split_fixed checks its inputs Code str_split_fixed("x", "x", 0) @@ -28,7 +28,7 @@ Error in `str_split_fixed()`: ! `n` must be a number larger than 1, not the number 0. -# str_split_i check its inputs +# str_split_i checks its inputs Code str_split_i("x", "x", 0) diff --git a/tests/testthat/_snaps/trunc.md b/tests/testthat/_snaps/trunc.md index b46497c1..b6ce97f1 100644 --- a/tests/testthat/_snaps/trunc.md +++ b/tests/testthat/_snaps/trunc.md @@ -10,3 +10,4 @@ Condition Error in `str_trunc()`: ! `width` (3) is shorter than `ellipsis` (4). + diff --git a/tests/testthat/test-detect.R b/tests/testthat/test-detect.R index 216ba85a..464766b7 100644 --- a/tests/testthat/test-detect.R +++ b/tests/testthat/test-detect.R @@ -34,7 +34,7 @@ test_that("can use fixed() and coll()", { expect_equal(str_ends("\u0131", turkish_I()), TRUE) }) -test_that("can't empty/boundary", { +test_that("can't use empty/boundary", { expect_snapshot(error = TRUE, { str_detect("x", "") str_starts("x", "") diff --git a/tests/testthat/test-match.R b/tests/testthat/test-match.R index 62b31b6a..a87204bb 100644 --- a/tests/testthat/test-match.R +++ b/tests/testthat/test-match.R @@ -18,7 +18,7 @@ phones <- str_c( num[, 10] ) -test_that("empty strings return correct matrix of correct size", { +test_that("empty inputs return correctly sized matrices", { skip_if_not_installed("stringi", "1.2.2") expect_equal(str_match(NA, "(a)"), matrix(NA_character_, 1, 2)) @@ -63,7 +63,7 @@ test_that("match returns NA when optional group doesn't match", { expect_equal(str_match(c("ab", "a"), "(a)(b)?")[, 3], c("b", NA)) }) -test_that("match_all returns NA when option group doesn't match", { +test_that("match_all returns NA when optional group doesn't match", { expect_equal(str_match_all("a", "(a)(b)?")[[1]][1, ], c("a", "a", NA)) }) diff --git a/tests/testthat/test-pad.R b/tests/testthat/test-pad.R index 79a4b089..15033c3a 100644 --- a/tests/testthat/test-pad.R +++ b/tests/testthat/test-pad.R @@ -20,7 +20,7 @@ test_that("directions work for simple case", { expect_equal(pad("both"), " had ") }) -test_that("padding based of length works", { +test_that("padding based on length works", { # \u4e2d is a 2-characters-wide Chinese character pad <- function(...) str_pad("\u4e2d", ..., side = "both") diff --git a/tests/testthat/test-replace.R b/tests/testthat/test-replace.R index 2ee1a317..b2575959 100644 --- a/tests/testthat/test-replace.R +++ b/tests/testthat/test-replace.R @@ -25,7 +25,7 @@ test_that("replacement must be a string", { expect_snapshot(str_replace("x", "x", 1), error = TRUE) }) -test_that("replacement must be a string", { +test_that("NA replacement returns NA", { expect_equal(str_replace("xyz", "x", NA_character_), NA_character_) }) diff --git a/tests/testthat/test-split.R b/tests/testthat/test-split.R index b2126e8a..c0f8ac40 100644 --- a/tests/testthat/test-split.R +++ b/tests/testthat/test-split.R @@ -66,7 +66,7 @@ test_that("str_split_fixed pads with empty string", { ) }) -test_that("str_split_fixed check its inputs", { +test_that("str_split_fixed checks its inputs", { expect_snapshot(str_split_fixed("x", "x", 0), error = TRUE) }) @@ -85,7 +85,7 @@ test_that("str_split_i returns NA for absent components", { expect_equal(str_split_i(c("1-2-3", "4-5"), "-", -4), c(NA_character_, NA)) }) -test_that("str_split_i check its inputs", { +test_that("str_split_i checks its inputs", { expect_snapshot(error = TRUE, { str_split_i("x", "x", 0) str_split_i("x", "x", 0.5) diff --git a/vignettes/from-base.Rmd b/vignettes/from-base.Rmd index 71b1e8c6..39faa80a 100644 --- a/vignettes/from-base.Rmd +++ b/vignettes/from-base.Rmd @@ -176,7 +176,7 @@ str_sub(hw, end = 6) In base you could use `substr()` or `substring()`. The former requires both a start and stop of the substring while the latter assumes the stop will be the end of the string. The stringr version, `str_sub()` has the same functionality, but also gives a default start value (the beginning of the string). Both the base and stringr functions have the same order of expected inputs. -In stringr you can use negative numbers to index from the right-hand side string: -1 is the last letter, -2 is the second to last, and so on. +In stringr you can use negative numbers to index from the right-hand side of the string: -1 is the last letter, -2 is the second to last, and so on. ```{r} str_sub(hw, start = 1, end = -1) @@ -308,7 +308,7 @@ nchar(factor("abc")) str_length(factor("abc")) ``` -Note that "characters" is a poorly defined concept, and technically both `nchar()` and `str_length()` returns the number of code points. This is usually the same as what you'd consider to be a character, but not always: +Note that "characters" is a poorly defined concept, and technically both `nchar()` and `str_length()` return the number of code points. This is usually the same as what you'd consider to be a character, but not always: ```{r} x <- c("\u00fc", "u\u0308") @@ -449,7 +449,7 @@ str_flatten(letters, collapse = "-") The advantage of `str_flatten()` is that it always returns a vector the same length as its input; to predict the return length of `paste()` you must carefully read all arguments. -## `str_dup()`: duplicate strings within a character vector +## `str_dup()`: Duplicate strings within a character vector To duplicate strings within a character vector use `strrep()` (in R 3.3.0 or greater) or `str_dup()`: diff --git a/vignettes/locale-sensitive.Rmd b/vignettes/locale-sensitive.Rmd index 58c1926a..9291fbe0 100644 --- a/vignettes/locale-sensitive.Rmd +++ b/vignettes/locale-sensitive.Rmd @@ -56,7 +56,7 @@ str_to_sentence(dutch_sentence) str_to_sentence(dutch_sentence, locale = "nl") ``` -Case conversion also comes up in another situation: case-insensitive comparison. This is relevant in two contexts. First, `str_equal()` and `str_unique()` can optionally ignore case, so it's important to also supply locale when working with non-English text. For example, imagine we're searching for a Turkish name, ignoring case: +Case conversion also comes up in another situation: case-insensitive comparison. This is relevant in two contexts. First, `str_equal()` and `str_unique()` can optionally ignore case, so it's important to also supply a locale when working with non-English text. For example, imagine we're searching for a Turkish name, ignoring case: ```{r} turkish_names <- c("İpek", "Işık", "İbrahim") @@ -69,7 +69,7 @@ str_equal(turkish_names, search_name, ignore_case = TRUE) str_equal(turkish_names, search_name, ignore_case = TRUE, locale = "tr") ``` -Case conversion also comes up in pattern matching functions like `str_detect()`. You might be accustomed to use `ignore_case = TRUE` with `regex()` or `fixed()`, but if you want to use locale-sensitive comparison you instead need to use `coll()`: +Case conversion also comes up in pattern matching functions like `str_detect()`. You might be accustomed to using `ignore_case = TRUE` with `regex()` or `fixed()`, but if you want to use locale-sensitive comparison you instead need to use `coll()`: ```{r} # incorrect diff --git a/vignettes/regular-expressions.Rmd b/vignettes/regular-expressions.Rmd index 33cf7c2a..bd5c90ce 100644 --- a/vignettes/regular-expressions.Rmd +++ b/vignettes/regular-expressions.Rmd @@ -17,7 +17,7 @@ knitr::opts_chunk$set( library(stringr) ``` -Regular expressions are a concise and flexible tool for describing patterns in strings. This vignette describes the key features of stringr's regular expressions, as implemented by [stringi](https://github.com/gagolews/stringi). It is not a tutorial, so if you're unfamiliar regular expressions, I'd recommend starting at . If you want to master the details, I'd recommend reading the classic [_Mastering Regular Expressions_](https://www.amazon.com/Mastering-Regular-Expressions-Jeffrey-Friedl/dp/0596528124) by Jeffrey E. F. Friedl. +Regular expressions are a concise and flexible tool for describing patterns in strings. This vignette describes the key features of stringr's regular expressions, as implemented by [stringi](https://github.com/gagolews/stringi). It is not a tutorial, so if you're unfamiliar with regular expressions, I'd recommend starting at . If you want to master the details, I'd recommend reading the classic [_Mastering Regular Expressions_](https://www.amazon.com/Mastering-Regular-Expressions-Jeffrey-Friedl/dp/0596528124) by Jeffrey E. F. Friedl. Regular expressions are the default pattern engine in stringr. That means when you use a pattern matching function with a bare string, it's equivalent to wrapping it in a call to `regex()`: @@ -162,7 +162,7 @@ There are five other escaped pairs that match narrower classes of characters: * `\s`: matches any whitespace. This includes tabs, newlines, form feeds, and any character in the Unicode Z Category (which includes a variety of - space characters and other separators.). The complement, `\S`, matches any + space characters and other separators). The complement, `\S`, matches any non-whitespace character. ```{r} @@ -170,7 +170,7 @@ There are five other escaped pairs that match narrower classes of characters: str_replace_all(text, "\\s+", " ") ``` -* `\p{property name}` matches any character with specific unicode property, +* `\p{property name}` matches any character with a specific unicode property, like `\p{Uppercase}` or `\p{Diacritic}`. The complement, `\P{property name}`, matches all characters without the property. A complete list of unicode properties can be found at @@ -216,7 +216,7 @@ There are a number of pre-built classes that you can use inside `[]`: * `[:punct:]`: punctuation. * `[:alpha:]`: letters. * `[:lower:]`: lowercase letters. -* `[:upper:]`: upperclass letters. +* `[:upper:]`: uppercase letters. * `[:digit:]`: digits. * `[:xdigit:]`: hex digits. * `[:alnum:]`: letters and numbers. @@ -228,7 +228,7 @@ There are a number of pre-built classes that you can use inside `[]`: These all go inside the `[]` for character classes, i.e. `[[:digit:]AX]` matches all digits, A, and X. -You can also using Unicode properties, like `[\p{Letter}]`, and various set operations, like `[\p{Letter}--\p{script=latin}]`. See `?"stringi-search-charclass"` for details. +You can also use Unicode properties, like `[\p{Letter}]`, and various set operations, like `[\p{Letter}--\p{script=latin}]`. See `?"stringi-search-charclass"` for details. ## Alternation @@ -272,7 +272,7 @@ This is most useful for more complex cases where you need to capture matches and You can use `(?...)`, the named capture group, to provide a reference to the matched text. This is more readable and maintainable, especially with complex regular expressions, because you can reference the matched text by name instead of a potentially confusing numerical index. -*Note: `` should not include an underscore because they are not supported.* +*Note: `` should not include an underscore because underscores are not supported.* ```{r} date_string <- "Today's date is 2025-09-19." @@ -359,7 +359,7 @@ By default these matches are "greedy": they will match the longest string possib * `+?`: 1 or more, match as few times as possible. * `*?`: 0 or more, match as few times as possible. * `{n,}?`: n or more, match as few times as possible. -* `{n,m}?`: between n and m, , match as few times as possible, but at least n. +* `{n,m}?`: between n and m, match as few times as possible, but at least n. ```{r} str_extract(x, c("C{2,3}", "C{2,3}?")) @@ -421,7 +421,7 @@ There are two ways to include comments in a regular expression. The first is wit str_detect("xyz", "x(?#this is a comment)") ``` -The second is to use `regex(comments = TRUE)`. This form ignores spaces and newlines, and anything everything after `#`. To match a literal space, you'll need to escape it: `"\\ "`. This is a useful way of describing complex regular expressions: +The second is to use `regex(comments = TRUE)`. This form ignores spaces and newlines, and everything after `#`. To match a literal space, you'll need to escape it: `"\\ "`. This is a useful way of describing complex regular expressions: ```{r} phone <- regex(" diff --git a/vignettes/stringr.Rmd b/vignettes/stringr.Rmd index d234ded3..57ee923d 100644 --- a/vignettes/stringr.Rmd +++ b/vignettes/stringr.Rmd @@ -40,7 +40,7 @@ str_length("abc") This is now equivalent to the base R function `nchar()`. Previously it was needed to work around issues with `nchar()` such as the fact that it returned 2 for `nchar(NA)`. This has been fixed as of R 3.3.0, so it is no longer so important. -You can access individual character using `str_sub()`. It takes three arguments: a character vector, a `start` position and an `end` position. Either position can either be a positive integer, which counts from the left, or a negative integer which counts from the right. The positions are inclusive, and if longer than the string, will be silently truncated. +You can access individual characters using `str_sub()`. It takes three arguments: a character vector, a `start` position and an `end` position. Either position can be a positive integer, which counts from the left, or a negative integer which counts from the right. The positions are inclusive, and if longer than the string, will be silently truncated. ```{r} x <- c("abcdef", "ghifjk") @@ -146,7 +146,7 @@ str_sort(x) str_sort(x, locale = "lt") ``` -The locale always defaults to English to ensure that the default behaviour is identical across systems. Locales always include a two letter ISO-639-1 language code (like "en" for English or "zh" for Chinese), and optionally a ISO-3166 country code (like "en_UK" vs "en_US"). You can see a complete list of available locales by running `stringi::stri_locale_list()`. +The locale always defaults to English to ensure that the default behaviour is identical across systems. Locales always include a two letter ISO-639-1 language code (like "en" for English or "zh" for Chinese), and optionally an ISO-3166 country code (like "en_UK" vs "en_US"). You can see a complete list of available locales by running `stringi::stri_locale_list()`. ## Pattern matching @@ -169,7 +169,7 @@ phone <- "([2-9][0-9]{2})[- .]([0-9]{3})[- .]([0-9]{4})" - `str_detect()` detects the presence or absence of a pattern and returns a logical vector (similar to `grepl()`). `str_subset()` returns the elements of a character vector that match a regular expression (similar to `grep()` - with `value = TRUE`)`. + with `value = TRUE`). ```{r} # Which strings contain phone numbers?