@@ -933,26 +933,20 @@ redistribute_null_units <- function(units, spacing, margin, type = "width") {
933
933
}
934
934
935
935
# Get spacing between guides and margins in absolute units
936
- size <- switch (type , width = convertWidth , height = convertHeight )
937
- spacing <- size(spacing , " cm" , valueOnly = TRUE )
938
- spacing <- sum(rep(spacing , length(units ) - 1 ))
936
+ size <- switch (type , width = width_cm , height = height_cm )
937
+ spacing <- sum(rep(spacing , length.out = length(units ) - 1 ))
939
938
margin <- switch (type , width = margin [c(2 , 4 )], height = margin [c(1 , 3 )])
940
- margin <- sum(size(margin , " cm " , valueOnly = TRUE ))
939
+ margin <- sum(size(margin ))
941
940
942
941
# Get the absolute parts of the unit
943
- absolute <- vapply(units , function (u ) {
944
- u <- absolute.size(u )
945
- u <- size(u , " cm" , valueOnly = TRUE )
946
- sum(u )
947
- }, numeric (1 ))
948
- absolute_sum <- sum(absolute ) + spacing + margin
942
+ absolute <- vapply(units , function (u ) sum(size(absolute.size(u ))), numeric (1 ))
943
+ absolute_sum <- sum(absolute ) + sum(size(spacing )) + margin
949
944
950
945
# Get the null parts of the unit
946
+ num_null <- function (x ) sum(as.numeric(x )[unitType(x ) == " null" ])
951
947
relative <- rep(0 , length(units ))
952
- relative [has_null ] <- vapply(units [has_null ], function (u ) {
953
- sum(as.numeric(u )[unitType(u ) == " null" ])
954
- }, numeric (1 ))
955
- relative_sum <- sum(relative )
948
+ relative [has_null ] <- vapply(units [has_null ], num_null , numeric (1 ))
949
+ relative_sum <- sum(relative ) + num_null(spacing )
956
950
957
951
if (relative_sum == 0 ) {
958
952
return (unit(absolute , " cm" ))
0 commit comments