nealrichardson commented on a change in pull request #11032:
URL: https://github.com/apache/arrow/pull/11032#discussion_r727896513
##########
File path: r/R/duckdb.R
##########
@@ -118,3 +118,50 @@ duckdb_disconnector <- function(con, tbl_name) {
})
environment()
}
+
+#' Create an Arrow object from others
+#'
+#' This can be used in pipelines that pass data back and forth between Arrow
and
+#' other processes (like DuckDB).
+#'
+#' @param .data the object to be converted
+#'
+#' @return an `arrow_dplyr_query` object, to be used in dplyr pipelines.
+#' @export
+#'
+#' @examplesIf getFromNamespace("run_duckdb_examples", "arrow")()
+#' library(dplyr)
+#'
+#' ds <- InMemoryDataset$create(mtcars)
+#'
+#' ds %>%
+#' filter(mpg < 30) %>%
+#' to_duckdb() %>%
+#' group_by(cyl) %>%
+#' summarize(mean_mpg = mean(mpg, na.rm = TRUE)) %>%
+#' to_arrow() %>%
+#' collect()
+to_arrow <- function(.data) {
+ # If this is an Arrow object already, return quickly since we're already
Arrow
+ is_adq <- inherits(.data, "arrow_dplyr_query")
+ is_arrow_tabular <- inherits(.data, "ArrowObject") & inherits(.data,
c("Dataset", "ArrowTabular"))
+ if (is_adq | is_arrow_tabular) {
Review comment:
```suggestion
if (inherits(.data, c("arrow_dplyr_query", "ArrowObject")) {
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]