R – Appropriate data structure for flat file processing

data structuresflat-file

Essentially, I have to get a flat file into a database. The flat files come in with the first two characters on each line indicating which type of record it is.

Do I create a class for each record type with properties matching the fields in the record? Should I just use arrays?

I want to load the data into some sort of data structure before saving it in the database so that I can use unit tests to verify that the data was loaded correctly.

Here's a sample of what I have to work with (BAI2 bank statements):

01,121000358,CLIENT,050312,0213,1,80,1,2/

02,CLIENT-STANDARD,BOFAGB22,1,050311,2359,,/

03,600812345678,GBP,fab1,111319005,,V,050314,0000/

88,fab2,113781251,,V,050315,0000,fab3,113781251,,V,050316,0000/

88,fab4,113781251,,V,050317,0000,fab5,113781251,,V,050318,0000/

88,010,0,,,015,0,,,045,0,,,100,302982205,,,400,302982205,,/

16,169,57626223,V,050311,0000,102 0101857345,/

88,LLOYDS TSB BANK PL 779300 99129797

88,TRF/REF 6008ABS12300015439

88,102 0101857345 K BANK GIRO CREDIT

88,/IVD-11 MAR

49,1778372829,90/

98,1778372839,1,91/

99,1778372839,1,92

Best Answer

I'd recommend creating classes (or structs, or what-ever value type your language supports), as

record.ClientReference

is so much more descriptive than

record[0]

and, if you're using the (wonderful!) FileHelpers Library, then your terms are pretty much dictated for you.

Related Topic