Skip to content

Instantly share code, notes, and snippets.

@turingDH
Created November 15, 2018 03:28
Show Gist options
  • Save turingDH/80a91745a7d60d4272486c0618a91476 to your computer and use it in GitHub Desktop.
Save turingDH/80a91745a7d60d4272486c0618a91476 to your computer and use it in GitHub Desktop.
Search script files in RStudio; open via file protocol
library(dplyr)
library(DT)
library(purrr)
library(tidyr)
phraseToSearch <- 'this|that'
scriptFiles <-
bind_rows(
map_dfc('~/R', list.files, full.names = T) %>% rename(fileNames = V1),
map_dfc('~/randomTraining', list.files, full.names = T) %>% rename(fileNames = V1)
) %>%
filter(grepl('.sql$|.R$|.py$|.pyc$|.txt$|.yxmd$|.sh$|.awk$', fileNames, ignore.case = T))
logicalFileVector <- vector()
for (i in seq_along(scriptFiles$fileNames)){
logicalFileVector[i] <- any(grep(phraseToSearch, readLines(scriptFiles$fileNames[i]), value = F, ignore.case = T))
}
filesWithString <-
bind_cols(scriptFiles, as_tibble(logicalFileVector)) %>%
filter(value) %>%
select(-value) %>%
mutate(fileNames = paste0("file://", fileNames))
datatable(filesWithString, class='cell-border')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment