Skip to content

Commit

Permalink
Merge pull request #104 from aalucaci/issue_103
Browse files Browse the repository at this point in the history
assert: remove dead code (closes #103)
  • Loading branch information
tonyfischetti authored Jan 24, 2021
2 parents e69e369 + 24dc081 commit 045b61a
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 12 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: assertr
Type: Package
Title: Assertive Programming for R Analysis Pipelines
Version: 2.6.9000
Version: 2.7
Authors@R: person("Tony", "Fischetti",
email="[email protected]",
role = c("aut", "cre"))
Expand Down
4 changes: 4 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# assertr 2.7

* `assert()`: remove dead code (closes #103)

# assertr 2.6

* bugs due to changes in rlang 0.3.0 fixed.
Expand Down
5 changes: 0 additions & 5 deletions R/assertions.R
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,6 @@ assert <- function(data, predicate, ..., success_fun=success_continue,
return(apply.predicate.to.vector(this.vector,
predicate))})

if(class(log.mat)=="logical"){
log.mat <- matrix(log.mat)
colnames(log.mat) <- colnames(sub.frame)
}

# if all checks pass in current assertion
if(all(log.mat))
return(success_fun(data, "assert", name.of.predicate, colnames(log.mat), NA, description))
Expand Down
1 change: 1 addition & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ is.vectorized.predicate <- function(predicate){

apply.predicate.to.vector <- function(a.column, predicate){
res <- logical(length(a.column))

if(is.vectorized.predicate(predicate))
res <- predicate(a.column)
else
Expand Down
34 changes: 28 additions & 6 deletions tests/testthat/test-assertions.R
Original file line number Diff line number Diff line change
Expand Up @@ -328,8 +328,13 @@ test_that("assert raises *custom error* if verification fails", {
test_that("assert breaks appropriately", {
expect_error(assert(in_set(0,1), mtcars$vs),
"assert requires columns to be selected. Check number of arguments")
expect_error(assert(mtcars, in_set(0,1), vs, tree),
"object 'tree' not found")
expect_error(
object = {
assert(mtcars, in_set(0,1), vs, tree)
},
regexp = "Column `tree` doesn't exist",
class = "error"
)
expect_error(assert(mtcars, in_set(0,1), vs, "tree"))
expect_error(assert("tree"),
"argument \"predicate\" is missing, with no default")
Expand Down Expand Up @@ -427,8 +432,20 @@ test_that("assert_rows breaks appropriately", {
"argument \"predicate\" is missing, with no default")
expect_error(assert_rows(rowSums, in_set(0,1), mtcars$vs),
"assert_rows requires columns to be selected. Check number of arguments")
expect_error(assert_rows(mtcars, rowSums, in_set(0,1,2), vs, am, tree),
"object 'tree' not found")
expect_error(
object = {
assert_rows(
data = mtcars,
row_reduction_fn = rowSums,
predicate = in_set(0,1,2),
vs,
am,
tree
)
},
regexp = "Column `tree` doesn't exist",
class = "error"
)
expect_error(assert_rows(mtcars, rowSums, in_set(0,1,2), vs, am, "tree"))
expect_error(assert_rows("tree"),
"argument \"row_reduction_fn\" is missing, with no default")
Expand Down Expand Up @@ -502,8 +519,13 @@ test_that("insist breaks appropriately", {
expect_error(insist(within_n_sds(5), mtcars$vs),
"insist requires columns to be selected. Check number of arguments")
expect_error(insist(mtcars, within_n_sds(5), "vs:am"))
expect_error(insist(mtcars, within_n_sds(5), tree),
"object 'tree' not found")
expect_error(
object = {
insist(data = mtcars, predicate_generator = within_n_sds(5), tree)
},
regexp = "Column `tree` doesn't exist",
class = "error"
)
expect_error(insist("tree"),
"argument \"predicate_generator\" is missing, with no default")
expect_error(insist(iris, within_n_sds(5), Petal.Width:Species),
Expand Down

0 comments on commit 045b61a

Please sign in to comment.