Browse code

anno_mark(), anno_zoom(); print message under RStudio

Zuguang Gu authored on 14/06/2020 20:36:59
Showing5 changed files

... ...
@@ -9,6 +9,9 @@ CHANGES in VERSION 2.5.3
9 9
 * `anno_image()`: fixed a bug that images are not reordered.
10 10
 * `anno_mark()`: now expression is correctly supported.
11 11
 * `anno_zoom()`: order of index in `panel_fun` is adjusted to the order in the heatmap
12
+* `list_to_matrix()`: convert elements to characters.
13
+* print messages for `anno_mark()`, `anno_zoom()`, `draw_legend()` (if legends are wrapped) 
14
+  if working under RStudio.
12 15
 
13 16
 ========================
14 17
 
... ...
@@ -2794,6 +2794,12 @@ anno_mark = function(at, labels, which = c("column", "row"),
2794 2794
 	link_gp = lines_gp, 
2795 2795
 	extend = unit(0, "mm")) {
2796 2796
 
2797
+	if(is_RStudio_current_dev()) {
2798
+		if(ht_opt$message) {
2799
+			message_wrap("It seems you are using RStudio IDE. `anno_mark()` needs to work with the physical size of the graphics device. It only generates correct plot in the figure panel, while in the zoomed plot (by clicking the icon 'Zoom') or in the exported plot (by clicking the icon 'Export'), the connection to heatmap rows/columns might be wrong. You can directly use e.g. pdf() to save the plot into a file.\n\nUse `ht_opt$message = FALSE` to turn off this message.")
2800
+		}
2801
+	}
2802
+
2797 2803
 	if(is.null(.ENV$current_annotation_which)) {
2798 2804
 		which = match.arg(which)[1]
2799 2805
 	} else {
... ...
@@ -3335,6 +3341,12 @@ anno_zoom = function(align_to, panel_fun = function(index, nm = NULL) { grid.rec
3335 3341
 	link_width = unit(5, "mm"), link_height = link_width, link_gp = gpar(),
3336 3342
 	extend = unit(0, "mm"), width = NULL, height = NULL, internal_line = TRUE) {
3337 3343
 	
3344
+	if(is_RStudio_current_dev()) {
3345
+		if(ht_opt$message) {
3346
+			message_wrap("It seems you are using RStudio IDE. `anno_zoom()` needs to work with the physical size of the graphics device. It only generates correct plot in the figure panel, while in the zoomed plot (by clicking the icon 'Zoom') or in the exported plot (by clicking the icon 'Export'), the connection to heatmap rows/columns might be wrong. You can directly use e.g. pdf() to save the plot into a file.\n\nUse `ht_opt$message = FALSE` to turn off this message.")
3347
+		}
3348
+	}
3349
+
3338 3350
 	if(is.null(.ENV$current_annotation_which)) {
3339 3351
 		which = match.arg(which)[1]
3340 3352
 	} else {
... ...
@@ -431,6 +431,14 @@ draw_legend = function(ColorMappingList, ColorMappingParamList, side = c("right"
431 431
         } else if(side == "bottom") {
432 432
             draw(pk, y = unit(0, "npc"), just = "bottom")
433 433
         }
434
+
435
+        if(pk@nr > 1 || pk@nc > 1) {
436
+            if(is_RStudio_current_dev()) {
437
+                if(ht_opt$message) {
438
+                    message_wrap("It seems you are using RStudio IDE. There are many legends and they are wrapped into multiple rows/columns. The arrangement relies on the physical size of the graphics device. It only generates correct plot in the figure panel, while in the zoomed plot (by clicking the icon 'Zoom') or in the exported plot (by clicking the icon 'Export'), the legend positions might be wrong. You can directly use e.g. pdf() to save the plot into a file.\n\nUse `ht_opt$message = FALSE` to turn off this message.")
439
+                }
440
+            }
441
+        }
434 442
     }
435 443
 
436 444
     size = unit.c(width, height)
... ...
@@ -835,6 +835,8 @@ packLegend = function(..., gap = unit(2, "mm"), row_gap = unit(2, "mm"), column_
835 835
 		stop_wrap("Length of `column_gap` must be one.")
836 836
 	}
837 837
     n_lgd = length(legend_list)
838
+    nr = 1
839
+    nc = 1
838 840
     if(direction == "vertical") {
839 841
 	    lgd_height = do.call("unit.c", lapply(legend_list, grobHeight))
840 842
 
... ...
@@ -959,6 +961,8 @@ packLegend = function(..., gap = unit(2, "mm"), row_gap = unit(2, "mm"), column_
959 961
 	object@grob = gt
960 962
 	object@type = "packed_legends"
961 963
 	object@n = n_lgd
964
+	object@nr = nr
965
+	object@nc = nc
962 966
 	return(object)
963 967
 }
964 968
 
... ...
@@ -1053,3 +1053,17 @@ colorRamp2_biv = function(f1, f2, transparency = 0.5) {
1053 1053
     }
1054 1054
 }
1055 1055
 
1056
+
1057
+is_RStudio_current_dev = function() {
1058
+    dv = names(dev.list())
1059
+    if(length(dv) < 2) {
1060
+        FALSE
1061
+    } else {
1062
+        n = length(dv)
1063
+        if(dv[n-1] == "RStudioGD") {
1064
+            TRUE
1065
+        } else {
1066
+            FALSE
1067
+        }
1068
+    }
1069
+}