Skip to content

Commit

Permalink
fix(?) .checkFilterVariables() + unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lgatto committed Apr 11, 2024
1 parent 1be8767 commit 9b0cda1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
12 changes: 8 additions & 4 deletions R/QFeatures-filter.R
Original file line number Diff line number Diff line change
Expand Up @@ -370,10 +370,14 @@ filterFeaturesWithFormula <- function(object, filter, i,
## 2 in .local()
## 3 in filterFeatures()
## 4 in environment the function was called
vars <- vars[!vars %in% ls(envir = parent.frame(4))]
if (!length(vars))
stop("No vars left")
## Get in which assays each variable comes from
##
## BUT WHY? This fails when the user has a variable in their
## working environment.
##
## vars <- vars[!vars %in% ls(envir = parent.frame(4))]
## if (!length(vars))
## stop("No vars left")
## get in which assays each variable comes from
out <- sapply(colnames(rowdata), function(rdn) vars %in% rdn)
if (!is.array(out)) out <- t(out)
rownames(out) <- vars
Expand Down
7 changes: 2 additions & 5 deletions tests/testthat/test_utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ test_that(".checkFilterVariables works", {
expect_error(.checkFilterVariables(rd, "v"),
"'v' is/are absent from all rowData.")
w <- 1
## This one fails when run interactively
## expect_error(.checkFilterVariables(rd, "w"),
## "No vars left")
expect_error(.checkFilterVariables(rd, "ww"),
"'ww' is/are absent from all rowData.")
expect_error(.checkFilterVariables(rd, "w"),
"'w' is/are absent from all rowData.")
})

0 comments on commit 9b0cda1

Please sign in to comment.