[R] bringToTop without focus?

christian.ritter at shell.com christian.ritter at shell.com
Thu Aug 3 15:47:32 CEST 2006


Thanks for fast response.

'Had another look at the problem and found a partial but nice solution which will solve my present problem and might be useful to others.

Here is the context:
In fact I have all my data and stuff in Excel and I use R(D)COM with Rexcel to communicate with R and do some of the work there. One of the things I do is to create a graph in R and to display it. To make sure it stays visible, I use bringToTop(stay=TRUE) from R. But then I would like to keep working in Excel without having to re-activate the workbook window. This is where the problem originated. Within excel there is a somewhat crude solution:
Submit the code which makes the graph via a VBA procedure (macro) and end it with SendKeys "%{TAB}". Here is an example:

  Sub Refilter
  Range("Alldata").AdvancedFilter Action:=xlFilterCopy, CriteriaRange:=Range( _
        "Criteria"), CopyToRange:=Range("Extractrange"), Unique:=False
  SendCommands Range("DiagPlot")
  SendKeys "%{TAB}"
  End sub

Here "DiagPlot" is a range which contains the code to construct the plot such as plot(x,y). 

The VBA macro should be run when the worksheet of interest has focus. The call SendKeys "%{TAB}" simulates pressing ALT TAB which goes back to the previous window on the stack. This was the one which had focus when bringToTop. There we go. 

Have a nice day,

Chris.

Morale: if impossible / change the point of view

-----Original Message-----
From: Duncan Murdoch [mailto:murdoch at stats.uwo.ca]
Sent: Thursday, 03 August, 2006 3:18 PM
To: Ritter, Christian C GSMCIL-GSTMS/2
Cc: r-help at stat.math.ethz.ch
Subject: Re: [R] bringToTop without focus?


On 8/3/2006 9:13 AM, christian.ritter at shell.com wrote:
> Hi all who know R on Windows,
> 
> Quick question: Is there a way to do "bringToTop(stay=TRUE)" without giving "focus"? I would like to pop a graph window but I would like to preserve focus in the window which I was in before. 

No, there's no way to do that.  The closest is

{ bringToTop(stay=TRUE); bringToTop(-1) }

but that only works if the previous window was the console.

Duncan Murdoch



More information about the R-help mailing list