-1

Im assert if there is a "." in a string in R, but grepl always comes back false. Can anyone explain where im going wrong?

Here is my code:

grepl("testtxt",".")
[1] FALSE
grepl("test.txt",".")
[1] FALSE
blobbymatt
  • 317
  • 1
  • 2
  • 17

1 Answers1

1

We need either fixed = TRUE

grepl("test.txt", pattern = ".", fixed = TRUE)
#[1] TRUE

NOTE: pattern is the first argument of grep/grepl If we specify it in different order, make sure to name the parameter

or escape (\\.) the . as . is a metacharacter that matches any character

akrun
  • 874,273
  • 37
  • 540
  • 662