Skip to content

Commit

Permalink
Join methods should be for data.table not tbl_dt.
Browse files Browse the repository at this point in the history
Closes #470
  • Loading branch information
hadley committed Aug 1, 2014
1 parent cc0026a commit b978eeb
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 16 deletions.
8 changes: 4 additions & 4 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
S3method(all.equal,tbl_df)
S3method(all.equal,tbl_dt)
S3method(anti_join,data.frame)
S3method(anti_join,data.table)
S3method(anti_join,tbl_df)
S3method(anti_join,tbl_dt)
S3method(anti_join,tbl_sql)
S3method(arrange,data.frame)
S3method(arrange,data.table)
Expand Down Expand Up @@ -122,14 +122,14 @@ S3method(groups,tbl_sql)
S3method(head,tbl_dt)
S3method(head,tbl_sql)
S3method(inner_join,data.frame)
S3method(inner_join,data.table)
S3method(inner_join,tbl_df)
S3method(inner_join,tbl_dt)
S3method(inner_join,tbl_sql)
S3method(intersect,data.frame)
S3method(intersect,default)
S3method(left_join,data.frame)
S3method(left_join,data.table)
S3method(left_join,tbl_df)
S3method(left_join,tbl_dt)
S3method(left_join,tbl_sql)
S3method(mutate,data.frame)
S3method(mutate,data.table)
Expand Down Expand Up @@ -200,8 +200,8 @@ S3method(select,tbl_df)
S3method(select,tbl_dt)
S3method(select,tbl_sql)
S3method(semi_join,data.frame)
S3method(semi_join,data.table)
S3method(semi_join,tbl_df)
S3method(semi_join,tbl_dt)
S3method(semi_join,tbl_sql)
S3method(setdiff,data.frame)
S3method(setdiff,default)
Expand Down
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# dplyr 0.2.0.99

* joining two data.tables now correctly dispatches to data table methods,
and result is a data table (#470)

* New `n_groups()` function tells you how many groups in a tbl. It returns
1 for ungrouped data. (#477)

Expand Down
8 changes: 4 additions & 4 deletions R/join-dt.r
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,15 @@ join_dt <- function(op) {

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

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

#' @export
#' @rdname join.tbl_dt
semi_join.tbl_dt <- join_dt({
semi_join.data.table <- join_dt({
# http://stackoverflow.com/questions/18969420/perform-a-semi-join-with-data-table
w <- unique(x[y, which = TRUE, allow.cartesian = TRUE])
w <- w[!is.na(w)]
Expand All @@ -75,4 +75,4 @@ semi_join.tbl_dt <- join_dt({

#' @export
#' @rdname join.tbl_dt
anti_join.tbl_dt <- join_dt(x[!y, allow.cartesian = TRUE])
anti_join.data.table <- join_dt(x[!y, allow.cartesian = TRUE])
16 changes: 8 additions & 8 deletions man/join.tbl_dt.Rd
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
% Generated by roxygen2 (4.0.1): do not edit by hand
\name{join.tbl_dt}
\alias{anti_join.tbl_dt}
\alias{inner_join.tbl_dt}
\alias{anti_join.data.table}
\alias{inner_join.data.table}
\alias{join.tbl_dt}
\alias{left_join.tbl_dt}
\alias{semi_join.tbl_dt}
\alias{left_join.data.table}
\alias{semi_join.data.table}
\title{Join data table tbls.}
\usage{
\method{inner_join}{tbl_dt}(x, y, by = NULL, copy = FALSE, ...)
\method{inner_join}{data.table}(x, y, by = NULL, copy = FALSE, ...)

\method{left_join}{tbl_dt}(x, y, by = NULL, copy = FALSE, ...)
\method{left_join}{data.table}(x, y, by = NULL, copy = FALSE, ...)

\method{semi_join}{tbl_dt}(x, y, by = NULL, copy = FALSE, ...)
\method{semi_join}{data.table}(x, y, by = NULL, copy = FALSE, ...)

\method{anti_join}{tbl_dt}(x, y, by = NULL, copy = FALSE, ...)
\method{anti_join}{data.table}(x, y, by = NULL, copy = FALSE, ...)
}
\arguments{
\item{x,y}{tbls to join}
Expand Down
7 changes: 7 additions & 0 deletions tests/testthat/test-joins.r
Original file line number Diff line number Diff line change
Expand Up @@ -184,3 +184,10 @@ test_that("join functions error on column not found #371", {
"No common variables"
)
})

test_that("joining data tables yields a data table (#470)", {
out <- left_join(data.table(a), data.table(b))
expect_is(out, "data.table")
out <- semi_join(data.table(a), data.table(b))
expect_is(out, "data.table")
})

0 comments on commit b978eeb

Please sign in to comment.