Skip to content

Commit

Permalink
adjust with_ht_verbose and with_ht_opts
Browse files Browse the repository at this point in the history
  • Loading branch information
Yunuuuu committed Jun 26, 2024
1 parent ac5ef34 commit c61f109
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
1 change: 0 additions & 1 deletion R/eanno.R
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@
#' draw(anno[1:2])
#' @seealso [AnnotationFunction][ComplexHeatmap::AnnotationFunction]
#' @return A `ExtendedAnnotation` object.
#' @importFrom ComplexHeatmap ht_opt
#' @export
eanno <- function(draw_fn, ..., matrix = NULL, which = NULL, subset_rule = NULL,
width = NULL, height = NULL, show_name = TRUE,
Expand Down
15 changes: 11 additions & 4 deletions R/utils-complexheatmap.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,15 @@ eheat_decorate <- function(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) {
with_ht_verbose <- function(code, verbose = TRUE) {
old <- ComplexHeatmap::ht_opt("verbose")
ComplexHeatmap::ht_opt(verbose = TRUE)
ComplexHeatmap::ht_opt(verbose = verbose)
on.exit(ComplexHeatmap::ht_opt(verbose = old))
force(code)
}
Expand All @@ -71,18 +72,24 @@ with_ht_verbose <- function(code) {
#' list(verbose = TRUE),
#' ggheat(matrix(rnorm(81), nrow = 9))
#' )
#' @importFrom ComplexHeatmap ht_opt
#' @export
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)
# names(old) <- nms
rlang::inject(ComplexHeatmap::ht_opt(!!!opts))
on.exit(rlang::inject(ComplexHeatmap::ht_opt(RESET = TRUE)))
ComplexHeatmap::ht_opt(opts)
on.exit(ComplexHeatmap::ht_opt(RESET = TRUE))
force(code)
}

set_ht_opt <- function(opt, value) {
old <- ht_opt[[opt]]
ht_opt[[opt]] <- value
invisible(old)
}

.eheat_decorate <- function(vp_name, code) {
current_vp <- grid::current.viewport()$name
Expand Down
4 changes: 3 additions & 1 deletion man/with_ht_verbose.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c61f109

Please sign in to comment.