Unlimited learning, half price | 50% off
Get 50% off unlimited learning

rquery (version 0.2.0)

orderby: Make an orderby node (not a relational operation).

Description

Order a table by a set of columns (not general expressions) and limit number of rows in that order.

Usage

orderby(source, orderby, ..., desc = FALSE, limit = NULL)

Arguments

source

source to select from.

orderby

order by column names.

...

force later arguments to be bound by name

desc

logical if TRUE reverse order

limit

number limit row count.

Value

select columns node.

Details

Note: this is a relational operator in that it takes a table that is a relation (has unique rows) to a table that is still a relation. However, most relational systems do not preserve row order in storage or between operations. So without the limit set this is not a useful operator except as a last step prior ot pulling data to an in-memory data.frame ( which does preserve row order).

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 <- orderby(d, "AUC", desc=TRUE, limit=4)
cat(format(eqn))
sql <- to_sql(eqn, my_db)
cat(sql)
DBI::dbGetQuery(my_db, sql)
DBI::dbDisconnect(my_db)

# }

Run the code above in your browser using DataLab