[R] Is there a way to open R terminal running in the background

Brad P bpschn01 at gmail.com
Wed Apr 19 18:45:39 CEST 2017


Duncan,

I was thinking to have an additional button in the GUI which would use an R
function to open the window/process running in the background.
I don't think this is a VBS question, as it is simply used to start the GUI
without opening R and calling it directly.
I suppose this may be considered a Windows question - I will look further
into opening a process running in the background using DOS commands.

Thank you for your time.


On Wed, Apr 19, 2017 at 12:14 PM, Duncan Murdoch <murdoch.duncan at gmail.com>
wrote:

> On 19/04/2017 11:44 AM, Brad P wrote:
>
>> Hello,
>>
>> I am working on a GUI, which is working well so far.
>> I am working on a Windows 7 machine with 64 bit R (Microsoft R Open 3.3.2)
>>
>> Essentially:
>> 1) a VBS executable is used to open the GUI leaving the R terminal running
>> in the background but not showing using:
>>
>> CreateObject("Wscript.Shell").Run R.exe CMD BATCH MyGUI.R , 0, TRUE
>>
>
> I think this is more of a Microsoft question than anything specific to R.
> How do you ask VBS to show you a process that it is running?
>
> No idea where to go with VBS questions.
>
> Duncan Murdoch
>
>
>> 2) for the GUI I use code similar to that shown below
>>
>> My question is, when the GUI is opened, an instance of R runs in the
>> background.
>> Is there a way to show ('open') that R terminal?  And similarly put it
>> back
>> as invisible.
>> I am imagining that I can write an R function to either open this directly
>> or by using Windows OS commands
>>
>> I have found  a way to open a terminal using the code at this link, but it
>> is not ideal (I want an actual R terminal):
>> http://freesourcecode.net/rprojects/104/sourcecode/ex-RGtk2-terminal.R
>>
>>
>>
>> # MyGUI.R ############################################################
>> ######
>> library(RGtk2)
>>
>> # initiate main window
>> main_window <<- gtkWindow(show = FALSE)
>> main_window["title"] <- "My GUI"
>> main_window$setDefaultSize(800, 600) # (width, height)
>>
>> # problem: red [X] in top-right leaves underlying R instance open
>> main_window$deletable <- FALSE  # makes the top-right [X] delete option
>> not
>> work ...
>> # Can this button be reprogrammed??
>>
>> # function to read in data file
>> open_cb <- function(widget, window) {
>>   dialog <- gtkFileChooserDialog("Choose a CSV file", window, "open",
>>                                  "gtk-cancel", GtkResponseType["cancel"],
>> "gtk-open",
>>                                  GtkResponseType["accept"])
>>   if (dialog$run() == GtkResponseType["accept"]) {
>>     fileName <<- dialog$getFilename()
>>     dat <<- read.csv(fileName, header=TRUE, na.strings=c("","NA"))
>>   }
>>   dialog$destroy()
>>   statusbar$push(info, paste("Dataset", fileName, "is currently loaded."))
>> }
>>
>> # variable to indicate whether it is time to stop R
>> StopNOW <<- 0
>>
>> quit_cb <- function(widget, window){
>>   StopNOW <<- 1
>>   window$destroy()
>>   quit(save = "no")
>> }
>>
>> # Lists actions in dropdown or toolbar menus
>> actions <- list(
>>   list("FileMenu", NULL, "Input File"),
>>   list("Open", "gtk-open", "_Import CSV File", "<control>O",
>>        "Select a CSV file to load as a spreadsheet", open_cb),
>>   list("Quit", "gtk-quit", "_Quit", "<control>Q",
>>        "Quit the application", quit_cb)
>> )
>> action_group <- gtkActionGroup("spreadsheetActions")
>> action_group$addActions(actions, main_window)
>>
>> ui_manager <- gtkUIManager()
>> ui_manager$insertActionGroup(action_group, 0)
>> merge <- ui_manager$newMergeId()
>> ui_manager$addUi(merge.id = merge, path = "/", name = "menubar", action =
>> NULL, type = "menubar", top = FALSE)
>> ui_manager$addUi(merge, "/menubar", "file", "FileMenu", "menu", FALSE)
>> ui_manager$addUi(merge, "/menubar/file", "open", "Open", "menuitem",
>> FALSE)
>> ui_manager$addUi(merge, "/", "toolbar", NULL, "toolbar", FALSE)
>> ui_manager$addUi(merge, "/toolbar", "quit", "Quit", "toolitem", FALSE)
>>
>> menubar <- ui_manager$getWidget("/menubar")
>> toolbar <- ui_manager$getWidget("/toolbar")
>> main_window$addAccelGroup(ui_manager$getAccelGroup())
>>
>> # Status bar shown at bottom left of GUI
>> statusbar <- gtkStatusbar()
>> info <- statusbar$getContextId("info")
>> statusbar$push(info, "Ready")
>>
>> notebook <- gtkNotebook()
>> notebook$setTabPos("bottom")
>>
>> vbox <- gtkVBox(homogeneous = FALSE, spacing = 0)
>> vbox$packStart(menubar, expand = FALSE, fill = FALSE, padding = 0)
>> vbox$packStart(toolbar, FALSE, FALSE, 0) # Uncomment if toolbar is used
>> vbox$packStart(notebook, TRUE, TRUE, 0)
>> vbox$packStart(statusbar, FALSE, FALSE, 0)
>> main_window$add(vbox)
>>
>> # open GUI window
>> main_window$show()
>>
>> gtkWidgetGrabFocus(main_window)
>>
>> # This repeat loop & stopNOW variable keeps the GUI window open until
>> closed
>> repeat {
>> Sys.sleep(0.001)
>>     if (StopNOW == 1) break
>>   }
>> # End GUI Code
>>
>>         [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posti
>> ng-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>>
>

	[[alternative HTML version deleted]]



More information about the R-help mailing list