Skip to content

Commit

Permalink
Merge pull request #42 from lionel-/compat-dplyr-0.6.0
Browse files Browse the repository at this point in the history
Compat dplyr 0.6.0
  • Loading branch information
lionel- authored Apr 21, 2017
2 parents 2ceec18 + e47cb5c commit 7a9223e
Show file tree
Hide file tree
Showing 21 changed files with 284 additions and 146 deletions.
2 changes: 2 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
^\.Rproj\.user$
^\.travis\.yml$
^cran-comments\.md$
^revdep$
^codecov\.yml$
7 changes: 4 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
Package: dtplyr
Title: Data Table Back-End for 'dplyr'
Version: 0.0.1.9000
Version: 0.0.2
Authors@R: c(
person("Hadley", "Wickham", , "[email protected]", role = c("aut", "cre")),
person("Lionel", "Henry", , "[email protected]", role = "cre"),
person("Hadley", "Wickham", , "[email protected]", role = "aut"),
person("RStudio", role = "cph")
)
Description: This implements the data table back-end for 'dplyr' so that you
Expand All @@ -18,6 +19,6 @@ Suggests:
testthat,
covr
LazyData: true
RoxygenNote: 5.0.1
RoxygenNote: 6.0.1
URL: https://github.com/hadley/dtplyr
BugReports: https://github.com/hadley/dtplyr/issues
58 changes: 5 additions & 53 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,88 +1,40 @@
# Generated by roxygen2: do not edit by hand


if (utils::packageVersion("dplyr") > "0.5.0") {
importFrom(dplyr,do)
S3method(do,data.table)
}
S3method(all.equal,tbl_dt)
S3method(anti_join,data.table)
S3method(arrange_,data.table)
S3method(arrange_,grouped_dt)
S3method(arrange_,tbl_dt)
S3method(as.data.frame,tbl_dt)
S3method(as.tbl,data.table)
S3method(auto_copy,tbl_dt)
S3method(dimnames,tbl_dt)
S3method(distinct_,data.table)
S3method(distinct_,grouped_dt)
S3method(distinct_,tbl_dt)
S3method(do_,data.table)
S3method(do_,grouped_dt)
S3method(do_,tbl_dt)
S3method(filter_,data.table)
S3method(filter_,grouped_dt)
S3method(filter_,tbl_dt)
S3method(full_join,data.table)
S3method(group_by_,data.table)
S3method(group_size,grouped_dt)
S3method(groups,grouped_dt)
S3method(groups,tbl_dt)
S3method(head,tbl_dt)
S3method(inner_join,data.table)
S3method(left_join,data.table)
S3method(mutate_,data.table)
S3method(mutate_,grouped_dt)
S3method(mutate_,tbl_dt)
S3method(n_groups,grouped_dt)
S3method(print,grouped_dt)
S3method(print,tbl_dt)
S3method(rename_,data.table)
S3method(rename_,grouped_dt)
S3method(rename_,tbl_dt)
S3method(right_join,data.table)
S3method(same_src,tbl_dt)
S3method(sample_frac,grouped_dt)
S3method(sample_frac,tbl_dt)
S3method(sample_n,grouped_dt)
S3method(sample_n,tbl_dt)
S3method(select_,data.table)
S3method(select_,grouped_dt)
S3method(select_,tbl_dt)
S3method(semi_join,data.table)
S3method(slice_,data.table)
S3method(slice_,grouped_dt)
S3method(slice_,tbl_dt)
S3method(summarise_,data.table)
S3method(summarise_,grouped_dt)
S3method(summarise_,tbl_dt)
S3method(tail,tbl_dt)
S3method(tbl_vars,tbl_dt)
S3method(ungroup,data.table)
S3method(ungroup,grouped_dt)
S3method(ungroup,tbl_dt)
export(.datatable.aware)
export(grouped_dt)
export(is.grouped_dt)
export(src_dt)
export(tbl_dt)
importFrom(dplyr,anti_join)
importFrom(dplyr,arrange_)
importFrom(dplyr,as.tbl)
importFrom(dplyr,auto_copy)
importFrom(dplyr,distinct_)
importFrom(dplyr,do_)
importFrom(dplyr,filter_)
importFrom(dplyr,full_join)
importFrom(dplyr,group_by_)
importFrom(dplyr,group_size)
importFrom(dplyr,groups)
importFrom(dplyr,inner_join)
importFrom(dplyr,left_join)
importFrom(dplyr,mutate_)
importFrom(dplyr,n_groups)
importFrom(dplyr,rename_)
importFrom(dplyr,right_join)
importFrom(dplyr,same_src)
importFrom(dplyr,sample_frac)
importFrom(dplyr,sample_n)
importFrom(dplyr,select_)
importFrom(dplyr,semi_join)
importFrom(dplyr,slice_)
importFrom(dplyr,summarise_)
importFrom(dplyr,tbl_vars)
Expand Down
6 changes: 5 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# dtplyr 0.0.1.9000
# dtplyr 0.0.2

