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

Abby Spurdle @purd|e@@ @end|ng |rom gm@||@com
Tue Jan 28 01:27:55 CET 2020


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