Die source code zeigt, wo die Probleme
mongo.cursor.to.data.frame <- function(cursor, nullToNA=TRUE, ...){
warning("This fails for most NoSQL data structures. I am working on a new solution")
res <- data.frame()
while (mongo.cursor.next(cursor)){
val <- mongo.bson.to.list(mongo.cursor.value(cursor))
if(nullToNA == TRUE)
val[sapply(val, is.null)] <- NA
# remove mongo.oid -> data.frame can not deal with that!
val <- val[sapply(val, class) != 'mongo.oid']
res <- rbind.fill(res, as.data.frame(val, ...))
}
return(as.data.frame(res))
}
Wir es plyr::rbind.fill
-rbind
data.frames ist mit sehen entstehen könnten. Also das alles kommt auf, was in rbind.fill
, nämlich val
übergeben wird.
Und val
ist das Ergebnis von val <- mongo.bson.to.list(mongo.cursor.value(cursor))
.
So lange wie as.data.frame(val, ...)
die Listenstruktur behandeln können, gehen Sie hinein, Sie sind in Ordnung.
Allerdings ist es ganz einfach, eine NoSQL Datenstruktur zu begreifen, dass dies nicht gelingen wird:
## consider the JSON structure
## [{"a":[1,2,3],"b":["a","b","c"]},{"d":[1.1,2.2,3.3],"e":[["nested","list"]]}]
##Which in R is the same as
lst = list(list(a = c(1L,2L,3L),
b = c("a","b","c")),
list(d = c(1.1, 2.2, 3.3),
e = list(c("nested", "list"))))
## this errors when coerced to a data.frame
as.data.frame(lst)
Error in data.frame(d = c(1.1, 2.2, 3.3), e = list(c("nested", "list")), :
arguments imply differing number of rows: 3, 2
An diesem Punkt ist soll ich das mongolite
Paket erwähnen, die in der Regel schneller ist, aber wieder gibt eine data.frame
zurück.
Und es gibt auch meine Erweiterung mongolite, mongolitedt
(noch nicht auf CRAN), die schneller ist immer noch und das Abrufen von Daten, aber auch hier durch das Ergebnis begrenzt wird, hat in ein data.table
gezwungen werden