- This is a compatibility release. It makes dtplyr compatible with
dplyr 0.6.0 in addition to dplyr 0.5.0.


# dtplyr 0.0.1

Expand Down
98 changes: 98 additions & 0 deletions R/compat-dplyr-0.6.0.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@

.onLoad <- function(libname, pkgname) {
if (utils::packageVersion("dplyr") > "0.5.0") {
register_s3_method("dplyr", "do", "data.table")
register_s3_method("dplyr", "group_by", "data.table")
register_s3_method("dplyr", "distinct", "data.table")
register_s3_method("dplyr", "filter", "data.table")
register_s3_method("dplyr", "summarise", "data.table")
register_s3_method("dplyr", "mutate", "data.table")
register_s3_method("dplyr", "arrange", "data.table")
register_s3_method("dplyr", "select", "data.table")
register_s3_method("dplyr", "rename", "data.table")
register_s3_method("dplyr", "slice", "data.table")
}

register_s3_method("dplyr", "do_", "data.table")
register_s3_method("dplyr", "do_", "tbl_dt")

register_s3_method("base", "print", "grouped_dt")
register_s3_method("dplyr", "groups", "grouped_dt")
register_s3_method("dplyr", "group_size", "grouped_dt")
register_s3_method("dplyr", "n_groups", "grouped_dt")
register_s3_method("dplyr", "ungroup", "grouped_dt")

register_s3_method("dplyr", "group_by_", "data.table")
register_s3_method("dplyr", "do_", "grouped_dt")
register_s3_method("dplyr", "distinct_", "grouped_dt")

register_s3_method("dplyr", "inner_join", "data.table")
register_s3_method("dplyr", "left_join", "data.table")
register_s3_method("dplyr", "right_join", "data.table")
register_s3_method("dplyr", "semi_join", "data.table")
register_s3_method("dplyr", "anti_join", "data.table")
register_s3_method("dplyr", "full_join", "data.table")

register_s3_method("dplyr", "sample_n", "tbl_dt")
register_s3_method("dplyr", "sample_n", "grouped_dt")
register_s3_method("dplyr", "sample_frac", "tbl_dt")
register_s3_method("dplyr", "sample_frac", "grouped_dt")

register_s3_method("dplyr", "distinct_", "data.table")
register_s3_method("dplyr", "distinct_", "tbl_dt")

register_s3_method("dplyr", "filter_", "grouped_dt")
register_s3_method("dplyr", "filter_", "tbl_dt")
register_s3_method("dplyr", "filter_", "data.table")

register_s3_method("dplyr", "summarise_", "grouped_dt")
register_s3_method("dplyr", "summarise_", "tbl_dt")
register_s3_method("dplyr", "summarise_", "data.table")

register_s3_method("dplyr", "mutate_", "grouped_dt")
register_s3_method("dplyr", "mutate_", "tbl_dt")
register_s3_method("dplyr", "mutate_", "data.table")

register_s3_method("dplyr", "arrange_", "grouped_dt")
register_s3_method("dplyr", "arrange_", "tbl_dt")
register_s3_method("dplyr", "arrange_", "data.table")

register_s3_method("dplyr", "select_", "grouped_dt")
register_s3_method("dplyr", "select_", "tbl_dt")
register_s3_method("dplyr", "select_", "data.table")

register_s3_method("dplyr", "rename_", "grouped_dt")
register_s3_method("dplyr", "rename_", "tbl_dt")
register_s3_method("dplyr", "rename_", "data.table")

register_s3_method("dplyr", "slice_", "grouped_dt")
register_s3_method("dplyr", "slice_", "tbl_dt")
register_s3_method("dplyr", "slice_", "data.table")

invisible()
}

