medavis6 medavis6 - 1 year ago 143
R Question

List of Data Frames to One Data Frame

Disclaimer: I know that this question has been asked before. The answer provided in this answer worked for me in the past, but for some reason has stopped now.

I am pulling Marketing email statistics from the Mailchimp API. I have been doing this for the last half year or so. However, in the past 2 months, I believe the structure of what I pull has changed and thus, my code no longer works and I cannot figure out why. I believe it has something to do with the nested data frames within my list of data frames that I receive.

Here is an example of my code and the resulting list of data frames. I have removed sensitive information from my code and image:


opens1 <- GET("***ReportNumber***/sent-to?count=4000",authenticate('***My Company***', '***My-Password***'))
opens1 <- content(opens1,"text")
opens1 <- fromJSON(opens1)

enter image description here

Then I run
opens1 <- ldply(opens1, data.frame)
, and I receive the following error:

Error in allocate_column(df[[var]], nrows, dfs, var) :
Data frame column 'merge_fields' not supported by rbind.fill

I tried using and looking up
and the other methods described in the linked answer at the top of my post, to no avail. What am I interpreting incorrectly about the
variable, or am I way off, and how do I correct it?

I'm just trying to get one data frame of all of the variables from the

Thanks for any and all help, and please, feel free to ask any clarification questions!

Answer Source

On a quick glance, this seems to work for me:

campaign_id <- "-------"
apikey = "------"
url <- sprintf("", campaign_id)
opens <- GET(url, query = list(apikey = apikey, count = 4000L))
lst <- rjson::fromJSON(content(opens, "text"))
df <- dplyr::bind_rows(
  lapply(lst$sent_to, function(x), stringsAsFactors = F)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download