metrumresearchgroup / pmplots

Plots for Pharmacometrics
https://metrumresearchgroup.github.io/pmplots
8 stars 1 forks source link

Pass tag_levels through pm_grid #80

Closed kylebaron closed 8 months ago

kylebaron commented 8 months ago

Summary

This PR falls out of #77, where we created panels of plots and potentially annotated them with tag_levels. This lets the user to pass tag_levels to pm_grid() to tag levels after arranging. This will make pm_grid() more useful for other, existing functions that return lists of plots which are typically arranged with pm_grid().

This PR also shuffles the arguments for pm_grid(); I don't believe this will change current behavior (?) but thought it would be safest to push ... to the back.

kyleam commented 8 months ago

This PR also shuffles the arguments for pm_grid(); I don't believe this will change current behavior (?)

I suppose the main change in behavior can come when callers have been passing unnamed args through. wrap_plots() signature is patchwork::wrap_plots(..., ncol = 3, {more named args}), so any unnamed args would get absorbed by its ....

fa <- function(x, ..., y = 2) {
  fc(x, y = y, ...)
}

fb <- function(x, y = 2, ...) {
  fc(x, y = y, ...)
}

fc <- function(..., y = 200) {
  message("y:   ", deparse1(y))
  message("...: ", deparse1(list(...)))
}

fa(1, 3)
#> y:   2
#> ...: list(1, 3)
fb(1, 3)
#> y:   3
#> ...: list(1)

But, in this case, it seems very unlikely that callers are passing unnamed args through. patchwork::wrap_plots() treats ... as additional ggplot2 objects, and I don't suspect any callers rely on that rather than including the plot in x. I of course leave that judgement call up to you, but I think the move is fine.