Skip to content

Commit

Permalink
Add method 'rows.etable'
Browse files Browse the repository at this point in the history
  • Loading branch information
gdemin committed Apr 2, 2022
1 parent e34f234 commit ea3ee62
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 6 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: maditr
Type: Package
Title: Fast Data Aggregation, Modification, and Filtering with Pipes and 'data.table'
Version: 0.8.2
Version: 0.8.3
Maintainer: Gregory Demin <gdemin@gmail.com>
Authors@R: person("Gregory", "Demin", email = "gdemin@gmail.com", role = c("aut", "cre"))
Depends: R (>= 3.3.0)
Expand All @@ -18,5 +18,5 @@ URL: https://github.com/gdemin/maditr
BugReports: https://github.com/gdemin/maditr/issues
VignetteBuilder: knitr
Encoding: UTF-8
RoxygenNote: 7.1.1
RoxygenNote: 7.1.2
Roxygen: list(markdown = TRUE)
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ S3method(query,data.frame)
S3method(query_if,data.frame)
S3method(rollup,data.frame)
S3method(rows,data.frame)
S3method(rows,etable)
S3method(sort_by,data.frame)
S3method(take,data.frame)
S3method(take_all,data.frame)
Expand Down
4 changes: 4 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
0.8.3 (2022-04-02)
================
* now 'rows' respects 'etable' class

0.8.2 (2021-05-25)
================
* fix serious bug with '%to%' in the multiassignment expression in the 'let'
Expand Down
18 changes: 14 additions & 4 deletions R/columns.R
Original file line number Diff line number Diff line change
Expand Up @@ -352,18 +352,28 @@ rows.data.frame = function(data, ...){
stop(sprintf("'rows': it seems you use '=' instead of '==': %s.", curr_names))
}


parent_frame = parent.frame()
# if data is expression we want to calculate it only once
data = force(data)
# NULL is just a placeholder
expr = substitute(
NULL[Reduce(f = '&', list(...)),]
)
parent_frame = parent.frame()
# if data is expression we want to calculate it only once
data = force(data)
eval_in_parent_frame(data, expr, frame = parent_frame)

}

#' @export
rows.etable = function(data, ...){
data_class = class(data)
data = as.data.table(data)
res = eval.parent(
substitute(maditr::rows(data, ...))
)
setDF(res)
class(res) = data_class
res
}



Expand Down
12 changes: 12 additions & 0 deletions inst/tinytest/test_dplyr_verbs.R
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,18 @@ expect_identical(
rows(mtcars, rowSums(vs %to% am)>0),
dt_mt[vs>0 | am>0, ]
)

etab = data.frame(a = 1:2, b = 3:4)
class(etab) = c("etable", class(etab))
res = etab[2,, drop = FALSE]
rownames(res) = NULL
expect_equal(res, rows(etab, 2))

etab = data.frame(a = 1:2, b = 3:4)
class(etab) = c("etable", class(etab))
res = etab[1,, drop = FALSE]
rownames(res) = NULL
expect_equal(res, rows(etab, b<4))
##########################

cat("\nContext:", "dt_arrange", "\n")
Expand Down

0 comments on commit ea3ee62

Please sign in to comment.