Created
January 12, 2023 22:30
-
-
Save benjamin-chan/29787752736b2b8b5a17cf7e14f8837e to your computer and use it in GitHub Desktop.
Search for text in a file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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