Importing csv file to R new line issue

2019-01-28 06:09发布

问题:

I have a csv file which has a text field that contains new line character '\n', so i cannot correctly import this file into R. My csv end of line is actually '\r\n' and I want R to use it as end of line, how I can do this?

Thanks

EDIT:

It seems R is ignoring my new line character in some records. An example is:

data[48,]

Var1   Var2   Var3 

 345   blue    N 

data[49,]

Var1   Var2   Var3

 634    red    N\n821,green,

where data[50,] should start with 821,green

I am using allowEscapes=TRUE.

回答1:

In a lot of csv handling implementations, you have to escape fields that have \n and other such codes, usually with quotes or double-quotes. Such as 'this is\nan example'