0

I want to text a .txt file in R but I keep getting an embedded null error.

I have tried this code:

text_df = read.delim2(testfile, header = TRUE, sep = ',')

The original file ("testfile") looks like this:

UPC,HSY Item Description,Hsy Seasonal Segmentation,Store Nbr,Store Name,Building City,Building State/Prov,Building Postal Code,Store Type,WM Date,SeasonAndYear,OH_Qty,POS_Qty,POS_Sales
"0001070006638","Whprs Rbn Egg 13.75OZ","EAS $2.98 Candy Dish",1,"ROGERS, AR","ROGERS","AR","72756","Supercenter",1/27/2018 12:00:00 AM,"EAS2018",0,0,0.0000
"0001070006638","Whprs Rbn Egg 13.75OZ","EAS $2.98 Candy Dish",1,"ROGERS, AR","ROGERS","AR","72756","Supercenter",1/30/2018 12:00:00 AM,"EAS2018",0,0,0.0000
"0001070006638","Whprs Rbn Egg 13.75OZ","EAS $2.98 Candy Dish",1,"ROGERS, AR","ROGERS","AR","72756","Supercenter",2/2/2018 12:00:00 AM,"EAS2018",0,0,0.0000

I keep getting this error:

Warning messages: 1: In read.table(file = file, header = header, sep = sep, quote = quote, : line 1 appears to contain embedded nulls 2: In read.table(file = file, header = header, sep = sep, quote = quote, : line 2 appears to contain embedded nulls 3: In read.table(file = file, header = header, sep = sep, quote = quote, : line 3 appears to contain embedded nulls 4: In read.table(file = file, header = header, sep = sep, quote = quote, : line 4 appears to contain embedded nulls 5: In read.table(file = file, header = header, sep = sep, quote = quote, : line 5 appears to contain embedded nulls 6: In scan(file = file, what = what, sep = sep, quote = quote, dec = dec, : embedded nul(s) found in input

DJV
  • 4,743
  • 3
  • 19
  • 34

1 Answers1

0

Try this:

df = read.table(yourFile, quote = '"', sep = ",", header = T)

This should treat the comma inside "ROGERS, AR" as part of the string and not as a separator.

R. Schifini
  • 9,085
  • 2
  • 26
  • 32