Learn R Programming

rquery (version 0.5.0)

extend_nse: Extend data by adding more columns.

Description

Create a node similar to a Codd extend relational operator (add derived columns).

Usage

extend_nse(source, ..., partitionby = NULL, orderby = NULL,
  reverse = NULL, env = parent.frame())

Arguments

source

source to select from.

...

new column assignment expressions.

partitionby

partitioning (window function) terms.

orderby

ordering (in window function) terms.

reverse

reverse ordering (in window function) terms.

env

environment to look for values in.

Value

extend node.

Details

Partitionby and orderby can only be used with a database that supports window-functions (such as PostgreSQL).

Examples

Run this code
# NOT RUN {
if (requireNamespace("DBI", quietly = TRUE) && requireNamespace("RSQLite", quietly = TRUE)) {
  my_db <- DBI::dbConnect(RSQLite::SQLite(), ":memory:")
  d <- rq_copy_to(my_db, 'd',
                   data.frame(AUC = 0.6, R2 = 0.2))
  optree <- extend_nse(d, v %:=% ifelse(AUC>0.5, R2, 1.0))
  cat(format(optree))
  sql <- to_sql(optree, my_db)
  cat(sql)
  print(DBI::dbGetQuery(my_db, sql))
  DBI::dbDisconnect(my_db)
}

# }

Run the code above in your browser using DataLab