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

I am a project-based software consultant, specializing in automating transitions from legacy reporting applications into modern BI/Analytics to leverage Social, Cloud, Mobile, Big Data, Visualizations, and Predictive Analytics using Information Builders' WebFOCUS. Based on scores of successful engagements, I have assembled proven Best Practice methodologies, software tools, and templates.

I have been blessed to work with innovators from firms such as: Ford, FedEx, Procter & Gamble, Nationwide, The Wendy's Company, The Kroger Co., JPMorgan Chase, MasterCard, Bank of America Merrill Lynch, Siemens, American Express, and others.

I was educated at Valparaiso University and the University of Cincinnati, where I graduated summa cum laude. In 1990, I joined Information Builders and for over a dozen years served in regional pre- and post-sales technical leadership roles. Also, for several years I led the US technical services teams within Cincom Systems' ERP software product group and the Midwest custom software services arm of Xerox.

Since 2007, I have provided enterprise BI services such as: strategic advice; architecture, design, and software application development of intelligence systems (interactive dashboards and mobile); data warehousing; and automated modernization of legacy reporting. My experience with BI products include WebFOCUS (vendor certified expert), R, SAP Business Objects (WebI, Crystal Reports), Tableau, and others.