[R] Displaying Grahics to the X Window when calling R from command line

Prof Brian Ripley ripley at stats.ox.ac.uk
Wed Apr 16 14:52:25 CEST 2008


On Wed, 16 Apr 2008, Pologruto, Thomas wrote:

> Thank you for your response.  I tried searching the archives but did not
> know that it was called X11() device.
>
> Can this be done in version 2.6.2 or do I need to have version 2.7.0

Flag --interactive is only in 2.7.0.  There is no simple way to get 2.6.2
to accept input redirected from a script and run the event loop on which
X11() depends.  (One non-simple way is to write an alternative front end.)

> running?  Also, when you say wait in my script, I need to put a sleep or
> something in the script or else it will delete the plot when the script
> exits?

You need to ensure that the script does not exit, which will close the
device (not just delete the plot).  Sys.sleep() may not be sufficiently
flexible -- one idea is to use locator() to get the viewer to click on the
plot when done with it.

Another route is to generate the plot as, say, a PNG file and launch a
separate viewer to show that via system(wait=FALSE).


> Thanks you again,
> Tom
>
>
>
>
> Please follow the attached hyperlink to an important disclosure:
> http://www.credit-suisse.com/legal/marketcommentary
>
>
> -----Original Message-----
> From: Prof Brian Ripley [mailto:ripley at stats.ox.ac.uk]
> Sent: Wednesday, April 16, 2008 3:12 AM
> To: Pologruto, Thomas
> Cc: r-help at r-project.org
> Subject: Re: [R] Displaying Grahics to the X Window when calling R from
> command line
>
> The issue is that the X11() device is the default device only in
> interactive use, and further than the event loop is only run in
> interactive use.
>
> You need to
>
> 1) make use of R 2.7.0 RC
> 2) call R with R --vanilla --interactive
> 3) arrange for your script to wait for something so the plot remains up.
>
> This has come up before, so please search the archives for more details.
>
>
> On Tue, 15 Apr 2008, Pologruto, Thomas wrote:
>
>> Hi,
>>
>> I am running an R script from the command line by calling:
>>
>>> R --vanilla < test.R
>>
>> My terminal is part of the Xwin (Xterm) and there is a plot(1:10)
>> command in the test.R script.
>>
>> This will not produce a grahic though.
>
> I think it does, on a PostScript or PDF file.
>
>> When I start R by calling R then
>> plotting from the R command in the same xterm, I do get a graphic
>> display.
>>
>> How do I create a xwin plot by calling R from the command line?
>>
>> Any help is most appreciated.  I have preprocessed the data in perl
>> and then feed it into my R script and want to see a plot on the
> screen.
>>
>> Thanks,
>> Tom
>>
>> ======================================================================
>> ======== Please access the attached hyperlink for an important
>> electronic communications disclaimer:
>>
>> http://www.credit-suisse.com/legal/en/disclaimer_email_ib.html
>> ======================================================================
>> ========
>>
>> 	[[alternative HTML version deleted]]
>>
>> ______________________________________________
>> R-help at r-project.org mailing list
>> 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.
>>
>
> --
> 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
>
>
> ==============================================================================
> Please access the attached hyperlink for an important electronic communications disclaimer:
>
> http://www.credit-suisse.com/legal/en/disclaimer_email_ib.html
> ==============================================================================
>
>

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