Re: [Rd] [R] read.csv behaviour

From: Jim Lemon <>
Date: Wed, 28 Sep 2011 20:17:20 +1000

On 09/28/2011 09:23 AM, Mehmet Suzen wrote:
> This might be obvious but I was wondering if anyone knows quick and easy
> way of writing out a CSV file with varying row lengths, ideally an
> initial data read from a CSV file which has the same format. See example
> below.
> I found it quite strange that R cannot write it in one go, so one must
> append blocks or post-process the file, is this true? (even Ruby can do
> it!!)
> Otherwise it puts ,"","" or similar for missing column values in the
> shorter length rows and fill=FALSE option do not work!
> I don't want to post-process if possible.
> See this post:
> Example that generated Error!
> writeLines(c("A,B,C,D",
> "1,a,b,c",
> "2,f,g,c",
> "3,a,i,j",
> "4,a,b,c",
> "5,d,e,f",
> "6,g,h,i,j,k,l,m,n"),
> con=file("test.csv"))
> read.csv("test.csv")
> try(read.csv("test.csv",fill=FALSE))

Hi Mehmet,
The example doesn't need to call "file", writeLines does it for you. It worked for me:


and to get the original object back, use:


The reason you can't use read.csv is that it returns a data frame, and that object can't have elements of unequal length. If you want an object with elements of unequal length, try:


Jim mailing list Received on Wed 28 Sep 2011 - 11:48:10 GMT

This quarter's messages: by month, or sorted: [ by date ] [ by thread ] [ by subject ] [ by author ]

All messages

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 28 Sep 2011 - 19:40:36 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.

list of date sections of archive