Skip to content

Commit

Permalink
Merged origin/main into edward-burn-str_dup_sep
Browse files Browse the repository at this point in the history
  • Loading branch information
hadley committed Aug 20, 2024
2 parents 089abea + 12839fc commit 7d802a1
Show file tree
Hide file tree
Showing 28 changed files with 85 additions and 41 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ on:
pull_request:
branches: [main, master]

name: R-CMD-check
name: R-CMD-check.yaml

permissions: read-all

Expand All @@ -27,8 +27,8 @@ jobs:
- {os: macos-latest, r: 'release'}

- {os: windows-latest, r: 'release'}
# use 4.1 to check with rtools40's older compiler
- {os: windows-latest, r: '4.1'}
# use 4.0 or 4.1 to check with rtools40's older compiler
- {os: windows-latest, r: 'oldrel-4'}

- {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'}
- {os: ubuntu-latest, r: 'release'}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pkgdown.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:
types: [published]
workflow_dispatch:

name: pkgdown
name: pkgdown.yaml

permissions: read-all

Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/pr-commands.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
issue_comment:
types: [created]

name: Commands
name: pr-commands.yaml

permissions: read-all

Expand All @@ -15,6 +15,8 @@ jobs:
runs-on: ubuntu-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
permissions:
contents: write
steps:
- uses: actions/checkout@v4

Expand Down Expand Up @@ -52,6 +54,8 @@ jobs:
runs-on: ubuntu-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
permissions:
contents: write
steps:
- uses: actions/checkout@v4

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-coverage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
pull_request:
branches: [main, master]

name: test-coverage
name: test-coverage.yaml

permissions: read-all

Expand Down
14 changes: 14 additions & 0 deletions R/count.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,20 @@
#' of `string.`
#'
#' @inheritParams str_detect
#' @param pattern Pattern to look for.
#'
#' The default interpretation is a regular expression, as described in
#' `vignette("regular-expressions")`. Use [regex()] for finer control of the
#' matching behaviour.
#'
#' Match a fixed string (i.e. by comparing only bytes), using
#' [fixed()]. This is fast, but approximate. Generally,
#' for matching human text, you'll want [coll()] which
#' respects character matching rules for the specified locale.
#'
#' Match character, word, line and sentence boundaries with
#' [boundary()]. The empty string, `""``, is equivalent to
#' `boundary("character")`.
#' @return An integer vector the same length as `string`/`pattern`.
#' @seealso [stringi::stri_count()] which this function wraps.
#'
Expand Down
4 changes: 1 addition & 3 deletions R/detect.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@
#' for matching human text, you'll want [coll()] which
#' respects character matching rules for the specified locale.
#'
#' Match character, word, line and sentence boundaries with
#' [boundary()]. An empty pattern, "", is equivalent to
#' `boundary("character")`.
#' You can not 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`.
Expand Down
2 changes: 1 addition & 1 deletion R/extract.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#' `str_extract()` extracts the first complete match from each string,
#' `str_extract_all()`extracts all matches from each string.
#'
#' @inheritParams str_detect
#' @inheritParams str_count
#' @param group If supplied, instead of returning the complete match, will
#' return the matched text from the specified capturing group.
#' @seealso [str_match()] to extract matched groups;
Expand Down
2 changes: 1 addition & 1 deletion R/locate.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#' Because the `start` and `end` values are inclusive, zero-length matches
#' (e.g. `$`, `^`, `\\b`) will have an `end` that is smaller than `start`.
#'
#' @inheritParams str_detect
#' @inheritParams str_count
#' @returns
#' * `str_locate()` returns an integer matrix with two columns and
#' one row for each element of `string`. The first column, `start`,
Expand Down
2 changes: 2 additions & 0 deletions R/replace.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
#' [fixed()]. This is fast, but approximate. Generally,
#' 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.
#' @param replacement The replacement value, usually a single string,
#' but it can be the a vector the same length as `string` or `pattern`.
#' References of the form `\1`, `\2`, etc will be replaced with
Expand Down
1 change: 0 additions & 1 deletion R/split.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#' * `str_split_fixed()` splits each string in a character vector into a
#' fixed number of pieces, returning a character matrix.
#'
#' @inheritParams str_detect
#' @inheritParams str_extract
#' @param n Maximum number of pieces to return. Default (Inf) uses all
#' possible split positions.
Expand Down
3 changes: 1 addition & 2 deletions man/str_count.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions man/str_detect.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions man/str_extract.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions man/str_locate.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions man/str_remove.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion man/str_replace.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions man/str_split.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions man/str_subset.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions man/str_view.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions man/str_which.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions tests/testthat/_snaps/conv.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# check encoding argument

Code
str_conv("A", c("ISO-8859-1", "ISO-8859-2"))
Condition
Error in `str_conv()`:
! `encoding` must be a single string, not a character vector.

8 changes: 8 additions & 0 deletions tests/testthat/_snaps/equal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# vectorised using TRR

Code
str_equal(letters[1:3], c("a", "b"))
Condition
Error in `str_equal()`:
! Can't recycle `x` (size 3) to match `y` (size 2).

8 changes: 8 additions & 0 deletions tests/testthat/_snaps/flatten.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# collapse must be single string

Code
str_flatten("A", c("a", "b"))
Condition
Error in `str_flatten()`:
! `collapse` must be a single string, not a character vector.

13 changes: 13 additions & 0 deletions tests/testthat/_snaps/match.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
# match and match_all fail when pattern is not a regex

Code
str_match(phones, fixed("3"))
Condition
Error in `str_match()`:
! `pattern` must be a regular expression.
Code
str_match_all(phones, coll("9"))
Condition
Error in `str_match_all()`:
! `pattern` must be a regular expression.

# match can't use other modifiers

Code
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-conv.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ test_that("encoding conversion works", {
})

test_that("check encoding argument", {
expect_error(str_conv("A", c("ISO-8859-1", "ISO-8859-2")), "single string")
expect_snapshot(str_conv("A", c("ISO-8859-1", "ISO-8859-2")), error = TRUE)
})
2 changes: 1 addition & 1 deletion tests/testthat/test-equal.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ test_that("vectorised using TRR", {
expect_equal(str_equal("a", character()), logical())
expect_equal(str_equal("a", "b"), FALSE)
expect_equal(str_equal("a", c("a", "b")), c(TRUE, FALSE))
expect_error(str_equal(letters[1:3], c("a", "b")), "recycle")
expect_snapshot(str_equal(letters[1:3], c("a", "b")), error = TRUE)
})

test_that("can ignore case", {
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-flatten.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ test_that("equivalent to paste with collapse", {
})

test_that("collapse must be single string", {
expect_error(str_flatten("A", c("a", "b")), "single string")
expect_snapshot(str_flatten("A", c("a", "b")), error = TRUE)
})

test_that("last optionally used instead of final separator", {
Expand Down
6 changes: 4 additions & 2 deletions tests/testthat/test-match.R
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,10 @@ test_that("multiple match works", {
})

test_that("match and match_all fail when pattern is not a regex", {
expect_error(str_match(phones, fixed("3")))
expect_error(str_match_all(phones, coll("9")))
expect_snapshot(error = TRUE, {
str_match(phones, fixed("3"))
str_match_all(phones, coll("9"))
})
})

test_that("uses tidyverse recycling rules", {
Expand Down

0 comments on commit 7d802a1

Please sign in to comment.