Skip to content

Commit

Permalink
Fix ends and starts for factor columns
Browse files Browse the repository at this point in the history
  • Loading branch information
mikmart committed Jan 19, 2024
1 parent d60b27a commit 927f4d8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
8 changes: 4 additions & 4 deletions R/searchbuilder.R
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ sbEvaluateCondition = function(condition, type, x, value) {
'=' = x == value,
'contains' = grepl(value, x, fixed = TRUE),
'!contains' = !grepl(value, x, fixed = TRUE),
'ends' = endsWith(x, value),
'!ends' = !endsWith(x, value),
'ends' = endsWith(as.character(x), value),
'!ends' = !endsWith(as.character(x), value),
'null' = is.na(x) | x == '',
'starts' = startsWith(x, value),
'!starts' = !startsWith(x, value),
'starts' = startsWith(as.character(x), value),
'!starts' = !startsWith(as.character(x), value),
stop(sprintf('unsupported condition "%s" for criteria type "%s"', condition, type))
)
} else if (type %in% c('num', 'num-fmt', 'html-num', 'html-num-fmt')) {
Expand Down
1 change: 1 addition & 0 deletions tests/testit/test-searchbuilder.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ assert('SearchBuilder condition evaluation works', {
(sbEvaluateCondition('>', 'num', 1:2, 1) == c(FALSE, TRUE))
(sbEvaluateCondition('between', 'num', 7, c(2, 4)) == FALSE)
(sbEvaluateCondition('starts', 'string', 'foo', 'f') == TRUE)
(sbEvaluateCondition('starts', 'string', factor('foo'), 'f') == TRUE)
})

assert('SearchBuilder logic evaluation works', {
Expand Down

0 comments on commit 927f4d8

Please sign in to comment.