Re: [R] getGraphicsEvent plotting two graph

From: Greg Snow <Greg.Snow_at_imail.org>
Date: Mon, 14 Apr 2008 09:38:38 -0600

I think that the problem is with the dev.off commands.

The first time running b there are not a device 2 and device 3 so dev.off does nothing (or if they did exist then they are turned off). Then you set the graphics event callback which attaches to the current graph window (number 3 in general). Then when you call b again, this graphics device goes away and since the callback is attached to that device, the callback goes away as well and either that stops the execution, or things just get confused.

I would recommend instead of using dev.off, use dev.set with dev.prev and dev.next to move between active windows (create the 2 windows the first time, but just move between them after that, don't delete and create new ones). That should help, and will also work better if there are multiple open devices before calling a.

Hope this helps,

-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.snow_at_imail.org
(801) 408-8111
 
 


> -----Original Message-----
> From: r-help-bounces_at_r-project.org
> [mailto:r-help-bounces_at_r-project.org] On Behalf Of
> cgenolin_at_u-paris10.fr
> Sent: Sunday, April 13, 2008 6:49 AM
> To: r-help_at_r-project.org
> Subject: [R] getGraphicsEvent plotting two graph
>
> Hi the list,
>
> I need to use getGraphicsEvent to plot two graph. On the following toy
> example:
> - the function b is ploting two graph depending on a parameter
> - the function a is calling b according to some user answers.
> It is suppose to call b until the user press Return, but it does not.
>
>
> b <- function(x){
> dev.off(2);dev.off(3)
> windows();windows(3,3,xpos=0)
> dev.set(2);plot(1:x)
> dev.set(3);plot(1:x^2)
> return(NULL)
> }
> b(2)
>
> a <- function(y){
> b(y)
> getGraphicsEvent("Arrow Up or Return",
> onKeybd=function(key){
> if(key!="ctrl-J"){
> if(key=="Up"){y <<- y+1}else{}
> b(y)
> cat("\n*** This function a never gets here... ***\n")
> return(NULL)
> }else{
> return(TRUE)
> }
> }
> )
> }
>
> a(3)
>
> Is there something wrong in my code, or something I did not
> understand in getGraphicsEvent ?
> I try on R 2.2.1, then on R 2.7
>
> Thanks for your help.
>
> Christophe
>
> ----------------------------------------------------------------
> Ce message a ete envoye par IMP, grace a l'Universite Paris
> 10 Nanterre
>
> ______________________________________________
> 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.
>
______________________________________________ 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.
Received on Mon 14 Apr 2008 - 18:58:53 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 14 Apr 2008 - 19:30:28 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive