Learn R Programming

rquery (version 0.5.0)

project_nse: project data by grouping, and adding aggregate columns.

Description

project data by grouping, and adding aggregate columns.

Usage

project_nse(source, groupby, ..., env = parent.frame())

Arguments

source

source to select from.

groupby

grouping columns.

...

new column assignment expressions.

env

environment to look for values in.

Value

project node.

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(group = c('a', 'a', 'b', 'b'),
               val = 1:4,
               stringsAsFactors = FALSE))

  op_tree <- d %.>%
    project_nse(., groupby = "group", vmax %:=% max(val))
  cat(format(op_tree))
  sql <- to_sql(op_tree, my_db)
  cat(sql)
  execute(my_db, op_tree) %.>%
     print(.)

  op_tree <- d %.>%
    project_nse(., groupby = NULL, vmax %:=% max(val))
  cat(format(op_tree))
  sql <- to_sql(op_tree, my_db)
  cat(sql)
  execute(my_db, op_tree) %.>%
    print(.)

  DBI::dbDisconnect(my_db)
}

# }

Run the code above in your browser using DataLab