Consistently Infrequent

November 16, 2011

fgui: Automatically Creating Widgets for Arguments of a Function – A Quick Example

Filed under: R — Tags: , , , , , , — Tony Breyal @ 11:14 am

Here’s something I came across by accident, an R package called fgui which has the ability to automatically create a widget just by passing it a function with parameters, e.g.:

# load packages
require(fgui)

# add two number together and return the value
add <- function(x1,  x2) {
  return(x1 + x2)
}

# execute function through GUI
y <- guiv(add)
# [1] 5

The GUI produced from the code above looks like this:

I love how easy that was to do, very cool, and useful too! The package is a wrapper to the base R package tcltk.

About these ads

4 Comments »

  1. This is Windows only I believe. Installing package ‘tcltk’ in Linux is not a task one would want to take on; this may not be true for all distributions but is my experience so far. Package “gWidgets” comes to the rescue!

    Comment by Rainer — November 16, 2011 @ 5:27 pm

    • Seems to work fine under Ubuntu 11.10 with R 2.14.0 and Windows 7. The objective of the code above was to illustrate a cool feature of fgui which I have to say is rather impressive (to me, at least). Package gWidgets is something I want to look at in the future but there’s so many different gui packages it difficult to know where to start – I wish there was some kind of comprehensive guide contrasting the different packages.

      Comment by Tony Breyal — November 16, 2011 @ 11:07 pm

  2. @Rainer
    tcltk is pre-installed in most linux distros and is very simple to install on others.
    I have ubuntu and RStudio and got the above example working in one minute.

    Regards
    Antonio (flaap)

    Comment by Antonio — November 16, 2011 @ 6:06 pm

  3. See also the ggenericwidget function from gWidgets.

    Comment by richierocks (@richierocks) — November 22, 2011 @ 6:49 pm


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

The Shocking Blue Green Theme. Create a free website or blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.

Join 76 other followers

%d bloggers like this: