Last active
August 24, 2016 00:26
-
-
Save mndrake/16dba08498fd371cd7806ddc63d01199 to your computer and use it in GitHub Desktop.
extension methods for dplyr remote tables
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(dplyr) | |
library(nycflights13) | |
conn <- nycflights13_sqlite() | |
flights_sql <- tbl(conn, 'flights') | |
weather_sql <- tbl(conn, 'weather') | |
`[.tbl_sql` <- function(x, condition) { | |
x %>% select_(condition) | |
} | |
sum.tbl_sql <- function(x, na.rm = FALSE) { | |
names <- colnames(x) | |
if (length(names) > 1) { | |
stop("sum needs a single column for remote tables") | |
} | |
x %>% rename_(x = as.name(names[1])) %>% summarize(sum(x)) %>% collect %>% as.numeric | |
} | |
sum(flights_sql['dep_delay']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment