Browse code

change argument length to length.out in seq()

Zuguang Gu authored on 26/11/2021 14:06:31
Showing6 changed files

... ...
@@ -1049,7 +1049,7 @@ anno_lines = function(x, which = c("column", "row"), border = TRUE, gp = gpar(),
1049 1049
 				y = value[index, i]
1050 1050
 				if(smooth) {
1051 1051
 					fit = loess(y ~ x)
1052
-					x2 = seq(x[1], x[length(x)], length = 100)
1052
+					x2 = seq(x[1], x[length(x)], length.out = 100)
1053 1053
 					y2 = predict(fit, x2)
1054 1054
 					grid.lines(y2, x2, gp = subset_gp(gp, i), default.units = "native")
1055 1055
 				} else {
... ...
@@ -1072,7 +1072,7 @@ anno_lines = function(x, which = c("column", "row"), border = TRUE, gp = gpar(),
1072 1072
 			y = value[index]
1073 1073
 			if(smooth) {
1074 1074
 				fit = loess(y ~ x)
1075
-				x2 = seq(x[1], x[length(x)], length = 100)
1075
+				x2 = seq(x[1], x[length(x)], length.out = 100)
1076 1076
 				y2 = predict(fit, x2)
1077 1077
 				grid.lines(y2, x2, gp = gp, default.units = "native")
1078 1078
 			} else {
... ...
@@ -1107,7 +1107,7 @@ anno_lines = function(x, which = c("column", "row"), border = TRUE, gp = gpar(),
1107 1107
 				y = value[index, i]
1108 1108
 				if(smooth) {
1109 1109
 					fit = loess(y ~ x)
1110
-					x2 = seq(x[1], x[length(x)], length = 100)
1110
+					x2 = seq(x[1], x[length(x)], length.out = 100)
1111 1111
 					y2 = predict(fit, x2)
1112 1112
 					grid.lines(x2, y2, gp = subset_gp(gp, i), default.units = "native")
1113 1113
 				} else {
... ...
@@ -1130,7 +1130,7 @@ anno_lines = function(x, which = c("column", "row"), border = TRUE, gp = gpar(),
1130 1130
 			y = value[index]
1131 1131
 			if(smooth) {
1132 1132
 				fit = loess(y ~ x)
1133
-				x2 = seq(x[1], x[length(x)], length = 100)
1133
+				x2 = seq(x[1], x[length(x)], length.out = 100)
1134 1134
 				y2 = predict(fit, x2)
1135 1135
 				grid.lines(x2, y2, gp = gp, default.units = "native")
1136 1136
 			} else {
... ...
@@ -1265,7 +1265,7 @@ anno_barplot = function(x, baseline = 0, which = c("column", "row"), border = TR
1265 1265
 	if(is.null(dim(x))) x = matrix(x, ncol = 1)
1266 1266
 	nc = ncol(x)
1267 1267
 	if(missing(gp)) {
1268
-		gp = gpar(fill = grey(seq(0, 1, length = nc+2))[-c(1, nc+2)])
1268
+		gp = gpar(fill = grey(seq(0, 1, length.out = nc+2))[-c(1, nc+2)])
1269 1269
 	}
1270 1270
 
1271 1271
 	if(beside) {
... ...
@@ -1795,7 +1795,7 @@ anno_histogram = function(x, which = c("column", "row"), n_breaks = 11,
1795 1795
 
1796 1796
 	n = length(value)
1797 1797
 	x_range =range(unlist(value), na.rm = TRUE)
1798
-	histogram_stats = lapply(value, hist, plot = FALSE, breaks = seq(x_range[1], x_range[2], length = n_breaks))
1798
+	histogram_stats = lapply(value, hist, plot = FALSE, breaks = seq(x_range[1], x_range[2], length.out = n_breaks))
1799 1799
 	histogram_breaks = lapply(histogram_stats, function(x) x$breaks)
1800 1800
 	histogram_counts = lapply(histogram_stats, function(x) x$counts)
1801 1801
 
... ...
@@ -2005,7 +2005,7 @@ anno_density = function(x, which = c("column", "row"),
2005 2005
 		min_y = min(unlist(density_y))
2006 2006
 		max_y = max(unlist(density_y))
2007 2007
 		col_fun = colorRamp2(seq(min_y, max_y, 
2008
-			length = length(heatmap_colors)), heatmap_colors)
2008
+			length.out = length(heatmap_colors)), heatmap_colors)
2009 2009
 	}
2010 2010
 
2011 2011
 	axis_param$direction = "normal"
... ...
@@ -2092,7 +2092,7 @@ anno_density = function(x, which = c("column", "row"),
2092 2092
 			min_y = min(unlist(density_y))
2093 2093
 			max_y = max(unlist(density_y))
2094 2094
 			col_fun = colorRamp2(seq(min_y, max_y, 
2095
-				length = length(heatmap_colors)), heatmap_colors)
2095
+				length.out = length(heatmap_colors)), heatmap_colors)
2096 2096
 		}
2097 2097
 
2098 2098
 		n = length(index)
... ...
@@ -578,7 +578,7 @@ Heatmap = function(matrix, col, name,
578 578
                     .Object@matrix_color_mapping = ColorMapping(colors = col, name = name, na_col = na_col)
579 579
                     if(verbose) qqcat("input color is a vector with no names, treat it as discrete color mapping\n")
580 580
                 } else if(is.numeric(matrix)) {
581
-                    col = colorRamp2(seq(min(matrix, na.rm = TRUE), max(matrix, na.rm = TRUE), length = length(col)),
581
+                    col = colorRamp2(seq(min(matrix, na.rm = TRUE), max(matrix, na.rm = TRUE), length.out = length(col)),
582 582
                                      col, space = color_space)
583 583
                     .Object@matrix_color_mapping = ColorMapping(col_fun = col, name = name, na_col = na_col)
584 584
                     if(verbose) qqcat("input color is a vector with no names, treat it as continuous color mapping\n")
... ...
@@ -501,7 +501,7 @@ SingleAnnotation = function(name, value, col, fun,
501 501
                     names(col) = sort(unique(value))
502 502
                     if(verbose) qqcat("@{names}: add names for discrete color mapping\n")
503 503
                 } else if(is.numeric(value)) {
504
-                    col = colorRamp2(seq(min(value, na.rm = TRUE), max(value, na.rm = TRUE), length = length(col)), col)
504
+                    col = colorRamp2(seq(min(value, na.rm = TRUE), max(value, na.rm = TRUE), length.out = length(col)), col)
505 505
                     if(verbose) qqcat("@{name}: assume as a continuous color mapping\n")
506 506
                 }
507 507
             }
... ...
@@ -132,7 +132,7 @@ densityHeatmap = function(data,
132 132
 		min_x = range[1]
133 133
 	}
134 134
 	
135
-	x = seq(min_x, max_x, length = 500)
135
+	x = seq(min_x, max_x, length.out = 500)
136 136
 
137 137
 	mat = lapply(density_list, function(r) {
138 138
 			f = approxfun(r$x, r$y)
... ...
@@ -156,7 +156,7 @@ densityHeatmap = function(data,
156 156
 	if(inherits(col, "function")) {
157 157
 		col = col(mat)
158 158
 	} else {
159
-		col = colorRamp2(seq(0, quantile(mat, 0.99, na.rm = TRUE), length = length(col)), col, space = color_space)
159
+		col = colorRamp2(seq(0, quantile(mat, 0.99, na.rm = TRUE), length.out = length(col)), col, space = color_space)
160 160
 	}
161 161
 
162 162
 	bb = grid.pretty(c(min_x, max_x))
... ...
@@ -464,7 +464,7 @@ frequencyHeatmap = function(data,
464 464
 	if(inherits(col, "function")) {
465 465
 		col = col(mat)
466 466
 	} else {
467
-		col = colorRamp2(seq(0, quantile(mat, 0.99, na.rm = TRUE), length = length(col)), col, space = color_space)
467
+		col = colorRamp2(seq(0, quantile(mat, 0.99, na.rm = TRUE), length.out = length(col)), col, space = color_space)
468 468
 	}
469 469
 
470 470
 	bb = grid.pretty(c(min_x, max_x))
... ...
@@ -174,9 +174,9 @@ heatmap = function(x,
174 174
         n_col = length(col)
175 175
         if(identical(scale, "row") || identical(scale, "column")) {
176 176
             lim = max(abs(mat), na.rm = TRUE)
177
-            ht_param$col = colorRamp2(seq(-lim, lim, length = n_col), col)
177
+            ht_param$col = colorRamp2(seq(-lim, lim, length.out = n_col), col)
178 178
         } else {
179
-            ht_param$col = colorRamp2(seq(min(mat, na.rm = TRUE), max(mat, na.rm = TRUE), length = n_col), col)
179
+            ht_param$col = colorRamp2(seq(min(mat, na.rm = TRUE), max(mat, na.rm = TRUE), length.out = n_col), col)
180 180
         } 
181 181
     }
182 182
     
... ...
@@ -567,11 +567,11 @@ heatmap.2 = function(x,
567 567
     if(length(breaks)==1)
568 568
     {
569 569
       if(!symbreaks)
570
-        breaks <- seq( min(mat, na.rm=na.rm), max(mat,na.rm=na.rm), length=breaks)
570
+        breaks <- seq( min(mat, na.rm=na.rm), max(mat,na.rm=na.rm), length.out = breaks)
571 571
       else
572 572
         {
573 573
           extreme <- max(abs(mat), na.rm=TRUE)
574
-          breaks <- seq( -extreme, extreme, length=breaks )
574
+          breaks <- seq( -extreme, extreme, length.out = breaks )
575 575
         }
576 576
     }
577 577
 
... ...
@@ -585,9 +585,9 @@ heatmap.2 = function(x,
585 585
 
586 586
     if(exists("extreme")) {
587 587
         lim = max(abs(mat), na.rm = TRUE)
588
-        ht_param$col = colorRamp2(seq(-lim, lim, length = n_col), col)
588
+        ht_param$col = colorRamp2(seq(-lim, lim, length.out = n_col), col)
589 589
     } else {
590
-        ht_param$col = colorRamp2(seq(min(mat, na.rm = TRUE), max(mat, na.rm = TRUE), length = n_col), col)
590
+        ht_param$col = colorRamp2(seq(min(mat, na.rm = TRUE), max(mat, na.rm = TRUE), length.out = n_col), col)
591 591
     } 
592 592
     
593 593
 
... ...
@@ -792,7 +792,7 @@ heatmap.2 = function(x,
792 792
                     width = unit(1, "npc") - left_width - unit(2, "mm"), height = unit(1, "npc") - bottom_height- top_height,
793 793
                     just = c("left", "bottom"), xscale = x_range, yscale = y_range))
794 794
 
795
-                x = seq(min(breaks), max(breaks), length = 101)
795
+                x = seq(min(breaks), max(breaks), length.out = 101)
796 796
                 grid.rect(x = x[1:100], width = (x_range[2] - x_range[1])/100, default.units = "native", just = "left",
797 797
                     gp = gpar(fill = ht_param$col(x + (x_range[2] - x_range[1])/100*0.5), col = NA))
798 798
 
... ...
@@ -171,9 +171,9 @@ pheatmap = function(mat,
171 171
             n_col = length(color)
172 172
             if(identical(scale, "row") || identical(scale, "column")) {
173 173
                 lim = max(abs(mat), na.rm = TRUE)
174
-                ht_param$col = colorRamp2(seq(-lim, lim, length = n_col), color)
174
+                ht_param$col = colorRamp2(seq(-lim, lim, length.out = n_col), color)
175 175
             } else {
176
-                ht_param$col = colorRamp2(seq(min(mat, na.rm = TRUE), max(mat, na.rm = TRUE), length = n_col), color)
176
+                ht_param$col = colorRamp2(seq(min(mat, na.rm = TRUE), max(mat, na.rm = TRUE), length.out = n_col), color)
177 177
             }
178 178
         } else  {
179 179
             if(length(breaks) == length(color) + 1) {
... ...
@@ -201,7 +201,7 @@ pheatmap = function(mat,
201 201
                 ht_param$col = colorRamp2(breaks, color)
202 202
             } else {
203 203
                 n_col = length(color)
204
-                ht_param$col  = colorRamp2(seq(min(breaks), max(breaks), length = n_col), color)
204
+                ht_param$col  = colorRamp2(seq(min(breaks), max(breaks), length.out = n_col), color)
205 205
                 warning_wrap("`breaks` does not have the same length as `color`. The colors are interpolated from the minimal to the maximal of `breaks`.")
206 206
             }
207 207
         }
... ...
@@ -311,7 +311,7 @@ pheatmap = function(mat,
311 311
                 if(is.null(names(annotation_colors[[nm]])) && is.numeric(annotation_col[, nm])) {
312 312
                     foo_x = annotation_col[, nm]
313 313
                     foo_n_col = length(annotation_colors[[nm]])
314
-                    annotation_colors[[nm]] = colorRamp2(seq(min(foo_x), max(foo_x), length = foo_n_col), annotation_colors[[nm]])
314
+                    annotation_colors[[nm]] = colorRamp2(seq(min(foo_x), max(foo_x), length.out = foo_n_col), annotation_colors[[nm]])
315 315
                 }
316 316
             }
317 317
         }
... ...
@@ -339,7 +339,7 @@ pheatmap = function(mat,
339 339
                 if(is.null(names(annotation_colors[[nm]])) && is.numeric(annotation_row[, nm])) {
340 340
                     foo_x = annotation_row[, nm]
341 341
                     foo_n_col = length(annotation_colors[[nm]])
342
-                    annotation_colors[[nm]] = colorRamp2(seq(min(foo_x), max(foo_x), length = foo_n_col), annotation_colors[[nm]])
342
+                    annotation_colors[[nm]] = colorRamp2(seq(min(foo_x), max(foo_x), length.out = foo_n_col), annotation_colors[[nm]])
343 343
                 }
344 344
             }
345 345
         }