register_s3_method <- function(pkg, generic, class, fun = NULL) {
stopifnot(is.character(pkg), length(pkg) == 1)
envir <- asNamespace(pkg)

stopifnot(is.character(generic), length(generic) == 1)
stopifnot(is.character(class), length(class) == 1)
if (is.null(fun)) {
fun <- get(paste0(generic, ".", class), envir = parent.frame())
}
stopifnot(is.function(fun))


if (pkg %in% loadedNamespaces()) {
registerS3method(generic, class, fun, envir = envir)
}

# Always register hook in case package is later unloaded & reloaded
setHook(
packageEvent(pkg, "onLoad"),
function(...) {
registerS3method(generic, class, fun, envir = envir)
}
)
}
12 changes: 9 additions & 3 deletions R/do.R
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
#' @rawNamespace
#' if (utils::packageVersion("dplyr") > "0.5.0") {
#' importFrom(dplyr,do)
#' S3method(do,data.table)
#' }
do.data.table <- function(.data, ...) {
do_(.data, .dots = lazyeval::lazy_dots(...))
}

#' @importFrom dplyr do_
#' @export
do_.data.table <- function(.data, ..., .dots) {
out <- do_(as.data.frame(.data), ..., .dots = .dots)
data.table::as.data.table(out)
}

