Hello Guys,
I have run into a confusion. I am trying to select columns of a table with ends_with function of the dplyr package. It works fine if i use it with out regex. However, in my case i need to use regex. Below is the reprex of what I am trying to do.
I am sure it is something stupid that I am forgetting. Kindly help out.
library(reprex)
library(tidyverse)
#> Warning: package 'dplyr' was built under R version 3.6.3
#> Warning: package 'forcats' was built under R version 3.6.3
tibble(
a = c(1,2,1,3,5,8),
b = c(1,2,3,4,5,6),
a_11 = c(7,8,9,4,5,6)
) -> temp
## ends_with works with simple charasters
temp %>%
select(ends_with("a")) %>% names()
#> [1] "a"
## ends with does not work with regex
temp %>%
select(ends_with("_[:digit:]{1,}")) %>% names()
#> character(0)
## checking if regex is correect
str_detect(names(temp),"_[:digit:]{1,}" )
#> [1] FALSE FALSE TRUE
Created on 2020-04-26 by the reprex package (v0.3.0)