0

I am looping through hundreds of csv files and reading them into r data frames (read.csv()). Some of the csv files are missing an end of line (EOL) character. This produces the error, "incomplete final line found by readTableHeader." After getting this error, I don't get the any of the desired data from that csv.

The following steps fix the problem for a single csv: 1. Open the file 2. Navigate to the very last line of the file 3. Place the cursor the end of that line 4. Press return 5. Save the file

HOWEVER, I need to incorporate this methodology into my loop. I have 100+ files formatted like the example below (only a few are returning this error). I cannot go to every csv and fix with the aforementioned steps. Any recommendations?

Function used to read table: AdamTurb <- read.csv("myfile.csv")

This is the contents of myfile.csv: OrganizationIdentifier,OrganizationFormalName,ActivityIdentifier,ActivityTypeCode,ActivityMediaName,ActivityMediaSubdivisionName,ActivityStartDate,ActivityStartTime/Time,ActivityStartTime/TimeZoneCode,ActivityEndDate,ActivityEndTime/Time,ActivityEndTime/TimeZoneCode,ActivityDepthHeightMeasure/MeasureValue,ActivityDepthHeightMeasure/MeasureUnitCode,ActivityDepthAltitudeReferencePointText,ActivityTopDepthHeightMeasure/MeasureValue,ActivityTopDepthHeightMeasure/MeasureUnitCode,ActivityBottomDepthHeightMeasure/MeasureValue,ActivityBottomDepthHeightMeasure/MeasureUnitCode,ProjectIdentifier,ActivityConductingOrganizationText,MonitoringLocationIdentifier,ActivityCommentText,SampleAquifer,HydrologicCondition,HydrologicEvent,SampleCollectionMethod/MethodIdentifier,SampleCollectionMethod/MethodIdentifierContext,SampleCollectionMethod/MethodName,SampleCollectionEquipmentName,ResultDetectionConditionText,CharacteristicName,ResultSampleFractionText,ResultMeasureValue,ResultMeasure/MeasureUnitCode,MeasureQualifierCode,ResultStatusIdentifier,StatisticalBaseCode,ResultValueTypeName,ResultWeightBasisText,ResultTimeBasisText,ResultTemperatureBasisText,ResultParticleSizeBasisText,PrecisionValue,ResultCommentText,USGSPCode,ResultDepthHeightMeasure/MeasureValue,ResultDepthHeightMeasure/MeasureUnitCode,ResultDepthAltitudeReferencePointText,SubjectTaxonomicName,SampleTissueAnatomyName,ResultAnalyticalMethod/MethodIdentifier,ResultAnalyticalMethod/MethodIdentifierContext,ResultAnalyticalMethod/MethodName,MethodDescriptionText,LaboratoryName,AnalysisStartDate,ResultLaboratoryCommentText,DetectionQuantitationLimitTypeName,DetectionQuantitationLimitMeasure/MeasureValue,DetectionQuantitationLimitMeasure/MeasureUnitCode,PreparationStartDate,ProviderName NARS_WQX,EPA National Aquatic Resources Survey,NARS_WQX-QWCH:0452:1:070615:P,Sample-Routine,Water,,2007-06-15,00:00:00,,,,,,,,,,,,NARS_NLA2007;NARS_NLA2007_ECOREGION_SPL,,NARS_WQX-NLA06608-0452,"VISIT_NO=""1"";SAMPLE_CATEGORY=""P"";INDXSAMP_CHEM=""YES"";SAMPLE_DEPTH=""2"";SAMPLE_ID_CHEM=""502231"";LAB_ID_CHEM=""0710049"";COMMENT_LAB_CHEM=""Live creatures in unfiltered sample."";DATE_FILTERED=""2007-06-16"";DATE_RECEIVED=""2007-06-16"";DATEFILT_ALERT=""N"";DATECHEM=""2007-06-15""",,,,2meterMPCA,NARS_WQX,Integrated water sampler,Water Sampler (Other),,Turbidity,,3.59,NTU,,Final,,Actual,,,,,,"TURB_HT_ALERT=""N"";TURB_HT=""3"";TURB_RL_ALERT=""N""",,,,,,,,,,,,,,,,,,STORET NARS_WQX,EPA National Aquatic Resources Survey,NARS_WQX-QWCH:1083:1:070629:P,Sample-Routine,Water,,2007-06-29,00:00:00,,,,,,,,,,,,NARS_NLA2007;NARS_NLA2007_ECOREGION_SPL,,NARS_WQX-NLA06608-1083,"VISIT_NO=""1"";SAMPLE_CATEGORY=""P"";INDXSAMP_CHEM=""YES"";SAMPLE_DEPTH=""1.2"";SAMPLE_ID_CHEM=""503301"";LAB_ID_CHEM=""0710174"";DATE_FILTERED=""2007-06-30"";DATE_RECEIVED=""2007-06-30"";DATEFILT_ALERT=""N"";DATECHEM=""2007-06-29""",,,,2meterMPCA,NARS_WQX,Integrated water sampler,Water Sampler (Other),,Turbidity,,27.6,NTU,,Final,,Actual,,,,,,"TURB_HT_ALERT=""N"";TURB_HT=""3"";TURB_RL_ALERT=""N""",,,,,,,,,,,,,,,,,,STORET

Thanks!

Zmrkr
  • 1
  • 2
  • Can you provide a minimal csv file that will produce the error and the code to produce it? – effel Mar 08 '16 at 13:54
  • 1
    I guess it produces a warning (not an error), which warns you that the file may be incomplete. But you know it isn't. So just ignore it? You can also suppress the warnings by wrapping `read.table` in `suppressWarnings`. – lukeA Mar 08 '16 at 13:56
  • Possible duplicate of ['Incomplete final line' warning when trying to read a .csv file into R](http://stackoverflow.com/questions/5990654/incomplete-final-line-warning-when-trying-to-read-a-csv-file-into-r) – user5249203 Mar 08 '16 at 14:18

0 Answers0