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

Abby Spurdle @purd|e@@ @end|ng |rom gm@||@com
Thu Jan 30 07:05:49 CET 2020


> 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.

The previous script isn't very good.
I've improved it.
The new version has been tested on Linux and Windows, and with lattice
and ggplot2.

I note that the script is more complex that originally intended.
And I suspect that there maybe (mostly small) problems, that would
require further maintenance.

Running R (by itself) non-REPL with partial interactivity, while it
has merit, may be problematic, in the long run.
(Unless, of course, one were to hack the graphics device(s), but that
would probably be a lot of work).

But in saying that, you're welcome to run R, however, you like.

----------------page.r----------------
os = tolower (Sys.info ()[1])
if (os == "windows")
    options (device = windows)
if (os == "linux")
    options (device = X11)

.initialize = function ()
{   n = length (dev.list () )
    if (n > 0)
        locator (1)
}

.finalize = function ()
{   n = length (dev.list () )
    if (n > 0)
        invisible (locator (1) )
}

"+" = function (a, b)
{   object = base::`+` (a, b)
    if (inherits (object, "gg") )
        print (object)
    object
}

.prompt = function (pkg, fun)
{   fbody = character (1)
    fbody [1] = paste (fun, "=", 'function (...) {')
    fbody [2] = '.initialize ()'
    fbody [3] = paste ('print (', pkg, '::', fun, '(...) )', sep="")
    fbody [4] = "}"
    eval (str2lang (paste (fbody, collapse="\n") ), -2)
}

####################################################
#add other top-level plotting functions, if required
####################################################
.prompt ("graphics", "plot")
.prompt ("lattice", "xyplot")
.prompt ("ggplot2", "ggplot")
####################################################

args = commandArgs (TRUE)
source (args [1])

.finalize ()
----------------EOF----------------

Usage is similar to before:
> Rscript page.r myfile.r

The file <myfile.r> shouldn't require any modification, can have multiple plots.

Click on the plot, to move to next one...



More information about the R-help mailing list