arrange.tbl_lazy {dbplyr}R Documentation

Arrange rows by variables in a remote database table

Description

Order rows of database tables by an expression involving its variables.

Usage

## S3 method for class 'tbl_lazy'
arrange(.data, ..., .by_group = FALSE)

Arguments

.data

A data frame, data frame extension (e.g. a tibble), or a lazy data frame (e.g. from dbplyr or dtplyr). See Methods, below, for more details.

...

Variables, or functions or variables. Use desc() to sort a variable in descending order.

.by_group

If TRUE, will sort first by grouping variable. Applies to grouped data frames only.

Value

An object of the same class as .data.

Missing values

Compared to its sorting behaviour on local data, the arrange() method for most database tables sorts NA at the beginning unless wrapped with desc(). Users can override this behaviour by explicitly sorting on is.na(x).

Examples

library(dplyr)

dbplyr::memdb_frame(a = c(3, 4, 1, 2)) %>%
  arrange(a)

# NA sorted first
dbplyr::memdb_frame(a = c(3, 4, NA, 2)) %>%
  arrange(a)

# override by sorting on is.na() first
dbplyr::memdb_frame(a = c(3, 4, NA, 2)) %>%
  arrange(is.na(a), a)


[Package dbplyr version 1.4.4 Index]