From 1c2955379d727d0d7f80e12448902beaa8e8e041 Mon Sep 17 00:00:00 2001 From: yun Date: Thu, 27 Jun 2024 01:46:56 +0800 Subject: [PATCH] use `ht_opt` directly --- R/utils-complexheatmap.R | 49 ++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/R/utils-complexheatmap.R b/R/utils-complexheatmap.R index a4addb7..af358b9 100644 --- a/R/utils-complexheatmap.R +++ b/R/utils-complexheatmap.R @@ -44,18 +44,11 @@ eheat_decorate <- function(vp_name, code) { eval(substitute(.eheat_decorate(vp_name, code))) } -#' Make ComplexHeatmap verbose -#' @param code Running [ggheat] or [Heatmap][ComplexHeatmap::Heatmap] function. -#' @param verbose A boolean value indicates whether to draw Heatmap verbosely. -#' @return The results of the evaluation of the `code` argument. -#' @examples -#' with_ht_verbose(ggheat(matrix(rnorm(81), nrow = 9))) -#' @seealso [with_ht_opts] -#' @export -with_ht_verbose <- function(code, verbose = TRUE) { - old <- ComplexHeatmap::ht_opt("verbose") - ComplexHeatmap::ht_opt(verbose = verbose) - on.exit(ComplexHeatmap::ht_opt(verbose = old)) +.eheat_decorate <- function(vp_name, code) { + current_vp <- grid::current.viewport()$name + if (current_vp == "ROOT") current_vp <- "global" + grid::seekViewport(vp_name) + on.exit(grid::seekViewport(current_vp)) force(code) } @@ -77,11 +70,27 @@ with_ht_verbose <- function(code, verbose = TRUE) { with_ht_opts <- function(opts, code) { assert_(opts, function(x) is.list(x) && rlang::is_named(x), "a named list") # nms <- rlang::names2(opts) - # old <- rlang::inject(ComplexHeatmap::ht_opt(!!!nms)) - # if (is.null(old)) old <- list(old) + # old <- rlang::inject(ht_opt(!!!nms)) + # if (!is.list(old)) old <- list(old) # names(old) <- nms - ComplexHeatmap::ht_opt(opts) - on.exit(ComplexHeatmap::ht_opt(RESET = TRUE)) + ht_opt(opts) # set options + # if (length(old)) on.exit(ht_opt(old)) # reset option + on.exit(ht_opt(RESET = TRUE)) # reset option + force(code) +} + +#' Make ComplexHeatmap verbose +#' @param code Running [ggheat] or [Heatmap][ComplexHeatmap::Heatmap] function. +#' @param verbose A boolean value indicates whether to draw Heatmap verbosely. +#' @return The results of the evaluation of the `code` argument. +#' @examples +#' with_ht_verbose(ggheat(matrix(rnorm(81), nrow = 9))) +#' @seealso [with_ht_opts] +#' @export +with_ht_verbose <- function(code, verbose = TRUE) { + old <- ht_opt("verbose") + ht_opt(verbose = verbose) + on.exit(ht_opt(verbose = old)) force(code) } @@ -91,14 +100,6 @@ set_ht_opt <- function(opt, value) { invisible(old) } -.eheat_decorate <- function(vp_name, code) { - current_vp <- grid::current.viewport()$name - if (current_vp == "ROOT") current_vp <- "global" - grid::seekViewport(vp_name) - on.exit(grid::seekViewport(current_vp)) - force(code) -} - eheat_which <- function(which = NULL) { out <- eheat_env_get("current_annotation_which") if (is.null(out)) {