I am trying to create an icon on my desktop (Windows OS). By clicking on this icon, an R script will be executed, which launches a GUI application (gWidgets
).

- 59,984
- 12
- 142
- 149

- 655
- 4
- 8
- 17
4 Answers
Read the help file ?Startup for details on what R goes through in the startup process and how you can automate running code.
I have done things like this for clients where I create a GUI for a specific demonstration (I use tcltk, but all should work the same). I created a desktop shortcut for them and modified the shortcut to start in a specific folder (but run the standard Rgui program), then in that folder I save a .Rdata file with all the code and data that the demo needs along with a function named .First that starts the demo.
Then the client does not need to know anything about R, just double click the shortcut and R starts and my demo starts automatically for them, they enter some numbers, click some options, slide some sliders, etc. and click on "OK" to see a graph or other output customized to their situation.

- 48,497
- 6
- 83
- 110
-
1Thank you. This method is now more elaborately written [here](http://drunks-and-lampposts.com/2012/06/18/r-creating-a-shortcut-to-run-a-gwidgets-gui/) and [here](http://4dpiecharts.com/2012/07/20/look-ma-no-typing-autorunning-code-on-r-startup/). – Stéphane Laurent Jul 11 '14 at 09:48
I think your looking for a batch file to launch a file ?
if so check this out, this comment lists how to do it in command prompt, turn that into a batch file.
https://stat.ethz.ch/pipermail/r-help/2002-March/019950.html

- 8,293
- 5
- 32
- 56
-
1I have tried R CMD BATCH but my file is a GUI with gWidgets objects and window. This command doesnt open the GUI. – SilverSpoon Apr 25 '12 at 09:17
-
A batch file or windows script file can easily replace your default `.Rprofile` file with one of your choice which contains a command to `source` anything you want (this file executes automatically when R starts up). Your comment that your "file is a GUI" is unclear. Your file *initiates* a GUI. If `source(abc.R)` works at the console, but not under batch, then it probably means you need to load required libraries before sourcing the file. – Carl Witthoft Apr 25 '12 at 11:11
-
1ive tried running a .bat file to do Rscript.exe E:\test.R. Getting back the error: Loading required package: gWidgets Loading required package: methods Error in function (classes, fdef, mtable) : unable to find an inherited method for function ".gwindow", for signature "NUL L" Calls: gwindow -> .gwindow ->
Execution halted – SilverSpoon Apr 27 '12 at 10:25
Have you tried using the RScript command? I don't know how it works on Windows, but in Linux I would do something like:
Rscript --vanilla -e 'source("abc.R")'

- 59,984
- 12
- 142
- 149

- 175
- 5
-
Probably you could create a shortcut which launches this command to create something that behaves like an executable – Paul Hiemstra Apr 25 '12 at 12:36
A basic version of this I've done in Windows 7 is;
- locate RScript.exe (e.g. C:\Users\USERNAME\Documents\R\R-3.3.2\bin\x64\RScript.exe)
- right click and select 'Pin to Taskbar'
The R icon should appear on the taskbar at the bottom of your screen
- find your script (e.g. C:\Users\USERNAME\Documents\MyScript.R) and drag this onto the R icon on the taskbar
- right-click the icon, 'MyScript' should be pinned there.
- click 'MyScript' to run the script.

- 382
- 3
- 12