rquery_apply_to_data_frame: Execute optree in an environment where d is the only data.

View source: R/ex_data_frame.R

rquery_apply_to_data_frameR Documentation

Execute optree in an environment where d is the only data.

Description

Default DB uses RSQLite (so some functions are not supported).

Usage

rquery_apply_to_data_frame(
  d,
  optree,
  ...,
  limit = NULL,
  source_limit = NULL,
  allow_executor = TRUE,
  env = parent.frame()
)

Arguments

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.

Value

data.frame result

Examples


# 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)
}


rquery documentation built on Aug. 20, 2023, 9:06 a.m.