rquery (version 1.4.6)

affine_transform: Implement an affine transformaton

Description

Implement an affine transformaton

Usage

affine_transform(source, linear_transform, offset, ..., env = parent.frame())

Arguments

source

relop source (or data.frame source)

linear_transform

matrix with row names taken from source column names (inputs), and column names are outputs.

offset

vector of offsets with names same as column names of linear_transform.

...

force later arguments to bind by name

env

environment to look for values in.

Value

relop node

Examples

Run this code
# NOT RUN {
if (requireNamespace("DBI", quietly = TRUE) &&
    requireNamespace("RSQLite", quietly = TRUE)) {
  my_db <- DBI::dbConnect(RSQLite::SQLite(), ":memory:")
  d <- data.frame(AUC = 0.6, R2 = 0.2)
  source <- rq_copy_to(my_db, 'd',
                       d,
                       overwrite = TRUE,
                       temporary = TRUE)
  linear_transform <- matrix(c(1 ,1, 2, -1, 1, 0, 0, 0), nrow = 2)
  rownames(linear_transform) <- c("AUC", "R2")
  colnames(linear_transform) <- c("res1", "res2", "res3", "res4")
  offset <- c(5, 7, 1, 0)
  names(offset) <- colnames(linear_transform)

  optree <- affine_transform(source, linear_transform, offset)
  cat(format(optree))

  sql <- to_sql(optree, my_db)
  cat(sql)

  print(DBI::dbGetQuery(my_db, sql))
  print(as.matrix(d) %*% linear_transform + offset)

  DBI::dbDisconnect(my_db)
}

# }

Run the code above in your browser using DataLab