[R] Graphics after invoking R from the command line

Prof Brian Ripley ripley at stats.ox.ac.uk
Wed Nov 28 19:18:31 CET 2007


On Wed, 28 Nov 2007, Mithun Jacob wrote:

>>> Duncan Murdoch
>
> I wish to run R with Visual C++ as a front end. So I was hoping to run
> a file such as graph.r in the following manner:
>
> R --slave --save --file=graph.r
>
> But when the plot function runs, it does not display the graph.
>
>>> Prof Brian Ripley:

Eh, that's not me you are quoting!

> So would I be correct to assume that it's not possible to run graphics
> in batch mode?

Running the on-screen device is not intended to be done in batch mode, no. 
(It would be useless as it would disappear at the end of the 
computations.)  You can pipe to stdin and use --ess to force R to behave 
interactively.  Better, you could use an embedded R via (D)COM or 
Rserve or otherwise (see `Writing R Extensions').

In future, please consider posing your real problem rather than asking 
about a solution to an unstated problem that few of us would have 
contemplated.

AND mention 'Windows' in your subject line, as all this is specific to 
Windows.

>
> Thanks for all the help!
>
> Regards,
> Mithun
>
> On 11/28/07, Prof Brian Ripley <ripley at stats.ox.ac.uk> wrote:
>> On Wed, 28 Nov 2007, Mithun Jacob wrote:
>>
>>> I've tried running graphics commands like plot by invoking R at the
>>> command line but the graphics window does not appear. I'm using
>>> R-2.6.0 on Windows XP and am using the cmd shell. Here's a sample
>>> session:
>>>
>>> R --slave --save --file=-
>>> x<-c(1,2,3,4)
>>> plot(x,x)
>>>
>>> This leads to nothing. I've found a way around it, but the graph
>>> window is frozen and commands to it have to be sent twice for the data
>>> to appear.
>>>
>>> R --slave --save --file=-
>>> x<-c(1,2,3,4)
>>> windows()
>>> plot(x,x)
>>> plot(x,x)
>>>
>>> Am I doing something wrong here? It would be nice if I could display a
>>> graphics window which isn't frozen.
>>
>> So use R interactively, rather than in batch mode typing at stdin. (Using
>> --file puts you into batch mode.) Only in interactive use does the event
>> loop give time to windows such as the screen device, pagers, data frame
>> viewers ....
>>
>> I have no idea where you got the idea of 'R --slave --save --file=-' from:
>> the way to use R 'at the command line' on Windows is to use Rterm.
>> 'Rterm --slave --save' would do the same without the freezing, but most
>> people do find prompts useful.

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595



More information about the R-help mailing list