June 18, 2012 Mark Bulling

R: Creating a shortcut to run a gWidgets GUI

Tweet about this on TwitterShare on LinkedInShare on FacebookGoogle+Share on StumbleUponEmail to someone

I’ve been playing around with using gWidgets on Windows over the last few weeks as a way of creating front ends for various functions and set of functions that I’ve created, so that non R users can have the benefit of these without having to write a single line of code.

The likes of 4Dpiecharts offer some good introductions to various aspects of the tool, but one thing which I struggled to find was a way of creating an icon based way of launching the GUI – i.e. click on an icon on the desktop and have the GUI launch in an application like way.

At first, I assumed that this could be done via a batch file, but found that this didn’t seem to work when the script should display a GUI as the output.

I then came across this very handy stackoverflow post. Although, slightly enigmatic, the method outlined by Greg Snow worked and gave me what I wanted.

1. Create a new folder at a convenient place on your drive.

2. Create a shortcut to RGui.exe or Rterm.exe – these will likely be located in a folder like C:program filesRR-versionbini386. If the shortcut is to RGui then the full R GUI will be brought up, whilst R term will bring up the console version (I went with this option so that the focus would stay with the GUI).

3. Create an R function called .First which includes the various functions, data, etc. to launch your code.

 .First <- function() {  insert code here } 

4. Ensure that your R session is clean and only contains the functions (particularly .First) and data that you want to launch when you double click the shortcut. Save this workspace (which will be called “.rData”) to the folder that you created in Step 1.

5. Right click on the Shortcut that you created in Step 2 and change the Start In property (under the “Shortcut” tab) to the name of the folder that you created in Step 1.

Tagged:

Comments (8)

  1. VERY interesting.

    Any chance you will add a ZIP file with a folder structure that implements your steps?

    Cool post :)
    Tal

  2. excellent advice! I’ve been playing around with gWidgets myself and this was one of the items in my to-do list…

  3. Michael

    Man, for some reason when I follow this tutorial, when I double click the Rgui shortcut, it just brings me the regular console (empty). The function is saved to the workplace, but it isn’t loaded automatically when I double click it? Any advice?

    Thanks in advance!

    • Hi michael

      Just so i understand what you’re trying to do… Does the function create a GUI? Are you calling that function as well as creating it in the First function?

      If its easier for you to privately send the workspace, happy to have a look.

      Cheers

      Mark

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Machine Learning and Analytics based in London, UK