Centralized and simplify xlab and ylab processing#462
Centralized and simplify xlab and ylab processing#462vincentarelbundock merged 12 commits intograntmcdermott:mainfrom
xlab and ylab processing#462Conversation
|
@grantmcdermott this is an internal refactoring for maintainability. The only change to snapshots you'll notice is that when we supply only This is a self-contained PR. I plan to take a more serious look at |
Hmmm, this is actually something that I'd like to preserve the current behaviour for. I agree it's kind of a corner case, but it's one I use surprisingly often myself and is often the first thing I show audiences when comparing |
Somehow I had not realized this was base behavior. Makes sense to stick with it then. All the old tests now pass and I added no new snapshots. |
grantmcdermott
left a comment
There was a problem hiding this comment.
Looks good, thanks. Just one or two minor comments.
| tmp = sanitize_axes(axes, xaxt, yaxt, frame.plot) | ||
| list2env(tmp, environment()) |
There was a problem hiding this comment.
Should we just do list2env(sanitize_axes(...), environment()) directly to avoid writing the temporary list?
| tmp = sanitize_xylab( | ||
| x = x, xlab = xlab, x_dep = x_dep, xmin_dep = xmin_dep, xmax_dep = xmax_dep, | ||
| y = y, ylab = ylab, y_dep = y_dep, ymin_dep = ymin_dep, ymax_dep = ymax_dep, | ||
| type = type) | ||
| list2env(tmp, environment()) |
There was a problem hiding this comment.
Same comment as above; I think it's safer to do this directly than creating a temporary variable in case something goes wrong and the value of tmp doesn't get (re)assigned properly.
|
made requested changes and merged. Thanks for the review! |
xlab and ylab` processingxlab and ylab processing
|
Vincent, thanks for this. This is much clearer than before. Given that you thought about this, I wanted to ask you whether you had any ideas for further improvement. When writing new One alternative approach would be that the Another possibility would be to explicitly list all known types from within the package in Maybe you thought about this type of problem and have some ideas? |
|
That's a good question, and I hadn't really thought about it. At the moment, I think I would lean towards this:
It's not the most elegant, and I'm sure there's a fancy approach we could invent, but I feel the main problem in readability beforehand is that things were done at several different points, and that made the logic very opaque. Keeping everything in one place is much simpler, and facilitates re-use.
Not sure we need to pollute the namespace for something like this, since the number of users affected is likely small. But one thing we could easily do is pass the deparsed The actual sanitation only ever takes a couple lines anyway, so custom type functions don't actually need a helper for this. |
|
Yes, maybe that would be an improvement. The price would be, of course, that every time we introduce a new |
The
xlabandylabarguments get processed at several different places in the (already very long)tinyplot()function. This makes it very difficult to follow, audit, or improve the logic.This is an attempt to pull out all the processing inside a single helper function called
sanitize_xylab(). This allows a few improvements for consistency:tinyplot_add()the deparsed label from the last plot is printed. test-misc.Rtinyplot(0:10)prints deparsed "0:10" on both axes instead of "Index". test-type-other.R