diff --git a/NAMESPACE b/NAMESPACE index be9e9daa..7a7d60e0 100755 --- a/NAMESPACE +++ b/NAMESPACE @@ -120,6 +120,7 @@ importFrom(purrr,as_mapper) importFrom(purrr,map) importFrom(purrr,map2) importFrom(purrr,map2_dfr) +importFrom(purrr,map_chr) importFrom(purrr,map_dfr) importFrom(purrr,map_lgl) importFrom(purrr,reduce) diff --git a/R/methods_SE.R b/R/methods_SE.R index 5bf0f72d..f8d358ed 100755 --- a/R/methods_SE.R +++ b/R/methods_SE.R @@ -926,7 +926,7 @@ setMethod("aggregate_duplicates", -#' @importFrom rlang quo_is_symbol +#' @importFrom rlang quo_is_symbolic .deconvolve_cellularity_se = function(.data, reference = X_cibersort, method = "cibersort", @@ -944,7 +944,7 @@ setMethod("aggregate_duplicates", .[[get_assay_scaled_if_exists_SE(.data)]] %>% # Change row names - when(quo_is_symbol(.transcript) ~ { + when(quo_is_symbolic(.transcript) ~ { .x = (.) rownames(.x) = .data %>% pivot_transcript() %>% pull(!!.transcript) .x @@ -1294,6 +1294,8 @@ setMethod("keep_variable", #' keep_variable #' @inheritParams keep_variable #' +#' @importFrom purrr map_chr +#' #' @docType methods #' @rdname keep_variable-methods #' @@ -1319,10 +1321,10 @@ setMethod("keep_variable", # Check factor_of_interest if( !is.null(factor_of_interest) && - quo_is_symbol(factor_of_interest) && - (quo_name(factor_of_interest) %in% colnames(colData(.data)) %>% not()) + quo_is_symbolic(factor_of_interest) && + (quo_names(factor_of_interest) %in% colnames(colData(.data)) |> all() %>% not()) ) - stop(sprintf("tidybulk says: the column %s is not present in colData", quo_name(factor_of_interest))) + stop(sprintf("tidybulk says: the column %s is not present in colData", quo_names(factor_of_interest))) if (minimum_counts < 0) stop("The parameter minimum_counts must be > 0") @@ -1343,16 +1345,22 @@ setMethod("keep_variable", factor_of_interest %>% when( - quo_is_symbol(factor_of_interest) && + quo_is_symbolic(factor_of_interest) && ( - colData(.data)[, quo_name(factor_of_interest)] %>% - class %in% c("numeric", "integer", "double")) ~ + colData(.data)[, quo_names(factor_of_interest), drop=FALSE] |> + as_tibble() |> + map_chr(~class(.x)) %in% c("numeric", "integer", "double") |> + any() + ) ~ { - message("tidybulk says: The factor of interest is continuous (e.g., integer,numeric, double). The data will be filtered without grouping.") + message("tidybulk says: The factor(s) of interest include continuous variable (e.g., integer,numeric, double). The data will be filtered without grouping.") NULL }, - quo_is_symbol(factor_of_interest) ~ - colData(.data)[, quo_name(factor_of_interest)], + quo_is_symbolic(factor_of_interest) ~ + colData(.data)[, quo_names(factor_of_interest), drop=FALSE] |> + as_tibble() |> + unite("factor_of_interest") |> + pull(factor_of_interest), ~ NULL ) diff --git a/tests/testthat/test-bulk_methods_SummarizedExperiment.R b/tests/testthat/test-bulk_methods_SummarizedExperiment.R index 7643eb5e..895f5f43 100755 --- a/tests/testthat/test-bulk_methods_SummarizedExperiment.R +++ b/tests/testthat/test-bulk_methods_SummarizedExperiment.R @@ -4,7 +4,6 @@ data("se_mini") data("breast_tcga_mini_SE") input_df = setNames(se_mini %>% tidybulk() %>% as_tibble(), c( "b","a", "c", "Cell type", "time" , "condition", "days", "dead", "entrez")) - input_df_breast = setNames( breast_tcga_mini_SE %>% tidybulk() %>% as_tibble(), c( "b", "a","c", "c norm", "call" )) test_that("tidybulk SummarizedExperiment conversion",{