Julius Tesoro
2011-Aug-31 02:23 UTC
[R] reading data from multiple files with multiple headers
Dear All, I have many files with a lot of headers and text at the beginning of the file. The headers are not uniform though and they contain different sizes Is there a way where I can read a table and skip all of the headers/text on top of it until I encounter a certain text pattern? Here is an example. I just want to read the table after the ~A. ~Version Information ?VERS.????????????? 2.00:???? CWLS log ASCII Standard -VERSION 2.00 ?WRAP.??????????????? NO:???? One line per depth step # # ~Well Information Block #MNEM.UNIT???? Data Type????????????????????? Description #---------???? -----------??????????????????? ---------------- ?STRT.M???????????? 51.000??????????????????? :START DEPTH?? ? ?STOP.M?????????????? .010??????????????????? :STOP DEPTH??? ? ?STEP.M????????????? -.010??????????????????? :STEP????????? ? # # ~Curve Information Block #MNEM.UNIT??????????????????????? Curve Description #---------??????????????????????? ----------------------------- ?DEPT.M?????????????????????????? :DEPTH ?GRDE.GAPI??????????????????????? :GAMMA FROM DENSITY TOOL ?CODE.G/C3??????????????????????? :COMPENSATED DENSITY??? ? # # # ~A? Depth?????? GRDE?????? CODE?????? LSDU?????? BRDU?????? CADE?????? DENL?????? DENB?????? ADEN?????? VL2F?????? VL4F?????? VL6F?????? VL2A ??? 51.000??? -999.25??? -999.25??? -999.25??? -999.25??? -999.25??? -999.25??? -999.25??? -999.25??? -999.25??? -999.25??? -999.25??? -999.25 ??? 50.990??? -999.25??? -999.25??? -999.25??? -999.25??? -999.25??? -999.25??? -999.25??? -999.25??? -999.25??? -999.25??? -999.25??? -999.25 ??? 50.980??? -999.25??? -999.25??? -999.25??? -999.25??? -999.25??? -999.25??? -999.25??? -999.25??? -999.25??? -999.25??? -999.25??? -999.25 ??? 50.970??? -999.25??? -999.25??? -999.25??? -999.25??? -999.25??? -999.25??? -999.25??? -999.25??? -999.25??? -999.25??? -999.25??? -999.25 ??? 50.960??? -999.25??? -999.25??? -999.25??? -999.25??? -999.25??? -999.25??? -999.25??? -999.25??? -999.25??? -999.25??? -999.25??? -999.25 ??? 50.950??? -999.25??? -999.25??? -999.25??? -999.25??? -999.25??? -999.25??? -999.25??? -999.25??? -999.25??? -999.25??? -999.25??? -999.25 ??? 50.940??? -999.25??? -999.25??? -999.25??? -999.25??? -999.25??? -999.25??? -999.25??? -999.25??? -999.25??? -999.25??? -999.25??? -999.25
Jim Holtman
2011-Aug-31 03:14 UTC
[R] reading data from multiple files with multiple header
use readLines to read in the entire file, find your pattern of where your data starts and then write the data starting there using writeLines to a temporary file and now you can just read in that file using read.table; you will have 'skipped' the extra header data. Sent from my iPad On Aug 30, 2011, at 22:23, Julius Tesoro <jutesoro at yahoo.com> wrote:> Dear All, > > > I have many files with a lot of headers and text at the beginning of the file. The headers are not uniform though and they contain different sizes Is there a way where I can read a table and skip all of the headers/text on top of it until I encounter a certain text pattern? Here is an example. I just want to read the table after the ~A. > > > ~Version Information > VERS. 2.00: CWLS log ASCII Standard -VERSION 2.00 > WRAP. NO: One line per depth step > # > # > ~Well Information Block > #MNEM.UNIT Data Type Description > #--------- ----------- ---------------- > STRT.M 51.000 :START DEPTH > STOP.M .010 :STOP DEPTH > STEP.M -.010 :STEP > # > # > ~Curve Information Block > #MNEM.UNIT Curve Description > #--------- ----------------------------- > DEPT.M :DEPTH > GRDE.GAPI :GAMMA FROM DENSITY TOOL > CODE.G/C3 :COMPENSATED DENSITY > # > > # > # > ~A Depth GRDE CODE LSDU BRDU CADE DENL DENB ADEN VL2F VL4F VL6F VL2A > 51.000 -999.25 -999.25 -999.25 -999.25 -999.25 -999.25 -999.25 -999.25 -999.25 -999.25 -999.25 -999.25 > 50.990 -999.25 -999.25 -999.25 -999.25 -999.25 -999.25 -999.25 -999.25 -999.25 -999.25 -999.25 -999.25 > 50.980 -999.25 -999.25 -999.25 -999.25 -999.25 -999.25 -999.25 -999.25 -999.25 -999.25 -999.25 -999.25 > 50.970 -999.25 -999.25 -999.25 -999.25 -999.25 -999.25 -999.25 -999.25 -999.25 -999.25 -999.25 -999.25 > 50.960 -999.25 -999.25 -999.25 -999.25 -999.25 -999.25 -999.25 -999.25 -999.25 -999.25 -999.25 -999.25 > 50.950 -999.25 -999.25 -999.25 -999.25 -999.25 -999.25 -999.25 -999.25 -999.25 -999.25 -999.25 -999.25 > 50.940 -999.25 -999.25 -999.25 -999.25 -999.25 -999.25 -999.25 -999.25 -999.25 -999.25 -999.25 -999.25 > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.
Weidong Gu
2011-Aug-31 13:15 UTC
[R] reading data from multiple files with multiple headers
If you know how many lines to skip, you can set skip=xx in read.table. The question is what you can do if you have variable lines to skip in various files but you have characters indicating the begining of the data, like ~A. What you can do is get the file in using readLines, use grep to find the line where the character locates. Then, you can specify skip in read.table to input your data. HTH Weidong Gu On Tue, Aug 30, 2011 at 10:23 PM, Julius Tesoro <jutesoro at yahoo.com> wrote:> Dear All, > > > I have many files with a lot of headers and text at the beginning of the file. The headers are not uniform though and they contain different sizes Is there a way where I can read a table and skip all of the headers/text on top of it until I encounter a certain text pattern? Here is an example. I just want to read the table after the ~A. > > > ~Version Information > ?VERS.????????????? 2.00:???? CWLS log ASCII Standard -VERSION 2.00 > ?WRAP.??????????????? NO:???? One line per depth step > # > # > ~Well Information Block > #MNEM.UNIT???? Data Type????????????????????? Description > #---------???? -----------??????????????????? ---------------- > ?STRT.M???????????? 51.000??????????????????? :START DEPTH > ?STOP.M?????????????? .010??????????????????? :STOP DEPTH > ?STEP.M????????????? -.010??????????????????? :STEP > # > # > ~Curve Information Block > #MNEM.UNIT??????????????????????? Curve Description > #---------??????????????????????? ----------------------------- > ?DEPT.M?????????????????????????? :DEPTH > ?GRDE.GAPI??????????????????????? :GAMMA FROM DENSITY TOOL > ?CODE.G/C3??????????????????????? :COMPENSATED DENSITY > # > > # > # > ~A? Depth?????? GRDE?????? CODE?????? LSDU?????? BRDU?????? CADE?????? DENL?????? DENB?????? ADEN?????? VL2F?????? VL4F?????? VL6F?????? VL2A > ??? 51.000??? -999.25??? -999.25??? -999.25??? -999.25??? -999.25??? -999.25??? -999.25??? -999.25??? -999.25??? -999.25??? -999.25??? -999.25 > ??? 50.990??? -999.25??? -999.25??? -999.25??? -999.25??? -999.25??? -999.25??? -999.25??? -999.25??? -999.25??? -999.25??? -999.25??? -999.25 > ??? 50.980??? -999.25??? -999.25??? -999.25??? -999.25??? -999.25??? -999.25??? -999.25??? -999.25??? -999.25??? -999.25??? -999.25??? -999.25 > ??? 50.970??? -999.25??? -999.25??? -999.25??? -999.25??? -999.25??? -999.25??? -999.25??? -999.25??? -999.25??? -999.25??? -999.25??? -999.25 > ??? 50.960??? -999.25??? -999.25??? -999.25??? -999.25??? -999.25??? -999.25??? -999.25??? -999.25??? -999.25??? -999.25??? -999.25??? -999.25 > ??? 50.950??? -999.25??? -999.25??? -999.25??? -999.25??? -999.25??? -999.25??? -999.25??? -999.25??? -999.25??? -999.25??? -999.25??? -999.25 > ??? 50.940??? -999.25??? -999.25??? -999.25??? -999.25??? -999.25??? -999.25??? -999.25??? -999.25??? -999.25??? -999.25??? -999.25??? -999.25 > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >