How to filter through a vector a files and return a new vector that only has those contain “.html” on R

Solution for How to filter through a vector a files and return a new vector that only has those contain “.html” on R
is Given Below:

I tried using

files1 <- str_detect(files, "html")

but all that returns is the list as a boolean which I do not want.

We may need str_subset

library(stringr0
str_subset(files, "html")

Or use the logical output from ‘str_detect’ as index to extract the corresponding elements

files[str_detect(files, "html")]

A base R way, notice argument value.

grep("\.html", files, value = TRUE)