`grepl` isn't working correctly for `CharacterList` with `ignore.case` and `fixed` enabled
Closed this issue · 2 comments
mjsteinbaugh commented
Hi Bioconductor team,
I noticed an issue with grepl
matching against a CharacterList
object:
library(IRanges)
pattern <- "a"
x <- CharacterList(list(c("A", "a"), c("B", "b")))
print(x)
## CharacterList of length 2
## [[1]] A a
## [[2]] B b
This works as expected:
grepl(pattern = pattern, x = x, ignore.case = FALSE, fixed = FALSE)
## LogicalList of length 2
## [[1]] FALSE TRUE
## [[2]] FALSE FALSE
This works as expected:
grepl(pattern = pattern, x = x, ignore.case = FALSE, fixed = TRUE)
## LogicalList of length 2
## [[1]] FALSE TRUE
## [[2]] FALSE FALSE
This works as expected:
grepl(pattern = pattern, x = x, ignore.case = TRUE, fixed = FALSE)
## LogicalList of length 2
## [[1]] TRUE TRUE
## [[2]] FALSE FALSE
This doesn't work as expected. Warns and returns incorrect values. Should return [[1]] TRUE TRUE
.
grepl(pattern = pattern, x = x, ignore.case = TRUE, fixed = TRUE)
## Warning in grepl(pattern, unlist(x, use.names = FALSE), ignore.case, perl, :
## argument 'ignore.case = TRUE' will be ignored
## Calls: grepl -> grepl -> relist -> grepl -> grepl
## LogicalList of length 2
## [[1]] FALSE TRUE
## [[2]] FALSE FALSE
Best,
Mike
hpages commented
Should return
[[1]] TRUE TRUE
.
Are you sure?
base::grepl(pattern = "a", x = c("A", "a"), ignore.case = TRUE, fixed = TRUE)
# [1] FALSE TRUE
# Warning message:
# In base::grepl(pattern = "a", x = c("A", "a"), ignore.case = TRUE, :
# argument 'ignore.case = TRUE' will be ignored
mjsteinbaugh commented
@hpages argument 'ignore.case = TRUE' will be ignored
shouldn't be happening though right? This is confusing behavior in R.
grepl(pattern = "a", x = c("A", "a"), ignore.case = TRUE, fixed = FALSE)
## [1] TRUE TRUE
grepl(pattern = "a", x = c("A", "a"), ignore.case = TRUE, fixed = TRUE)
## Warning in grepl(pattern = "a", x = c("A", "a"), ignore.case = TRUE, fixed = TRUE) :
## argument 'ignore.case = TRUE' will be ignored
## [1] FALSE TRUE
Ah you're right thanks -- I'm going to close and make sure I don't use fixed
. This seems like a bug in base R to me.