R/ex_data_frame.R
rquery_apply_to_data_frame.Rd
Default DB uses RSQLite (so some functions are not supported).
rquery_apply_to_data_frame( d, optree, ..., limit = NULL, source_limit = NULL, allow_executor = TRUE, env = parent.frame() )
d | data.frame or named list of data.frames. |
---|---|
optree | rquery rel_op operation tree. |
... | force later arguments to bind by name. |
limit | integer, if not NULL limit result to no more than this many rows. |
source_limit | numeric if not NULL limit sources to this many rows. |
allow_executor | logical if TRUE allow any executor set as rquery.rquery_executor to be used. |
env | environment to look to. |
data.frame result
# WARNING: example tries to change rquery.rquery_db_executor option to RSQLite and back. if (requireNamespace("DBI", quietly = TRUE) && requireNamespace("RSQLite", quietly = TRUE)) { db <- DBI::dbConnect(RSQLite::SQLite(), ":memory:") RSQLite::initExtension(db) old_o <- options(list("rquery.rquery_db_executor" = list(db = db))) optree <- mk_td("d", c("AUC", "R2", "D")) %.>% extend(., c %:=% sqrt(R2)) %.>% orderby(., cols = "R2", reverse = "R2") d <- data.frame(AUC = 0.6, R2 = c(0.1, 0.2), D = NA, z = 2) v <- rquery_apply_to_data_frame(d, optree) print(v) # now load up a table without an R2 column, # want to show this is caught d <- data.frame(z = 1) tryCatch( rquery_apply_to_data_frame(d, optree), error = function(e) { as.character(e) } ) %.>% print(.) options(old_o) DBI::dbDisconnect(db) }#> AUC R2 D c #> 1 0.6 0.2 NA 0.4472136 #> 2 0.6 0.1 NA 0.3162278 #> [1] "Error in rquery_apply_to_data_frame(d, optree): rquery::rquery_apply_to_data_frame d missing required columns: AUC, R2, D\n"