Skip to content

Commit

Permalink
use ht_opt directly
Browse files Browse the repository at this point in the history
  • Loading branch information
Yunuuuu committed Jun 26, 2024
1 parent c61f109 commit 1c29553
Showing 1 changed file with 25 additions and 24 deletions.
49 changes: 25 additions & 24 deletions R/utils-complexheatmap.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand All @@ -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)
}

Expand All @@ -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)) {
Expand Down

0 comments on commit 1c29553

Please sign in to comment.