Skip to content

Commit

Permalink
Add test for dot-list selector
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcusKlik committed May 7, 2018
1 parent 66f4989 commit bd45361
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
language: R
cache: packages
sudo: false
warnings_are_errors: true
warnings_are_errors: false

r:
- oldrel
Expand Down
17 changes: 11 additions & 6 deletions R/table_proxy_methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -240,14 +240,15 @@ table_proxy_select_rows <- function(tbl_proxy, i) {
tbl_proxy
}


#' Apply a column transformation operation on the current table_proxy state
#'
#' Currently this is intended to be used with the j argument to a datatableinterface
#' object, but it could just as well be used to implement mutate or transmute for a
#' dplyr interface.
#'
#' @param tbl_proxy a table proxy object
#' @param j column expressions
#' @param colexps column expressions
#'
#' @return a table proxy object with the new state
#' @export
Expand All @@ -256,11 +257,15 @@ table_proxy_transform <- function(tbl_proxy, colexps) {
# update nrow
tbl_proxy$remotetablestate$ncol <- length(colexps)
tbl_proxy$remotetablestate$colnames <- names(colexps)
tbl_proxy$remotetablestate$colexps <- lapply(colexps, .resubstitute,
sub = tbl_proxy$remotetablestate$colexps)
tbl_proxy$remotetablestate$
coltypes <- rtable_column_types(tbl_proxy$remotetable)[match(tbl_proxy$remotetablestate$colexps,
rtable_colnames(tbl_proxy$remotetable))]
tbl_proxy$remotetablestate$colexps <-
lapply(colexps, .resubstitute, sub = tbl_proxy$remotetablestate$colexps)

# probably best to infer the column type from the expression result as type
# casting can occur when a more complex expression is used
tbl_proxy$remotetablestate$coltypes <-
rtable_column_types(tbl_proxy$remotetable)[match(tbl_proxy$remotetablestate$colexps,
rtable_colnames(tbl_proxy$remotetable))]

tbl_proxy
}

Expand Down
2 changes: 1 addition & 1 deletion man/table_proxy_transform.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 19 additions & 7 deletions tests/testthat/test_interface.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,11 @@ fst::write_fst(x, "1.fst")
ft <- fsttable::fst_table("1.fst")


# collect the ft and compares the result to the in-memory data.table
check_interface <- function(ft, dt, i, j) {
expect_equal(ft[i, j, collect = TRUE], dt[i, j])
}

expect_identical_table_proxy <- function(ft1, ft2) {
expect_identical(fsttable:::.get_table_proxy(ft1), fsttable:::.get_table_proxy(ft2))
}


test_that("empty i and j", {
ft_copy <- ft[]
expect_identical_table_proxy(ft, ft_copy)
Expand All @@ -35,10 +31,11 @@ test_that("empty i and j", {
test_that("row selection", {

# integer selection
check_interface(ft, x, 1:10)
expect_equal(ft[1:10, collect = TRUE], x[1:10, ])

# logical selection
check_interface(ft, x, rep(c(FALSE, TRUE, TRUE, FALSE), 25))
mask <- rep(c(FALSE, TRUE, TRUE, FALSE), 25)
expect_equal(ft[mask, collect = TRUE], x[mask, ])

# equivalent selection results in same structure
ft1 <- ft[5:1]
Expand All @@ -51,5 +48,20 @@ test_that("row selection", {
# full selection should return identical table
expect_identical_table_proxy(ft, ft[1:nrow(ft)])
expect_identical_table_proxy(ft, ft[rep(TRUE, nrow(ft))])
})


test_that("row selection", {

# dot single column selection
expect_equal(ft[, .(Z = X), collect = TRUE], x[, .(Z = X)])

# dot multiple identical column selection
expect_equal(ft[, .(Z = X, W = X), collect = TRUE], x[, .(Z = X, W = X)])

# dot multiple identical column selection
expect_equal(ft[, .(Z = X, W = X), collect = TRUE], x[, .(Z = X, W = X)])

# column name override
expect_equal(ft[, .(X = Y), collect = TRUE], x[, .(X = Y)])
})

0 comments on commit bd45361

Please sign in to comment.