Support file arg for writing plots to disk#143
Conversation
|
This looks fantastic, thanks for the work! A few minor comments:
Super nice implementation in general. Very nice feature! |
|
Great, thanks for the feedback @vincentarelbundock!
I'll try to action these suggestions when I get a sec and then we can merge unless anything else comes up. |
|
Thanks, Grant @grantmcdermott, for adding this. I'll take a closer look later today or tomorrow! |
|
Thanks both! (@vincentarelbundock I've attempted to address all three of your comments. Please kick the tyres and see if anything unexpected happens.) |
|
Looks and works great here! Does defaulting to inches make people angry? |
|
Thanks, again, Grant. I'm still afraid that it will turn into a can of worms but I also agree that this is a nifty feature that I will use myself. Some comments:
|
|
FWIW, I agree on adding JPG and on the idea that separate arguments for height and width are probably a clearer interface than a named list. I get that we are trying to minimize the number of arguments, but this is not a common pattern and requires careful reading of the docs, whereas different arguments are easy to understand. |
|
Excellent, thanks for the additional suggestions. I'll add jpeg support and tweak the png (and I guess jpeg?) code as you suggest, @zeileis. I agree that inches won't please everyone. But I think it's the most common default nowadays and folks can always revert back to manual I'm finding myself a little more reticent to switch to a default square layout since I never use this myself. But I think you're correct that this is the most common default, so it probably makes sense. I'm more hesitant about the separate |
|
Just for clarification: I was suggesting only that when We could also try to modify the existing device but I don't think that this is always possible. Also, I'm not sure how to accomplish a specific height/width in the RStudio plots window. If you have any pointers for this, I can try to have a look though. I'll also try out what happens in knitr/quarto. |
file(name) arg for writing plots to diskfile arg for writing plots to disk
|
Okay folks, all your suggestions have now been added, including separate tinyplot(Petal.Length ~ Petal.Width | Species, data = iris, file = "~/myplot.jpg") # default 7x7
tinyplot(Petal.Length ~ Petal.Width | Species, data = iris, file = "~/myplot2.jpg", height = 4.5, width = 12) # override dimensions
tinyplot(Petal.Length ~ Petal.Width | Species, data = iris, height = 4.5, width = 12) # opens new interactive windowI think that this is now ready to merge, but either of you should feel free to test one more time and merge once you're happy. |
|
Wait, in that last example, the height and weight are standalone arguments? |
|
Ugh, hold on. Testing from a different IDE (VS Code) is giving me annoying warning about calling UPDATE: It's related to facets. I'll push a fix later today when I get time. |
Yes. I thought that was the request? |
|
Ah no, sorry, I misread: saw the last example correctly, but thought the first two were still using the old named list specification. My eyes are getting too old for small font print. I think this is super nice! Don't wait for me to merge. |
|
Minor hiccup fixed, so I'll go ahead and merge. @zeileis please feel to raise an issue if you catch something else post hoc. Thanks again both for the great feedback and suggestions. |
Closes #125.
Right now, the functionality is pretty simple: It just detects the file extension (where only ".png", ".pdf", or ".svg" are supported) and invokes the appropriate device type. Users can also control some basic elements of the output size via
tpar("file.width", "file.height", "file.res"), where the defaults are 8, 5, and 300 respectively. We might think about integrating these into the maintinyplot(..., file(name) = X)function later somehow.