Tuesday, February 4, 2014

Closer Look at R Statistics Scripts Called by WebFOCUS

Part IV
Let's take a closer look at the R scripts WebFOCUS generating within my sample text-mining application. 

In this simple application, WebFOCUS generates one of three graph options: box plot, histogram, or a plot, depending on the user selection.  

If you do not have R already installed, you can get a copy and full implementation instructions from the Comprehensive R Archive Network--a kind of App Store for all things R. The hyperlink for the CRAN is: http://www.r-project.org/.

For WebFOCUS to be able to communicate easily with R, we want to install R on either the same computer as the BI product or within its network of accessible drives. 

When you code in the R programming language, you are commonly using assignment statements and functions. 

For example, I want to assign the values in my WebFOCUS-generated text file into a named R data structure. Assignments are done with a symbol that puts together a left-caret with a dash. 

To pull out those values, I must first read the text file using a read function. Here is the basic command:

I want a data structure called "keywords" to hold my WebFOCUS file. The read command has a variety of options; I am using the "table" option to read a simple tabular structure. My table has a row identifying the column headers, so I inform read of that with a parameter called header. My table values are separated by commas, so I tell read about that using the sep parameter.

After that command, R has loaded my WebFOCUS data table into its memory. 

Before I actually create an output graph, I need to tell R where to store it. Had I been working with R interactively, the graph would just show on the screen. Here, I need to save the graph into a bitmap file and later in the process tell WebFOCUS to display it on the screen. 

I do that with the R png command (PNG stands for Portable Network Graphics). Here is a sample:

Along with the output file's full path, I also include some optional parameters to tell R how tall and wide to make the graph. 

Two R commands down and just one more to make the graph! 

If the user requested a box plot, I would use the R function called, naturally enough, boxplot. My sample statement looks like this: 

The first parameter for the boxplot function tells it to use a column called "Count" in my keywords data structure. Notice that R uses the US dollar sign to separate the structure and column name (in this example, keywords$Count). I am also passing in some optional variables to make the box plot lay down horizontally, give R to option to vary its width, and set the X axis label to say "Search Counts." 

The boxplot function gives me a bitmap graph such as this:

The other R graph functions look very similar. For example, my histogram command is simply: 

The difference here is a parameter called main where I am blanking out the main title. My output histogram might look like this:

Next is the simple graph of points plotted, whose R function looks like this: 

This gives me a graph such as the following:

Quick Clean-Up!
Before the R script ends and returns control to WebFOCUS, I am going to tell R to close the output graph file (otherwise, R controls the picture and I cannot open it). To do that, I call a function called "dev" (short for device) and turn off the graphics device connected to the output. It is simply this:

One Last Thing
The three types of graphs used above are all standard R features. Some, however, require that an add-on "package" to be installed and referenced. You can read about this on the CRAN website.   

For example, I might want WebFOCUS to create a file of keyword counts and then produce a word cloud. Within R, I would need to install the package containing that feature. Once installed, WebFOCUS needs to reference that package with the "library" function. 

Here is an example of WebFOCUS generating a word cloud R script: 

If you do have R scripts that use a package, you must have WebFOCUS start R using the R_LIBS parameter to identify where you installed the package. See an earlier article on how that works

Do You Have WebFOCUS and R? 
I hope you enjoyed this multi-part article on integrating WebFOCUS and the R statistical programming language. Do you have both products and, if so, do you use them together? Please leave a comment and let us know your experience. 

As always, if I can ever be of service, just let me know.


Anonymous said...

I like your post thanks for sharing.Keep it up.
Online Knowledge Academy

jake george said...

Tibco Spotfire Online Training
Tibco Spotfire Course contents
Tibco Spotfire is an analytics and business intelligence platform for analysis of data by predictive and complex statistics. Spot fire Training is a uniquely designed learning experience. Though the use of role-based, process-driven, hands-on learning approaches, we provide a variety of delivery vehicles to suit the board range of learning styles across our organization.
Course Contents

vasudha dharani said...

Webfocus Online Training
Web Focus Overview - Web Focus Architecture - Web Focus Environment - Report Type - Reporting Tools - Data Adapters & Meta data Creation - Master File - Access File - Report Painter - Introduction - Creating new Procedure - Report Tools - Temporary Field - Saving and Reusing Report Output - Displaying Report Output -
Styling Reports with the Report PainterEmployees to learn at their own pace and maintain control of learning “where, when and how” with boundless access 24/7by 21st Century Software Solutions. contact@21cssindia.com Call Us +91-7386622889

Anonymous said...

Loving your article(s). These enablers open a variety of powerful possibilities with open end complexity utilizing some fairly basic techniques of involved tools. Now lets do some predictive analytics! Thank you very much.

BlueRiver Analytics said...

Good post, informative and useful. Check this link for more info.

BlueRiver Analytics said...

Good post, informative and useful. Check this link for more info.

About Me

My Photo


With over 20 years of industry experience, Doug Lautzenheiser has provided business intelligence services for well-known organizations such as Procter & Gamble, JPMorgan Chase, Omnicare, Wendy’s International, the State of Indiana, and the State of Oklahoma. ComputerWorld recognized one of Doug's projects with honors for innovative use of technology.  Doug is a featured blogger on BI software at Smart Data Collective.

With his broad knowledge of technologies, business processes, and industry best practices, Doug provides client value by performing strategic advisory services; leading tactical BI application development projects; and enabling dramatic reductions in time, cost, and risks through his unique automated BI consolidation application.

Doug has hands-on experience with a variety of enterprise applications. He is degreed summa cum laude in Information Systems from the University of Cincinnati. An experienced trainer and mentor, Doug has provided educational services to organizations such as National Semiconductor, Ford Motor Company, Northwest Airlines, Principal Financial Group, and Target Stores. Doug is the owner of Kencura Systems.

Talk to Doug before manually performing a large BI initiative. Doug will show you how other smart companies saved time and money by following proven methodologies and automating BI processes instead of letting somebody "wing it" with a manual approach.


B2B software vendor leadership. BI implementations, standardization, and consolidation; data warehousing; WebFOCUS; iWay; BI vendors (Cognos, SAP Business Objects/Crystal Reports, Microstrategy, Actuate, Hyperion/Brio, SAS, Tableau Software); ERP; and full SDLC.