-
Notifications
You must be signed in to change notification settings - Fork 3
/
arrange.R
37 lines (30 loc) · 830 Bytes
/
arrange.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#' @title Arrange rows by variables
#' @description Mimics dplyr::arrange using base R and rlang
#' @param .data data.frame
#' @param ... Comma separated list of unquoted variable names, use `-` for
#' descending order.
#' @return data.frame
#' @examples
#' airquality%>%
#' b_arrange(-Month,Temp)%>%
#' head()
#' @seealso
#' \code{\link[rlang]{quotation}}
#' @rdname b_arrange
#' @export
#' @author Jonathan Sidi
b_arrange <- function(.data,...){
UseMethod("b_arrange")
}
#' @rdname b_arrange
#' @export
#' @importFrom rlang quos quo_squash
b_arrange.default <- function(.data,...){
EXPRS <- lapply(rlang::quos(...),function(x) rlang::quo_squash(x))
.data[with(.data,do.call(order,EXPRS)),]
}
#' @rdname b_arrange
#' @export
b_arrange.split_df <- function(.data,...){
bindr(split(.data), b_arrange, .data, ...)
}