Skip to content

Instantly share code, notes, and snippets.

@benjamin-chan
Created January 12, 2023 22:30
Show Gist options
  • Save benjamin-chan/29787752736b2b8b5a17cf7e14f8837e to your computer and use it in GitHub Desktop.
Save benjamin-chan/29787752736b2b8b5a17cf7e14f8837e to your computer and use it in GitHub Desktop.
Search for text in a file
search <- function(file, str) {
text <- readLines(file.path(path, file), warn = FALSE)
df <- data.frame(file = file,
line = 1:length(text),
regex = str,
result = grepl(str, text),
text)
df[df$result == TRUE, ]
}
lapply(list.files(), search, str = "201620ORWA_Indiv4v7Final.dta") %>% dplyr::bind_rows()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment