Browse code

compatible with range is NULL in `geom_range`

Guangchuang Yu authored on 27/04/2019 08:07:04
Showing 2 changed files

... ...
@@ -1,5 +1,7 @@
1 1
 # ggtree 1.15.6
2 2
 
3
++ compatible with range is NULL in `geom_range` (2019-04-27, Sat)
4
+  - <https://groups.google.com/d/msg/bioc-ggtree/yNzjtioVVGU/MCh3MPl_CwAJ>
3 5
 + remove `getChild`, `getChild.df`, `getParent`, `getParent.df`, `getSibling`, `getAncestor` and `getAncestor.df`,
4 6
   instead use `child`, `parent`, `sibling` and `ancestor` methods implemented in `tidytree` and `treeio` (2019-01-30, Wed)
5 7
 + remove `get.offspring.df` and `get.offspring.tip` and instead use `tidytree::offspring` (2019-01-28, Mon)
... ...
@@ -53,11 +53,19 @@ StatRange <- ggproto("StatRange", Stat,
53 53
 
54 54
 
55 55
 range_lower <- function(range) {
56
-    sapply(range, function(x) as.numeric(x[1]))
56
+    sapply(range, function(x) {
57
+        ## length(x) == 0 for x is NULL
58
+        ## see https://groups.google.com/d/msg/bioc-ggtree/yNzjtioVVGU/MCh3MPl_CwAJ
59
+        if (length(x) == 0)
60
+            return(NA)
61
+        as.numeric(x[1])
62
+    })
57 63
 }
58 64
 
59 65
 range_upper <- function(range) {
60 66
     sapply(range, function(x) {
67
+        if (length(x) == 0) 
68
+            return(NA) 
61 69
         if (length(x) == 1 && is.na(x))
62 70
             return(NA)
63 71
         as.numeric(x[2])