[R] Search within a file

Seth Falcon sfalcon at fhcrc.org
Sat Nov 5 20:02:29 CET 2005


On  4 Nov 2005, JAROSLAW.W.TUSZYNSKI at saic.com wrote:

> Thanks for a great suggestions. I guess the code you suggested would
> look something like this:

Glad you found it useful.  A quick note on a potentially serious
problem:

It seems entirely possibly that you split an instance of pattern in
the buffer.  That is, if you are searching for "right" you might read
in "I have a ri" in the first read and then "ght to a trial by jury"
in the second read.

If you know the pattern you are looking for won't be split over
multiple lines, you could use readLines instead of readChar.

Depending on the application you could also read "words" or use some
other info about the strucutre of the data you are reading to ensure
you don't ever split a pattern across a read.

+ seth




More information about the R-help mailing list