Created
November 15, 2018 03:28
-
-
Save turingDH/80a91745a7d60d4272486c0618a91476 to your computer and use it in GitHub Desktop.
Search script files in RStudio; open via file protocol
This file contains 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
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