[R] [FORGED] Re: Executing an R script and show the plots.

Felix Blind |e||xb||nd @end|ng |rom gm@||@com
Tue Jan 28 13:02:51 CET 2020


Thanks Abby,

I am using Linux and device X11 worked for me in the past. I will check
your script later and tell you if it works.

On 1/28/20 1:27 AM, Abby Spurdle wrote:
> Here's a solution for Windows, for use with graphics::plot.
> Using, Linux and grid or ggplot2, may require some modification.
> (However, I assuming the modifications would be easy to make).
>
> You can create a file, say quasi_interactive.r
>
> ----quasi_interactive.r----
> #for use with windows only
> options (device = windows)
>
> .initialize = function ()
> {   n = length (dev.list () )
>     if (n == 0)
>         windows ()
>     else
>         locator (1)
> }
>
> .finalize = function ()
> {   n = length (dev.list () )
>     if (n > 0)
>         invisible (locator (1) )
> }
>
> #assumes plots called with graphics::plot function
> plot = function (x, ...)
> {   .initialize ()
>     graphics::plot (x, ...)
> }
>
> args = commandArgs (TRUE)
> source (args [1])
>
> .finalize ()
> ----end-of-file----
>
> Then at the terminal, use either of:
>> Rscript quasi_interactive.r my_script_file.r
>> R -f quasi_interactive.r --args test.r
> The first option is probably better.
>
> Also, instead of locator (1) you could test for text input (say by
> pressing enter), or wait (say 10 seconds per plot).
> Another option is to open one graphics device for each plot.
>
> B.



More information about the R-help mailing list