Skip to content

Commit

Permalink
Merge branch 'development' of github.com:SebKrantz/collapse into deve…
Browse files Browse the repository at this point in the history
…lopment
  • Loading branch information
SebKrantz committed Nov 2, 2024
2 parents 498da83 + 0666b3c commit 68371dc
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
4 changes: 2 additions & 2 deletions CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ identifiers:
- type: doi
value: 10.32614/CRAN.package.collapse
- type: url
value: https://twitter.com/collapse_R
value: https://x.com/collapse_R
abstract: A C/C++ based package for advanced data transformation and statistical computing
in R that is extremely fast, class-agnostic, robust and programmer friendly. Core
functionality includes a rich set of S3 generic grouped and weighted statistical
Expand Down Expand Up @@ -47,7 +47,7 @@ preferred-citation:
repository: https://CRAN.R-project.org/package=collapse
repository-code: https://github.com/SebKrantz/collapse
url: https://sebkrantz.github.io/collapse/
date-released: '2024-09-29'
date-released: '2024-10-27'
contact:
- family-names: Krantz
given-names: Sebastian
Expand Down
5 changes: 2 additions & 3 deletions R/recode_replace.R
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,8 @@ recode_char <- function(X, ..., default = NULL, missing = NULL, regex = FALSE,
} else {
repfun <- function(y) if(is.character(y)) {
z <- scv(y, 1L, y[1L], vind1 = TRUE) # Copy
y <- scv(y, nam[1L], default, set, TRUE)
scv(y, nam[1L], args[[1L]], TRUE)
for(i in seqarg[-1L]) scv(y, grepl(nam[i], z, ignore.case, FALSE, fixed), args[[i]], TRUE, vind1 = TRUE)
y <- scv(y, seq_along(y), default, set, vind1 = TRUE) # Initialize all to default
for(i in seqarg) scv(y, grepl(nam[i], z, ignore.case, FALSE, fixed), args[[i]], TRUE, vind1 = TRUE)
y
} else y
}
Expand Down
5 changes: 4 additions & 1 deletion tests/testthat/test-recode-replace.R
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ set.seed(101)
lmiss <- na_insert(letters)
month.miss <- na_insert(month.name)
char_dat <- na_insert(char_vars(GGDC10S))

char_nums <- c("-1", "1", "0", "2", "-2")
options(warn = -1)

test_that("recode_char works well", {
Expand Down Expand Up @@ -93,6 +93,9 @@ test_that("recode_char works well", {
expect_visible(recode_char(char_dat, saharan = "SSA", regex = TRUE, default = "n"))
expect_visible(recode_char(char_dat, saharan = "SSA", regex = TRUE, default = "n", missing = "c"))

expect_equal(recode_char(char_nums, "-\\d+" = "negative", "0" = "zero", regex = T), c("negative", "1", "zero", "2", "negative"))
expect_equal(recode_char(char_nums, "0" = "zero", "-\\d+" = "negative", default = "positive", regex = T), c("negative", "positive", "zero", "positive", "negative"))
expect_equal(recode_char(char_nums, "-\\d+" = "negative", "0" = "zero", default = "positive", regex = T), c("negative", "positive", "zero", "positive", "negative"))
})

set.seed(101)
Expand Down

0 comments on commit 68371dc

Please sign in to comment.