Tag Archives: r

When your write.csv won’t write

Today I learned that:

  • A column in a data frame can actually be a list even if it looks nice when you peek at it with head() and tail()
  • If you take this data frame and try to write it to a csv file using write.csv, you’re probably going to get an error like this in mean red letters:

Error in .External2(C_writetable, x, file, nrow(x), p, rnames, sep, eol, :
unimplemented type ‘list’ in ‘EncodeElement’

To avoid this, you should first check the data type for each column:

sapply(df, class)

Use unlist() or similar to fix the offending columns. This should fix the problem and write.csv() will happily dump your data as requested.