[R] automatically calling dev.off()
Thierry Onkelinx
thierry.onkelinx at inbo.be
Tue Sep 1 16:27:29 CEST 2015
Have a look at the implementation of ggsave in the ggplot2 package.
ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Research Institute for Nature
and Forest
team Biometrie & Kwaliteitszorg / team Biometrics & Quality Assurance
Kliniekstraat 25
1070 Anderlecht
Belgium
To call in the statistician after the experiment is done may be no
more than asking him to perform a post-mortem examination: he may be
able to say what the experiment died of. ~ Sir Ronald Aylmer Fisher
The plural of anecdote is not data. ~ Roger Brinner
The combination of some data and an aching desire for an answer does
not ensure that a reasonable answer can be extracted from a given body
of data. ~ John Tukey
2015-09-01 16:21 GMT+02:00 Jeff Newmiller <jdnewmil op dcn.davis.ca.us>:
> If you are implementing your own interactive graphics device by creating files, then I would expect you to want to leave all files closed between graphics operations so your widget can interactively update as the user makes graphics calls. However, I have not done this, so could only suggest that you look at some example client code (RStudio? RGui?) and perhaps search r-devel.
> ---------------------------------------------------------------------------
> Jeff Newmiller The ..... ..... Go Live...
> DCN:<jdnewmil op dcn.davis.ca.us> Basics: ##.#. ##.#. Live Go...
> Live: OO#.. Dead: OO#.. Playing
> Research Engineer (Solar/Batteries O.O#. #.O#. with
> /Software/Embedded Controllers) .OO#. .OO#. rocks...1k
> ---------------------------------------------------------------------------
> Sent from my phone. Please excuse my brevity.
>
> On September 1, 2015 6:54:33 AM PDT, axionator <axionator op gmail.com> wrote:
>>I did it on the console only for testing. I have a program that uses
>>Rserve
>>and would like to have it therefore. (the program basically provides a
>>terminal where you can type in R commands. Since plotting is only
>>possible
>>via files (when using Rserve) that are then displayed in a widget, I
>>like
>>to avoid the overhead of writing png() ... dev.off() for each plot.)
>>
>>On Tue, Sep 1, 2015 at 3:42 PM, Jeff Newmiller
>><jdnewmil op dcn.davis.ca.us>
>>wrote:
>>
>>> Don't use options to do this in batch mode. Open and close the file
>>as you
>>> make the plot.
>>>
>>---------------------------------------------------------------------------
>>> Jeff Newmiller The ..... ..... Go
>>Live...
>>> DCN:<jdnewmil op dcn.davis.ca.us> Basics: ##.#. ##.#. Live
>>> Go...
>>> Live: OO#.. Dead: OO#..
>>Playing
>>> Research Engineer (Solar/Batteries O.O#. #.O#. with
>>> /Software/Embedded Controllers) .OO#. .OO#.
>>rocks...1k
>>>
>>---------------------------------------------------------------------------
>>> Sent from my phone. Please excuse my brevity.
>>>
>>> On September 1, 2015 4:34:41 AM PDT, axionator <axionator op gmail.com>
>>> wrote:
>>> >Hi,
>>> >is there a way to automatically call dev.off()?
>>> >I use options(device="myfunc") to automatically open a device to
>>print
>>> >to.
>>> >Afterwards, I would like to close it (so that the file is actually
>>> >written).
>>> >I tried to do it via addTaskCallback, but unfortunately, I have to
>>use
>>> >Rserve and (for any reason), the callback does not work (in the
>>default
>>> >R
>>> >console on win7 it works, however).
>>> >
>>> >So, the following runs in the R console (but not via Rserve):
>>> >
>>> >mypng <- function(filename = "test.png", ...)
>>> >{
>>> > times <- function(total = 2, str = "Task") {
>>> > ctr <- 0
>>> > function(expr, value, ok, visible) {
>>> > ctr <<- ctr + 1
>>> > keep.me <- (ctr < total)
>>> > if (ctr == total) {
>>> > cat("ENDPRINT")
>>> > dev.off()
>>> > }
>>> > keep.me
>>> > }
>>> > }
>>> > png(filename, ...)
>>> > n <- addTaskCallback(times(1))
>>> >}
>>> >options(device="mypng")
>>> >plot(rnorm(333))
>>> >
>>> >Any hints?
>>> >
>>> > [[alternative HTML version deleted]]
>>> >
>>> >______________________________________________
>>> >R-help op r-project.org mailing list -- To UNSUBSCRIBE and more, see
>>> >https://stat.ethz.ch/mailman/listinfo/r-help
>>> >PLEASE do read the posting guide
>>> >http://www.R-project.org/posting-guide.html
>>> >and provide commented, minimal, self-contained, reproducible code.
>>>
>>>
>
> ______________________________________________
> R-help op r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list