grantmcdermott / tinyplot

Lightweight extension of the base R graphics system
https://grantmcdermott.com/tinyplot
Apache License 2.0
204 stars 7 forks source link

Plot writing / saving argument #125

Closed grantmcdermott closed 3 months ago

grantmcdermott commented 4 months ago

(Following on from https://github.com/grantmcdermott/tinyplot/issues/121#issuecomment-1941993963)

Something like:

tinyplot(1:10, save = "myplot.png")

or

tinyplot(1:10, file = "myplot.png")

Internally, this would need to open the appropriate graphics device based on the filename extension (here: png()) and call dev.off() right at the end.

We could potentially even support "in-memory" saving via recordPlot() if no extension is detected... although the interface might not be as clean. (Users would still have to call replayPlot() afterwards?)

vincentarelbundock commented 4 months ago

I kind of like this, because I'm too dumb to ever remember any of the graphics settings.

zeileis commented 4 months ago

I can see that this might be nifty. However, my feeling is that this opens a whole new can of worms that might lead to "feature creep"

In short: Selecting the supported parameters is not straightforward IMO.

grantmcdermott commented 4 months ago

Thanks @zeileis, I definitely hear you on the risk of feature creep. But, motivated by the fact that I personally would find this useful, I think we can potentially strike a reasonable compromise for the most common use cases:

Let me test out a dummy version and then submit a PR for you both to look at.

zeileis commented 4 months ago

OK, thanks, worth a try!

Will height/width/units only be honored when plotting to one of the file devices?

J-Moravec commented 4 months ago

Perhaps less obvious to users, but tinyplot(..., dev = NULL)

When dev is NULL default device is used, guessed in the same way it is done for standard plot().

The dev can be either device from ?Devices, or file name with an extension from which the device will be guestimated.

caleb-kwon commented 4 months ago

Not sure if this opinion is helpful at all, but I have now incorporated this wonderful package into my main workflow, and I think adding a writing/save argument would be an amazing addition.

Many thanks for all that you do @grantmcdermott!

grantmcdermott commented 3 months ago

Hey folks, I have a PR supporting this in #143 (branch: "filename"). This is one of the last things I want to enable / decide on before CRAN submission. So please try it out and report back under the PR.