From 5401dbcc1ed44b5b547452edd04bdfd365bd3a0b Mon Sep 17 00:00:00 2001 From: yun Date: Mon, 24 Jun 2024 23:21:01 +0800 Subject: [PATCH] rename `cheat` into `eheat` --- NAMESPACE | 4 +-- R/anno-.R | 2 +- R/gganno.R | 8 ++--- R/prepare.R | 8 ++--- R/utils-complexheatmap.R | 36 ++++++++++---------- man/{cheat_decorate.Rd => eheat_decorate.Rd} | 12 +++---- man/{cheat_grob.Rd => eheat_grob.Rd} | 8 ++--- 7 files changed, 39 insertions(+), 39 deletions(-) rename man/{cheat_decorate.Rd => eheat_decorate.Rd} (68%) rename man/{cheat_grob.Rd => eheat_grob.Rd} (95%) diff --git a/NAMESPACE b/NAMESPACE index 2a81f2c..3259b76 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -5,9 +5,9 @@ S3method(get_guides,ggplot) S3method(get_guides,gtable) export(anno_gg) export(anno_gg2) -export(cheat_decorate) -export(cheat_grob) export(draw) +export(eheat_decorate) +export(eheat_grob) export(gganno) export(ggfit) export(ggfit2) diff --git a/R/anno-.R b/R/anno-.R index 502fb21..6c35c2c 100644 --- a/R/anno-.R +++ b/R/anno-.R @@ -64,7 +64,7 @@ new_anno <- function(n, draw_fn, ylim = NULL, cli::cli_inform(msg) } anno <- methods::new("AnnotationFunction") - which <- cheat_which(which) + which <- eheat_which(which) anno@which <- which anno@fun_name <- name anno_size <- anno_width_and_height(which, width, height, unit(1, "cm")) diff --git a/R/gganno.R b/R/gganno.R index b923174..b9bd2ba 100644 --- a/R/gganno.R +++ b/R/gganno.R @@ -125,7 +125,7 @@ gganno_get_order_list <- function(name, axis, nframes <- sys.nframe() - 1L # total parents while (pos <= nframes) { env <- parent.frame(pos) - if (is_from_cheat(env) && + if (is_from_eheat(env) && exists(name, envir = env, inherits = FALSE) && is_call_from(pos, call_target)) { obj <- .subset2(env, name) @@ -255,7 +255,7 @@ draw_gganno <- function(anno, order_list, id) { rows = ggplot2::vars(.data$.slice), scales = "free_y", space = "free_y" ) - y_scale <- cheat_scales(coords[c(1L, 3:2)], labels, + y_scale <- eheat_scales(coords[c(1L, 3:2)], labels, scale_fn = ggplot2::scale_y_continuous ) if (!is.null(p$scales$get_scales("y"))) { @@ -273,7 +273,7 @@ draw_gganno <- function(anno, order_list, id) { cols = ggplot2::vars(.data$.slice), scales = "free_x", space = "free_x" ) - x_scale <- cheat_scales(coords[c(1L, 3:2)], labels, + x_scale <- eheat_scales(coords[c(1L, 3:2)], labels, scale_fn = ggplot2::scale_x_continuous ) if (!is.null(p$scales$get_scales("x"))) { @@ -352,7 +352,7 @@ draw_gganno <- function(anno, order_list, id) { # } else { # annotation_global_vp <- grid::current.viewport()$name # } - # .cheat_decorate(annotation_global_vp, { + # .eheat_decorate(annotation_global_vp, { # lapply(inside_guides, grid::grid.draw) # }) if (n == 1L) { diff --git a/R/prepare.R b/R/prepare.R index 0c4dc81..efe9803 100644 --- a/R/prepare.R +++ b/R/prepare.R @@ -61,7 +61,7 @@ prepare_ggheat <- function(object) { data$.column_index <- as.integer(data$.column_index) # prepare slice panels data ------------------------ - slice_list <- cheat_full_slice_index(order_list) + slice_list <- eheat_full_slice_index(order_list) # prepare data for ggplot2 -------------------------- coords <- lapply(slice_list, function(data) { @@ -132,7 +132,7 @@ prepare_ggheat <- function(object) { } cols <- sprintf(c(".slice_%s", ".%s", ".%s_index"), axis) # prepapre scales for each slice panel - cheat_scales(coords[cols], labels, scale_fn = fn) + eheat_scales(coords[cols], labels, scale_fn = fn) }) names(scales) <- c("row", "column") @@ -178,7 +178,7 @@ prepare_ggheat <- function(object) { nframes <- sys.nframe() - 1L # total parents while (pos <= nframes) { env <- parent.frame(pos) - if (is_from_cheat(env) && + if (is_from_eheat(env) && exists("kr", envir = env, inherits = FALSE) && exists("kc", envir = env, inherits = FALSE) && # Since ComplexHeatmap function much are the S4 methods @@ -209,7 +209,7 @@ prepare_ggheat <- function(object) { } # in the last slice, we draw inside guides if (n == total && length(inside_guides)) { - .cheat_decorate(heatmap_body_vp_name, { + .eheat_decorate(heatmap_body_vp_name, { lapply(inside_guides, grid::grid.draw) }) } diff --git a/R/utils-complexheatmap.R b/R/utils-complexheatmap.R index a72db32..94c3bf1 100644 --- a/R/utils-complexheatmap.R +++ b/R/utils-complexheatmap.R @@ -4,9 +4,9 @@ #' @return A [gTree][grid::gTree] object. #' @examples #' h <- ggheat(matrix(rnorm(100), 10)) -#' cheat_grob(h) +#' eheat_grob(h) #' @export -cheat_grob <- function(x, ...) grid::grid.grabExpr(expr = draw(x), ...) +eheat_grob <- function(x, ...) grid::grid.grabExpr(expr = draw(x), ...) #' Decorate ComplexHeatmap #' @param vp_name A valid viewport name returned by @@ -14,16 +14,16 @@ cheat_grob <- function(x, ...) grid::grid.grabExpr(expr = draw(x), ...) #' @param code Codes to draw elements in the viewport. #' @return Decorate the viewport. #' @examples -#' ggheat(matrix(rnorm(81), nrow = 9), column_km = 2L, name = "cheat_decorate") +#' ggheat(matrix(rnorm(81), nrow = 9), column_km = 2L, name = "eheat_decorate") #' ComplexHeatmap::list_components() -#' cheat_decorate("cheat_decorate_heatmap_body_wrap", { -#' grid.text("I'm from cheat_decorate", +#' eheat_decorate("eheat_decorate_heatmap_body_wrap", { +#' grid.text("I'm from eheat_decorate", #' 1.5 / 10, 2.5 / 4, #' default.units = "npc" #' ) #' }) #' @export -cheat_decorate <- function(vp_name, code) { +eheat_decorate <- function(vp_name, code) { assert_string(vp_name, empty_ok = FALSE) components <- ComplexHeatmap::list_components() if (!length(components)) { @@ -41,7 +41,7 @@ cheat_decorate <- function(vp_name, code) { ) )) } - eval(substitute(.cheat_decorate(vp_name, code))) + eval(substitute(.eheat_decorate(vp_name, code))) } #' Make ComplexHeatmap verbose @@ -84,7 +84,7 @@ with_ht_opts <- function(opts, code) { } -.cheat_decorate <- function(vp_name, code) { +.eheat_decorate <- function(vp_name, code) { current_vp <- grid::current.viewport()$name if (current_vp == "ROOT") current_vp <- "global" grid::seekViewport(vp_name) @@ -92,19 +92,19 @@ with_ht_opts <- function(opts, code) { force(code) } -cheat_which <- function(which = NULL) { - out <- cheat_env_get("current_annotation_which") +eheat_which <- function(which = NULL) { + out <- eheat_env_get("current_annotation_which") if (is.null(out)) { out <- match.arg(which, c("column", "row")) } out } -cheat_env_get <- function(name) .subset2(cheat_env(), name) +eheat_env_get <- function(name) .subset2(eheat_env(), name) -cheat_env <- function() utils::getFromNamespace(".ENV", ns = "ComplexHeatmap") +eheat_env <- function() utils::getFromNamespace(".ENV", ns = "ComplexHeatmap") -cheat_full_slice_index <- function(order_list) { +eheat_full_slice_index <- function(order_list) { row_full <- unlist(order_list$row, recursive = FALSE, use.names = FALSE) row_full <- structure(seq_along(row_full), names = row_full) column_full <- unlist(order_list$column, @@ -132,7 +132,7 @@ cheat_full_slice_index <- function(order_list) { out } -cheat_text_just <- function(rot, side) { +eheat_text_just <- function(rot, side) { rot <- rot %% 180 if (side == "left") { if (rot == 0) { @@ -169,7 +169,7 @@ cheat_text_just <- function(rot, side) { } } -cheat_check_gp <- function(gp) { +eheat_check_gp <- function(gp) { if (!"lineheight" %in% names(gp)) { gp$lineheight <- 0.9 } @@ -181,7 +181,7 @@ cheat_check_gp <- function(gp) { #' @param data A data.frame in the order of slice, coord, index #' @noRd -cheat_scales <- function(data, lables, scale_fn) { +eheat_scales <- function(data, lables, scale_fn) { lapply(split(data, data[[1L]]), function(slice_data) { slice_data <- slice_data[2:3] slice_data <- unique(slice_data) @@ -220,7 +220,7 @@ add_gg_legend_list <- function(name, gglegends, call_target = "make_layout") { nframes <- sys.nframe() - 1L # total parents while (pos <= nframes) { env <- parent.frame(pos) # we locate the legend environment - if (is_from_cheat(env) && + if (is_from_eheat(env) && exists(name, envir = env, inherits = FALSE) && # Since ComplexHeatmap function much are the S4 methods # we identify the call name from the parent generic function @@ -247,6 +247,6 @@ add_gg_legend_list <- function(name, gglegends, call_target = "make_layout") { } } -is_from_cheat <- function(env) { +is_from_eheat <- function(env) { identical(utils::packageName(topenv(env)), "ComplexHeatmap") } diff --git a/man/cheat_decorate.Rd b/man/eheat_decorate.Rd similarity index 68% rename from man/cheat_decorate.Rd rename to man/eheat_decorate.Rd index 7889d88..79afe15 100644 --- a/man/cheat_decorate.Rd +++ b/man/eheat_decorate.Rd @@ -1,10 +1,10 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/utils-complexheatmap.R -\name{cheat_decorate} -\alias{cheat_decorate} +\name{eheat_decorate} +\alias{eheat_decorate} \title{Decorate ComplexHeatmap} \usage{ -cheat_decorate(vp_name, code) +eheat_decorate(vp_name, code) } \arguments{ \item{vp_name}{A valid viewport name returned by @@ -19,10 +19,10 @@ Decorate the viewport. Decorate ComplexHeatmap } \examples{ -ggheat(matrix(rnorm(81), nrow = 9), column_km = 2L, name = "cheat_decorate") +ggheat(matrix(rnorm(81), nrow = 9), column_km = 2L, name = "eheat_decorate") ComplexHeatmap::list_components() -cheat_decorate("cheat_decorate_heatmap_body_wrap", { - grid.text("I'm from cheat_decorate", +eheat_decorate("eheat_decorate_heatmap_body_wrap", { + grid.text("I'm from eheat_decorate", 1.5 / 10, 2.5 / 4, default.units = "npc" ) diff --git a/man/cheat_grob.Rd b/man/eheat_grob.Rd similarity index 95% rename from man/cheat_grob.Rd rename to man/eheat_grob.Rd index 0c4db78..056dc7d 100644 --- a/man/cheat_grob.Rd +++ b/man/eheat_grob.Rd @@ -1,10 +1,10 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/utils-complexheatmap.R -\name{cheat_grob} -\alias{cheat_grob} +\name{eheat_grob} +\alias{eheat_grob} \title{Creates a gTree object from the Heatmap} \usage{ -cheat_grob(x, ...) +eheat_grob(x, ...) } \arguments{ \item{x}{A \link[ComplexHeatmap:HeatmapList-class]{HeatmapList-class} object.} @@ -44,5 +44,5 @@ Creates a gTree object from the Heatmap } \examples{ h <- ggheat(matrix(rnorm(100), 10)) -cheat_grob(h) +eheat_grob(h) }