-
Notifications
You must be signed in to change notification settings - Fork 73
Remove dplyr dependency #182
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
9b8a9a2
Simply forwarding functions to dplyr
jimhester 01d8acb
Remove dplyr import
jimhester 00a8cf9
Replace case_when
jimhester f36fa94
lead and lag implementations
jimhester 459e503
Arrange implementation
jimhester 870da11
Remove rename_ call
jimhester 343d566
Use base equivalents of if_else and filter
jimhester a86d755
Last implementation
jimhester ede7738
Slice implementation
jimhester 9ac48f8
Remove group by
jimhester ed31569
Remove mutate
jimhester cf2078d
Remove transmute
jimhester 4c7894b
Remove summarize_
jimhester 749d7e0
Add dplyr.R to collate
jimhester 7f17696
bind_rows implementation
jimhester 3f00434
Move dplyr to Suggests
jimhester d2e2b30
Merge branch 'master' into remove_dplyr2
krlmlr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
lag <- function(x, n = 1L, default = NA, ...) { | ||
if (n == 0) { | ||
return(x) | ||
} | ||
xlen <- length(x) | ||
n <- pmin(n, xlen) | ||
out <- c(rep(default, n), x[seq_len(xlen - n)]) | ||
attributes(out) <- attributes(x) | ||
out | ||
} | ||
|
||
lead <- function(x, n = 1L, default = NA, ...) { | ||
if (n == 0) { | ||
return(x) | ||
} | ||
xlen <- length(x) | ||
n <- pmin(n, xlen) | ||
out <- c(x[-seq_len(n)], rep(default, n)) | ||
attributes(out) <- attributes(x) | ||
out | ||
} | ||
|
||
arrange <- function(.data, ...) { | ||
stopifnot(is.data.frame(.data)) | ||
ord <- eval(substitute(order(...)), .data, parent.frame()) | ||
if (length(ord) != nrow(.data)) { | ||
stop("Length of ordering vectors don't match data frame size", | ||
call. = FALSE) | ||
} | ||
.data[ord, , drop = FALSE] | ||
} | ||
|
||
bind_rows <- function(x, y = NULL) { | ||
if (is.null(x) && is.null(y)) { | ||
return(tibble()) | ||
} | ||
if (is.null(x)) { | ||
if (inherits(y, "data.frame")) { | ||
return(y) | ||
} | ||
return(do.call(rbind.data.frame, x)) | ||
} | ||
if (is.null(y)) { | ||
if (inherits(x, "data.frame")) { | ||
return(x) | ||
} | ||
return(do.call(rbind.data.frame, x)) | ||
} | ||
if (NCOL(x) != NCOL(y)) { | ||
for (nme in setdiff(names(x), names(y))) { | ||
y[[nme]] <- NA | ||
} | ||
} | ||
rbind.data.frame(x, y) | ||
} | ||
|
||
if_else <- function(condition, true, false, missing = NULL) { | ||
ifelse(condition, true, false) | ||
} | ||
|
||
filter <- function(.data, ...) { | ||
subset(.data, ...) | ||
} | ||
|
||
left_join <- function(x, y, by, ...) { | ||
if (rlang::is_named(by)) { | ||
by_x <- names(by) | ||
by_y <- unname(by) | ||
} else { | ||
by_x <- by_y <- by | ||
} | ||
res <- as_tibble(merge(x, y, by.x = by_x, by.y = by_y, all.x = TRUE, ...)) | ||
res <- arrange(res, line1, col1, line2, col2, parent) | ||
|
||
# dplyr::left_join set unknown list columns to NULL, merge sets them | ||
# to NA | ||
if (exists("child", res) && any(is.na(res$child))) { | ||
res$child[is.na(res$child)] <- list(NULL) | ||
} | ||
res | ||
} | ||
|
||
nth <- function (x, n, order_by = NULL, default = x[NA_real_]) { | ||
stopifnot(length(n) == 1, is.numeric(n)) | ||
n <- trunc(n) | ||
if (n == 0 || n > length(x) || n < -length(x)) { | ||
return(default) | ||
} | ||
if (n < 0) { | ||
n <- length(x) + n + 1 | ||
} | ||
if (is.null(order_by)) { | ||
x[[n]] | ||
} | ||
else { | ||
x[[order(order_by)[[n]]]] | ||
} | ||
} | ||
|
||
|
||
last <- function (x, order_by = NULL, default = x[NA_real_]) { | ||
nth(x, -1L, order_by = order_by, default = default) | ||
} | ||
|
||
slice <- function(.data, ...) { | ||
.data[c(...), , drop = FALSE] | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
#' @api | ||
#' @import tibble | ||
#' @import dplyr | ||
#' @import tidyr | ||
NULL | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Once we have removed the tidyr and dplyr dependency, we can probably also refrain from declaring the variables below as globals, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No you still need them here because they are still used with Non-Standard Evaluation in arrange.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, right. And
filter
also I guess. I was just wondering whether it would be desirable to get rid of NSE completely.