ソースコードは、問題が発生する可能性がある場所を示しています
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) )
}
data.framesを使用plyr::rbind.fill
していることがわかります。rbind
したがって、これはすべて、 に渡されるものrbind.fill
、つまり に帰着しval
ます。
そしてval
の結果ですval <- mongo.bson.to.list(mongo.cursor.value(cursor))
。
as.data.frame(val, ...)
したがって、渡すリスト構造を処理できる限り、問題ありません。
ただし、これに失敗するNoSQLデータ構造を想像するのは非常に簡単です。
## 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
この時点で、mongolite
パッケージについて言及する必要があります。これは一般的に高速ですが、再びdata.frame
.
また、mongolite への私の拡張機能もありますmongolitedt
(まだ CRAN にはありません)。これはさらに高速でデータを取得しますが、結果によって制限されます。data.table