Skip Navigation Links
Link to the last RSS article here: Using S-Plus Graphics in Excel; SPSS News - Ed.
Two User Interfaces to the R Statistical System: Rcgi and R Commander
By Dr. Rich Herrington, Research and Statistical Support Services Manager
This month we continue our exploration of window interfaces for R: R Commander - a simple drop down menu system; and Rcgi - a CGI based web interface to R. The following is an excerpt from the R website http://www.r-project.org:
Starting R in the SDI Mode
At this point it is assumed that you have installed R and have an R icon on your desktop (see the earlier Benchmarks Online article on downloading and installing R). Additionally, it is assumed that you have installed all of the supporting R Commander (Rcmdr) packages. To use the Rcmdr library, we will want to configure the R system window to have a "single document interface" mode (sdi). Right mouse click the R icon on your desktop and select properties. Add " --sdi " to the Target field after the Rgui.exe statement (see below). Click apply, then ok. Double click the R icon on your desktop to start the R system.
Loading the R Commander (Rcmdr) Package
To load the Rcmdr package, select Packages from the main menu bar in your main R console window and select Load Package. Select Rcmdr in the list. The Rcmdr window system will appear. Alternatively, you can manually load the Rcmdr package window from the main R console window by typing the "library" function, with the appropriate library, into the command prompt:
After selecting the Rcmdr package in the package selection window OR by loading the package manually, the following menu system will appear:
Some Fundamentals of the Rcmdr Window System
The Rcmdr window system can be resized by "grabbing" one of the corners of the window with the mouse (hover over the corner until you get a "double-headed" arrow" then press your left mouse button and drag the mouse). The upper window in the Rcmdr window is a script window where commands can be typed and then be submitted for processing. Once these commands have been typed in, the commands can be highlighted and the "Submit" button can be clicked. Alternatively, a right-mouse click on the highlighted script brings up a small menu where the script can be submitted for processing. Additionally, this menu can be used to find, select all, delete, copy and paste scripts that are in this window. Type the following script in the R script window; highlight the script; right-mouse click and "Submit" the script:
Submitting the R script above, generates 30 random normal numbers; places them in the object "x"; displays the object "x"; and then generates a frequency distribution of the numbers (histogram). The bottom window of the Rcmdr generates the output from your R commands. You can scroll through this output; copy, cut, and paste the output.
The following graph is also generated:
Additionally, using the drop down menu system in Rcmdr generates a script that appears in the script window. This convenience allows one the benefit of the drop down menu system, but also allows one to learn the R command language set as well. Additionally, commands that are generated by the window system can be saved to a script file for additional processing at a later time. For an example, lets generate a normal density function from the menu system (click "ok" to accept the default normal density parameters):
The following R script is generated in your script window; and the following is generated in your output window:
Notice that when your graphic image is generated that a history of plots are recorded. Click on "History" then "Recording". This should be checked as it is turned on when Rcmdr starts. You can use your "PAGE-UP" and "PAGE-DOWN" keys on the keyboard to flip back and forth through the various plots you have generated.
On the File menu option of your R graphics device you will notice that you can copy your image to your clipboard for insertion into other Windows programs (i.e. Microsoft Word). Also you can print the image out as well.
Running R scripts from your Rcmdr window in your Rcgi Web Interface and Vice-Versa
Now we want to Start a web browser at the following link:
Paste the R script from your R Commander window into the R Web interface:
The "Clear the R program" button will clear the text from the CGI window; The "Display Graphic (GIF)" button will display any images that have been generated. Running the R script produces the following text:
The R script that is processed is produced with the output below the R script. Viewing the graphics can be done by selecting the "Low Quality GIF" link at the bottom of the page OR the "Display Graphic (GIF) button at the top of the page. A graphic image(s) is generated within the browser:
Here we see that the script produces two images. These images can be printed from your browser. Additionally, a right-mouse click on these images will allow you to copy to your clipboard for pasting into other programs (i.e. Microsoft Word), or for saving to a file. To get back to the script window, press the Back Page on your web browser. You can continue to click the "Back Page" on your browser to get to the point from which the script window was generated (such as from within an HTML document). Note: you can right-mouse click on the "Display Graphic" button or the "Low Quality GIF" button and select the "Open in new window" option to open your graphics in a separate window from your script window.
Creating a Data-frame to Use within R Commander
In R we can create a number of different data objects. We can create scalars (single numbers), vectors (concatenated scalars - a single column or single row of numbers), or a matrix (concatenated vectors - several adjacent columns with multiple rows). Additionally, data can be of type "character" or "numeric". Vectors and matrices must be all of one type or the other. For example:
We could not mix character type "rich" and the numeric type "3" in a vector or matrix. We need a "data-frame" for this purpose. The data-frame is what is we will refer to a rectangular data matrix where columns are "variables" or measurements on each respondent and rows are the distinct respondents. For example, a column could consist of names, another column might consist of salaries. "Names" would be a character variable and "Salary" would be numeric variable in the same data matrix. R Commander will need all data that will appear in the drop down dialog boxes to be in the form of a data-frame so that variable information can be utilized in the menu system. To create a simulated data-frame we can use the following script:
Notice that the data.frame function generates default variable headings: X1, X2, X3, X4, X5. These would represent variables for respondents. The numbers 1,2,3,4,5 would represent different respondents. Next, notice that the "Data Set" icon is grayed out and there is "<No active dataset>". Click the "Data Set" icon button and a drop down menu list will appear. Select the "x.df" object:
Notice that there is now an "Active data set" called x.df.
This mechanism allows a user to switch between different data sets for viewing and editing. Simple editing and viewing in a spreadsheet fashion can be accomplished by selecting "Edit data set" or "View data set":
NOTE: Make sure that you close the editing or viewing window before opening or moving to other windows!! There is a limitation of the spreadsheet program in that it doesn't work well with other windows that are concurrently open. For this reason, edit, enter or view your spreadsheet and finish this task before moving on to other window movements or dialog boxes. Remember, in general you will need to have an active data set in order to use the menu systems - unless you are using the menu system to generate a graph or data (not ACTING on data).
Using other Menus in R Commander
In general, the variables of the data-frame will appear in the men dialog boxes. Selecting these variables with the mouse will make them active in the dialog box. For example to generate a histogram:
Producing the following density plot (a histogram with a relative frequency on the y-axis):
Fox, John (2003). The R Commander: A Basic-Statistics GUI for R. http://socserv.mcmaster.ca/jfox/Misc/Rcmdr/