2

I developed an analyzer with GUI (utilizing gWidgets package). Everything seems good when I run my code in R console or R studio, GUI can popup as expected, interaction goes smoothly by choosing options.

However, my manager has no idea about coding stuff, and what he wants is click-N-run. So I tried to use R CMD BATCH to create .bat file.

R CMD BATCH G:\Temp\dav\AB_Analyzer\MAINcode.r outputFile

When I ran the bat file, there is nothing popping up.

May I know what I did wrong?

Thanks for any help.

R Yoda
  • 8,358
  • 2
  • 50
  • 87
  • 2
    I would think this has something to do with the fact that R CMD BATCH will *Run R non-interactively with input from infile and send output (stdout/stderr) to another file*. (as per the help file!) – mnel Sep 10 '13 at 23:16
  • Do you have any idea on how to have a click-n-run shortcut? – simeonyyyyyy Sep 11 '13 at 16:36
  • 1
    Ok, it seems that R CMD BATCH doesn't work for interactive GUI. I got another way, credit to the genius http://drunks-and-lampposts.com/2012/06/18/r-creating-a-shortcut-to-run-a-gwidgets-gui/ – simeonyyyyyy Sep 11 '13 at 22:08

1 Answers1

1

If you run an R script in batch mode (R CMD BATCH) the "interactive flag" is set to false which may trigger this behaviour (no user interaction = do not show any GUI).

You can query the "interactive flag" with the interactive() function in R.

Possible solution: Add the --interactive parameter to the command line.

To test his behaviour create an R script file with the following content:

print(interactive())

If you run this script with

R CMD BATCH --no-save --no-restore  batch_test.R out.txt

You will find the result FALSE in the out.txt file, if you run it with

R --vanilla --interactive  < batch_test.R

You will see a TRUE (so use the last command line as solution - note: without CMD).

R Yoda
  • 8,358
  • 2
  • 50
  • 87
  • 2
    Thank you for this. That last line is the only way I could get this to work for me, despite trying it many different ways from various answers here and elsewhere. I don't fully understand why, even after reading the help pages - but I'm glad it does! The only variation I had to use was switching `--interactive` to `--ess` as I'm on Windows. Then it works perfectly if you specifically call R.exe or Rterm.exe, but *not* RScript.exe. – Mooks Jul 01 '20 at 15:33
  • 1
    Thanks for point out the command line arg for Windows (which seems to lack the `--interactive` arg but `--ess` looks good (ess = don't use getline for command-line editing and assert interactive use"). – R Yoda Jul 01 '20 at 16:04