I made a GUI using RGtk2 named Main.R that works perfectly when run from RStudio but only works in CMD when I open R in it and then source the script. My goal is to make it fully portable and thus to write a .bat file able to run it.
Classical commands R CMD BATCH Main.R and Rscript Main.R don't work. In these cases, instead of waiting for me to interact, the window is closed immediately after its creation. After some research I only found out that the OP from run R script from .bat (batch file) (sadly unanswered) encountered a similar issue, but my question differs from his so I still believe my post is justified.
These commands don't even work for a very simplistic program I made with the same library, which indicates that the issue may be caused by GTk itself.
library(RGtk2)
Destroy <- function(button) {
window $ destroy()
}
vbox <- gtkVBoxNew (FALSE, 10, TRUE) #container for the first tab
vbox $ setBorderWidth (10)
label <- gtkLabelNew ("Welcome ! Click on the button to close the window")
vbox $ packStart (label, TRUE, 20, 0)
closeButton <- gtkButtonNewWithLabel("Close")
vbox $ packStart(closeButton, FALSE, FALSE, 0)
gSignalConnect (closeButton , "clicked" , Destroy)
#links the startButton to the Start function
window <- gtkWindow (NULL, FALSE)
window ["title"] <- "Example"
gtkWindowResize(window, 800, 450)
window $ add (notebook)
window $ showAll()
In my batch file, I tried this among other variants :
@echo off
title OCR GUI
start R.exe & "source("OCR_MR/R/Main.R")"
But of course the file executes the last line when the R session is closed manually. As R.exe can't take any arguments I need to make my batch file make an input inside R. Is there any way to do it ?
Any help will be highly appreciated !
UPDATE : Thanks to some comments I realised Rscript doesn't wait for any kind of input, even
readline(prompt="message")
doesn't work. It may be an issue of running interactive commands in a non-interactive mode, will keep you updated !