Skip to content

Instantly share code, notes, and snippets.

@brshallo
Created August 29, 2023 06:00
Show Gist options
  • Save brshallo/246b02d652d35995b73c42ee88079c87 to your computer and use it in GitHub Desktop.
Save brshallo/246b02d652d35995b73c42ee88079c87 to your computer and use it in GitHub Desktop.
library(magrittr)
find_in_files <- function(path, pattern){
path %>%
fs::dir_ls(recurse = TRUE, type = "file", regexp = "(\\.[rR])$") %>%
purrr::map(~grep(pattern, readLines(.x, warn = FALSE), value = TRUE)) %>%
purrr::keep(~length(.x) > 0)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment