Skip to content

Commit

Permalink
Adds optional usage of dplyr::bind_rows() or data.table::rbindlist().
Browse files Browse the repository at this point in the history
Signed-off-by: Aaron Jacobs <[email protected]>
  • Loading branch information
atheriel committed May 15, 2019
1 parent 7d37129 commit 98832aa
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
4 changes: 3 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ Roxygen: list(markdown = TRUE)
Suggests:
spelling,
nycflights13,
ggplot2
ggplot2,
data.table,
dplyr
Language: en-GB
Encoding: UTF-8
14 changes: 10 additions & 4 deletions R/stream.R
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,16 @@ mongo_stream_in <- function(cur, handler = NULL, pagesize = 1000, verbose = TRUE
out <- as.list(out, sorted = FALSE)
out <- out[order(as.numeric(names(out)))]
if (flat) {
out <- lapply(out, as.data.frame, stringsAsFactors = FALSE)
out <- do.call("rbind", out)
# Alternatively:
# out <- data.table::rbindlist(out)
if (requireNamespace("dplyr", quietly = TRUE)) {
out <- dplyr::bind_rows(out)
} else if (requireNamespace("data.table", quietly = TRUE)) {
out <- data.table::rbindlist(out, fill = TRUE)
} else {
# TODO: This is much, much slower. We might consider bundling an
# rbindlist implementation suited to the inputs instead.
out <- lapply(out, as.data.frame, stringsAsFactors = FALSE)
out <- do.call("rbind", out)
}
# For compatibility with jsonlite:::simplifyDataFrame():
attr(out, "row.names") <- seq_len(nrow(out))
out
Expand Down

0 comments on commit 98832aa

Please sign in to comment.