Skip to content

Commit

Permalink
revert back .checkFilterVariables() + document issue
Browse files Browse the repository at this point in the history
  • Loading branch information
lgatto committed Apr 11, 2024
1 parent 9b0cda1 commit 21e8374
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
20 changes: 15 additions & 5 deletions R/QFeatures-filter.R
Original file line number Diff line number Diff line change
Expand Up @@ -371,12 +371,22 @@ filterFeaturesWithFormula <- function(object, filter, i,
## 3 in filterFeatures()
## 4 in environment the function was called
##
## BUT WHY? This fails when the user has a variable in their
## working environment.
## This is needed for when the value is a variable itself, such as
## in:
## target <- "location"
## filterFeatures(feat1, ~ location == target)
##
## vars <- vars[!vars %in% ls(envir = parent.frame(4))]
## if (!length(vars))
## stop("No vars left")
## BUT is breaks if location exists in the working env:
## location <- 1
## filterFeatures(feat1, ~ location == "Mitchondrion")
## filterFeatures(feat1, ~ location == target)
##
## The number of variables (that we want to keep, vs their values
## (that we don't want) isn't necessarily 1, as shown in:
## filterFeatures(feat1, ~ pval <= 0.03 & grepl("Mito", location))
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)
Expand Down
6 changes: 4 additions & 2 deletions tests/testthat/test_utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ test_that(".checkFilterVariables works", {
expect_error(.checkFilterVariables(rd, "v"),
"'v' is/are absent from all rowData.")
w <- 1
expect_error(.checkFilterVariables(rd, "w"),
"'w' is/are absent from all rowData.")
## expect_error(.checkFilterVariables(rd, "w"),
## "No vars left.")
expect_error(.checkFilterVariables(rd, "ww"),
"'ww' is/are absent from all rowData.")
})

0 comments on commit 21e8374

Please sign in to comment.