Learn R Programming

rquery (version 0.2.0)

extend_se: Extend data by adding more columns.

Description

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

Usage

extend_se(source, assignments, ..., partitionby = NULL, orderby = NULL,
  desc = FALSE, env = parent.frame())

Arguments

source

source to select from.

assignments

new column assignment expressions.

...

force later arguments to bind by name

partitionby

partitioning (window function) terms.

orderby

ordering (window function) terms.

desc

reverse order

env

environment to look for values in.

Value

extend node.

Details

Allows re-use of column names in the spirit of partition_mutate_se, though re-use can break relational property. partitionby and orderby can only be used with a database that supports window-functions (such as PostgreSQL).

Examples

Run this code
# NOT RUN {
my_db <- DBI::dbConnect(RSQLite::SQLite(), ":memory:")
d <- dbi_copy_to(my_db, 'd',
                data.frame(AUC = 0.6, R2 = 0.2))
eqn <- extend_se(d, c("v" := "AUC + R2", "x" := "pmax(AUC,v)"))
cat(format(eqn))
sql <- to_sql(eqn, my_db)
cat(sql)
DBI::dbGetQuery(my_db, sql)

# SQLite can not run the following query
eqn2 <- extend_se(d, "v" := "rank()",
              partitionby = "AUC", orderby = "R2")
sql2 <- to_sql(eqn2, my_db)
cat(sql2)

DBI::dbDisconnect(my_db)

# }

Run the code above in your browser using DataLab