0

Currently i am working with twite data for what i am using the rtweet package. However when i want to save my data i got a poblem with it.

I use the following code to get my data:

Data1 <- get_timeline("Account1", n = 3200)

Data2 <- get_timeline("Account2", n = 3200)

Data3 <- get_timeline("Account2", n = 3200)

timelines <- dplyr::bind_rows(Data1, Data2, Data3)

write_csv(timelines, path = paste("./Data/Account_tweets_", Sys.Date(), ".csv", sep=""))

The error I recieve is as following:

Error in stream_delim_(df, path, ..., bom = bom, quote_escape = quote_escape) : Don't know how to handle vector of type list.

Can someone help me?

mischva11
  • 2,811
  • 3
  • 18
  • 34

2 Answers2

2

Seems like you have a list column in your data, and write_csv doesn't handle list columns. CSVs are flat, and embedded lists are not. As for options to proceed, either

  • flatten your data structure with, e.g., tidyr::unnest() before writing to CSV
  • or write to a different data structure. If you only need R to read them, I'd suggest base::saveRDS. If you need them to be portable, perhaps jsonlite::writeJSON.

Googling your error leads directly to this closed issue on the readr repository. In this linked discussion it sounds like there are not plans to enable list columns for CSV, as it's not generally clear how they should be handled.

Gregor Thomas
  • 136,190
  • 20
  • 167
  • 294
2

There is a specific function in the rTweet package write_as_csv : https://rdrr.io/cran/rtweet/man/write_as_csv.html

rtweet::write_as_csv(timelines, file_name = paste("./Data/Account_tweets_", Sys.Date(), ".csv", sep=""))

EDIT - my bad, I was too quick. It is file_name and not path that you should use

cyrilb38
  • 924
  • 6
  • 17