Skip to content

Commit

Permalink
update str_extract to remove stringr dep (#10)
Browse files Browse the repository at this point in the history
closes #9 



--------------------------------------------------------------------------------

Pre-review Checklist (if item does not apply, mark is as complete)
- [x] **All** GitHub Action workflows pass with a ✅
- [x] PR branch has pulled the most recent updates from master branch:
`usethis::pr_merge_main()`
- [x] If a bug was fixed, a unit test was added.
- [x] If a standalone script was updated, a comment is added to the
script header (changelog) AND the `last-updated` field has been updated.
- [x] Code coverage is suitable for any new functions/features
(generally, 100% coverage for new code): `devtools::test_coverage()`
- [x] Request a reviewer

Reviewer Checklist (if item does not apply, mark is as complete)

- [x] If a bug was fixed, a unit test was added.
- [x] If a standalone script was updated, a comment is added to the
script header (changelog) AND the `last-updated` field has been updated.
- [x] Run `pkgdown::build_site()`. Check the R console for errors, and
review the rendered website.
- [x] Code coverage is suitable for any new functions/features:
`devtools::test_coverage()`

When the branch is ready to be merged:
- [ ] **All** GitHub Action workflows pass with a ✅
- [ ] Approve Pull Request
- [ ] Merge the PR. Please use "Squash and merge" or "Rebase and merge".
- [ ] Create an issue in any repositories using {standalone} to update
the standalone scripts.
  • Loading branch information
ayogasekaram authored Feb 19, 2025
1 parent 3a7ad70 commit 60ba1ed
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
11 changes: 8 additions & 3 deletions R/standalone-check_pkg_installed.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# ---
# repo: insightsengineering/standalone
# file: standalone-check_pkg_installed.R
# last-updated: 2024-04-19
# last-updated: 2025-02-03
# license: https://unlicense.org
# dependencies: standalone-cli_call_env.R
# imports: [rlang, dplyr, tidyr]
Expand All @@ -10,6 +10,9 @@
# This file provides functions to check package installation.
#
# ## Changelog
# 2025-02-03
# - `get_pkg_dependencies()` was updated to use base r equivalents for `str_extract()` and `str_remove_all()`.

# nocov start
# styler: off

Expand Down Expand Up @@ -160,8 +163,10 @@ get_pkg_dependencies <- function(pkg = utils::packageName(), lib.loc = NULL) {
sep = " ", extra = "merge", fill = "right"
) |>
dplyr::mutate(
compare = .data$version |> str_extract(pattern = "[>=<]+"),
version = .data$version |> str_remove_all(pattern = "[\\(\\) >=<]")
compare = as.character(ifelse(regexpr("[>=<]+", .data$version) > 0,
regmatches(.data$version, regexpr("[>=<]+", .data$version)),
NA)),
version = gsub(pattern = "[\\(\\) >=<]", replacement = "", x = .data$version)
)
}

Expand Down
13 changes: 13 additions & 0 deletions tests/testthat/test-standalone-stringr.R
Original file line number Diff line number Diff line change
Expand Up @@ -270,3 +270,16 @@ test_that("str_split() works", {
s <- str_split("This is a test string\nwith multiple\nlines", pattern = "\\n(?!\\\\)")
expect_identical(s, stringr::str_split("This is a test string\nwith multiple\nlines", pattern = "\\n(?!\\\\)"))
})

test_that("str_extract() and str_remove_all() replacement works for package version identification", {
package_version <- "2.0.3"

s <- as.character(ifelse(regexpr("[>=<]+", package_version) > 0,
regmatches(package_version, regexpr("[>=<]+", package_version)),
NA))
expect_identical(s, stringr::str_extract(package_version, pattern = "[>=<]+"))

s <- gsub(pattern = "[\\(\\) >=<]", replacement = "", x = package_version)
expect_identical(s, stringr::str_remove_all(package_version, "[\\(\\) >=<]"))

})

0 comments on commit 60ba1ed

Please sign in to comment.