Imagine you finish a dirty coding project and want to present to your boss who is not in a good mood (may not be occasionally), how are you going to start? Show him your hundreads of lines code, point to the lines, explain what the arguments and outputs are? No, it is not a smart way since you are supposed to introduce in a few short sentences. Generating a GUI is probably the quickest / easiest way of understanding what this code does. As the old saying goes: a picture is worth a thousand words, so in a same logic, **a GUI is worth n thousand words**.

However, generating GUI is by no means easy as I know the pain when creating the Matlab-GUI equity derivative calculator. It becomes even worse in R language, to be honest, I hate the graph plotting in R, terribly unflexible compared with in Matlab. Luckily I came across a good R GUI package named “**fgui**“, it does as its description: Rapidly create a GUI interface for a function you created by automatically creating widgets for arguments of the function.

Very nice indeed, after playing for half an hour, it is simple to use, especially when what you need is just a basic GUI demonstrating to others a rough idea. **One line code is enough**.

For a simple example, I create a European option pricer with Black Scholes formula,

EuropeanOption <- function (s, k, r, t, vol, CallOption) {

d1 <- (log(s/k)+(r+0.5*vol^2)*t)/(vol*sqrt(t))

d2 <- d1-vol*sqrt(t)

if (CallOption){

return (s*pnorm(d1)-k*exp(-r*t)*pnorm(d2))

} else {

return (k*exp(-r*t)*pnorm(-d2)-s*pnorm(-d1))

}

}

**then generating a GUI for this function is as simple as adding the following code**

res <- gui(EuropeanOption, argOption=list(CallOption=c("TRUE","FALSE")))

It returns a GUI looks like

where you are able to set inputs and get outputs. Nice. More advanced GUI is possible by adding more lines.

Interested readers shall download the package “**fgui**” at http://cran.r-project.org/web/packages/fgui/index.html

Tags – r , gui

**Read the full post at Simple Dummy R GUI Generator**.

*Related*

R-bloggers.com offers

**daily e-mail updates** about

R news and

tutorials on topics such as:

Data science,

Big Data, R jobs, visualization (

ggplot2,

Boxplots,

maps,

animation), programming (

RStudio,

Sweave,

LaTeX,

SQL,

Eclipse,

git,

hadoop,

Web Scraping) statistics (

regression,

PCA,

time series,

trading) and more...

If you got this far, why not

__subscribe for updates__ from the site? Choose your flavor:

e-mail,

twitter,

RSS, or

facebook...