wligtenberg/ggplot2 — comment on commit 471885146b26321e93b345259f28a277eaf8c91d
File:  line 0
By wch:

I think you could simplify and reduce redundancy with something roughly like this:

```R

fspace <- list(
x = any(space %in% c("free_x", "free")),
y = any(space %in% c("free_y", "free"))
)

# Set default to fixed space
panel_widths <- rep(unit(1, "null"), ncol)
panel_heights <- rep(unit(1 * aspect_ratio, "null"), nrow)

size <- function(x) unit(diff(scale_dimension(x)), "null")

if (fspace$x) {
x_scales <- panel$layout$SCALE_X[panel$layout$ROW == 1]
panel_widths <- do.call("unit.c", llply(panel$x_scales, size))[x_scales]
}

if (fspace$y) {
y_scales <- panel$layout$SCALE_Y[panel$layout$COL == 1]
panel_heights <- do.call("unit.c", llply(panel$y_scales, size))[y_scales]
}

```