This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Error in writing a file from R

Hello,

I have a list in R, which I need to write into a file. When I try running write.table(data, file="molecules.txt"), I get the following error -

Error in (function (..., row.names = NULL, check.rows = FALSE, check.names = TRUE,  : 
  arguments imply differing number of rows: 1, 5, 547

Could someone please help me understand the error and how to go about solving it?

Thanks.

r write.table

1 answer

Try write.table(unlist(data), file="molecules.txt")

That solved the problem. Could you please explain to me what the error was?

You said your input is list, however write.table requires vector, data frame or data table. That is why you get an error (I assume). To write as list you can use write.list function which i have not used so far.

Log in to answer this question.