Created
February 28, 2019 20:47
-
-
Save rkingdc/19107d1140e87a5bd0461e6c62a8724b to your computer and use it in GitHub Desktop.
Binning Columns in Remote Tables: make rquery function
This file contains 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
.make_db_rquery_join_fn <- function(data, tbl_cuts, db=db, column_to_cut = 'column_to_cut'){ | |
# test rquery connection options | |
dbopts <- rquery::rq_connection_tests(db) | |
# create rquery option connection | |
rqdb <- rquery::rquery_db_info(connection = db, | |
is_dbi = TRUE, | |
connection_options = dbopts) | |
bin_choices <- data %.>% | |
rquery::select_columns(., c("id", as.character(column_to_cut), 'k_dummy')) %.>% | |
rquery::natural_join(., tbl_cuts, jointype = "LEFT", by = 'k_dummy') %.>% | |
rquery::select_rows_se(., qe(cut >= column_to_cut)) %.>% | |
rquery::project(., groupby = "id", cut_ = min(cut)) | |
annotation_ops <- rquery::natural_join(data, bin_choices, jointype = "LEFT", by = "id") | |
FUN = function(){ | |
# oprtation will function as long as table and column names are the same | |
# it's even database agnostic | |
rquery::materialize(db = rqdb, optree = annotation_ops) | |
} | |
return(FUN) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment