statquant
statquant

Reputation: 14370

Test if string exist in File (with R)

I have several fairly large csv files (few millions lines), and I would like to know which one I need to load. Some of them hold GOTCHASTR some do not. Say I way to load only the ones which hold this string, how can I test if without loading all the files and testing afterwards.

I realize it looks like a bash/grep question but as R import some UNIX functionalities I am hoping that this can work. I am using Windows 7 + gnuWin32

Upvotes: 0

Views: 2226

Answers (1)

user1600826
user1600826

Reputation:

patterns <- sapply(list.files("/your/dir", full.names=TRUE), FUN=function(x){
  grep("GOTCHASTR", readLines(x))
})

Upvotes: 4

Related Questions