#' @export
do_.tbl_dt <- function(.data, ..., .dots) {
out <- do_(as.data.frame(.data), ..., .dots = .dots)
tbl_dt(out)
Expand Down
14 changes: 3 additions & 11 deletions R/grouped-dt.r
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ grouped_dt <- function(data, vars, copy = TRUE) {
data
}

#' @export
groups.grouped_dt <- function(x) {
attr(x, "vars")
}
Expand All @@ -47,7 +46,6 @@ groups.grouped_dt <- function(x) {
#' @export
is.grouped_dt <- function(x) inherits(x, "grouped_dt")

#' @export
print.grouped_dt <- function(x, ..., n = NULL, width = NULL) {
cat("Source: local data table ", dplyr::dim_desc(x), "\n", sep = "")
cat("Groups: ", commas(deparse_all(dplyr::groups(x))), "\n", sep = "")
Expand All @@ -56,27 +54,23 @@ print.grouped_dt <- function(x, ..., n = NULL, width = NULL) {
invisible(x)
}

#' @importFrom dplyr group_size
#' @export
group_size.grouped_dt <- function(x) {
dplyr::summarise_(x, n = ~n())$n
}

#' @importFrom dplyr n_groups
#' @export
n_groups.grouped_dt <- function(x) {
nrow(dt_subset(x, , quote(list(1))))
}

#' @export
#' @importFrom dplyr group_by_
group_by.data.table <- function(.data, ..., add = FALSE) {
group_by_(.data, .dots = lazyeval::lazy_dots(...), add = add)
}
group_by_.data.table <- function(.data, ..., .dots, add = FALSE) {
groups <- dplyr::group_by_prepare(.data, ..., .dots = .dots, add = add)
grouped_dt(groups$data, groups$groups)
}

#' @export
#' @importFrom dplyr ungroup
ungroup.grouped_dt <- function(x, ...) {
data.table::setattr(x, "vars", NULL)
data.table::setattr(x, "class", setdiff(class(x), "grouped_dt"))
Expand All @@ -86,7 +80,6 @@ ungroup.grouped_dt <- function(x, ...) {

# Do ---------------------------------------------------------------------------

#' @export
do_.grouped_dt <- function(.data, ..., .dots) {
args <- lazyeval::all_dots(.dots, ...)
env <- lazyeval::common_env(args)
Expand Down Expand Up @@ -130,7 +123,6 @@ named_args <- function(args) {

# Set operations ---------------------------------------------------------------

#' @export
distinct_.grouped_dt <- function(.data, ..., .dots) {
groups <- lazyeval::as.lazy_dots(groups(.data))
dist <- distinct_vars(.data, ..., .dots = c(.dots, groups))
Expand Down
12 changes: 0 additions & 12 deletions R/joins.R
Original file line number Diff line number Diff line change
Expand Up @@ -54,23 +54,15 @@ join_dt <- function(op) {
# nocov end
}

#' @export
#' @rdname join.tbl_dt
#' @importFrom dplyr inner_join
inner_join.data.table <- join_dt({merge(x, y, by = by$x, allow.cartesian = TRUE)})

#' @export
#' @importFrom dplyr left_join
#' @rdname join.tbl_dt
left_join.data.table <- join_dt({merge(x, y, by = by$x, all.x = TRUE, allow.cartesian = TRUE)})

#' @export
#' @importFrom dplyr right_join
#' @rdname join.tbl_dt
right_join.data.table <- join_dt(merge(x, y, by = by$x, all.y = TRUE, allow.cartesian = TRUE))

#' @export
#' @importFrom dplyr semi_join
#' @rdname join.tbl_dt
semi_join.data.table <- join_dt({
# http://stackoverflow.com/questions/18969420/perform-a-semi-join-with-data-table
Expand All @@ -79,13 +71,9 @@ semi_join.data.table <- join_dt({
x[w]
})

#' @export
#' @importFrom dplyr anti_join
#' @rdname join.tbl_dt
anti_join.data.table <- join_dt({x[!y, allow.cartesian = TRUE]})

#' @export
#' @importFrom dplyr full_join
#' @rdname join.tbl_dt
# http://stackoverflow.com/a/15170956/946850
full_join.data.table <- join_dt({merge(x, y, by = by$x, all = TRUE, allow.cartesian = TRUE)})
6 changes: 0 additions & 6 deletions R/sample.R
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
#' @importFrom dplyr sample_n
#' @export
sample_n.tbl_dt <- function(tbl, size, replace = FALSE, weight = NULL,
.env = parent.frame()) {
tbl_dt(NextMethod())
}

#' @export
sample_n.grouped_dt <- function(tbl, size, replace = FALSE, weight = NULL,
.env = parent.frame()) {

Expand All @@ -18,14 +15,11 @@ sample_n.grouped_dt <- function(tbl, size, replace = FALSE, weight = NULL,
grouped_dt(tbl[idx], groups(tbl))
}

#' @importFrom dplyr sample_frac
#' @export
sample_frac.tbl_dt <- function(tbl, size = 1, replace = FALSE, weight = NULL,
.env = parent.frame()) {
tbl_dt(NextMethod())
}

#' @export
sample_frac.grouped_dt <- function(tbl, size = 1, replace = FALSE, weight = NULL,
.env = parent.frame()) {

Expand Down
7 changes: 4 additions & 3 deletions R/sets.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@

# Set operations ---------------------------------------------------------------

#' @export
distinct.data.table <- function(.data, ..., .keep_all = FALSE) {
distinct_(.data, .dots = lazyeval::lazy_dots(...), .keep_all = .keep_all)
}

#' @importFrom dplyr distinct_
distinct_.data.table <- function(.data, ..., .dots, .keep_all = FALSE) {
dist <- distinct_vars(.data, ..., .dots = .dots)
Expand All @@ -18,8 +21,6 @@ distinct_.data.table <- function(.data, ..., .dots, .keep_all = FALSE) {

res
}

#' @export
distinct_.tbl_dt <- function(.data, ..., .dots) {
tbl_dt(NextMethod(), copy = FALSE)
}
Expand Down
Loading

0 comments on commit 7a9223e

Please sign in to comment.