Page One

Campus Computing News

Renew PRAS Accounts Now

Accessing GroupWise E-mail From Home

SPSS on CMS to be Dropped

The UNIX Question

Computer Virus!!!!

Going Somewhere?

RSS Matters

The Network Connection

List of the Month


Short Courses

IRC News

Staff Activities


RSS Matters

By Rich Herrington, Research and Statistical Support Services

Introduction to S-Plus 5.1 on UNIX (SOL)

The Research and Statistical Support group (RSS) has recently upgraded S-Plus on SOL from version 5.0 to version 5.1. In this column we will cover basic operations using S-Plus on SOL.   This is part one of a three part series on using Splus on SOL.

Connecting to S-Plus

In order to view graphical output on SOL a graphics device needs to be opened. You will need to have a x-window open or be using x-window emulator software. The College of Arts and Sciences (CAS) currently runs X-Win32 on the GAB, Terrell Hall, and Wooten Hall Servers. After starting X-Win32 on your local desktop, and before entering S-PLUS, the UNIX display needs to be routed to your IP address. To do this from the UNIX prompt, type:

                                                     xterm -ls -display &

where the ipaddress is the address assigned to your machine (i.e. it is a number like In WIN95/98 one can run the program "winipcfg" to get the ipaddress for your desktop PC. Before starting S-Plus, it would be a good idea to create a directory where all the data objects created in Splus can be stored. From the Unix prompt:

                                                     mkdir projects
                                                     cd projects

Now create a chapter file within this directory:

                                                     Splus5 CHAPTER

This creates the hidden file ".Data" in this directory. This file will hold all of the objects created during your S-Plus session. This includes all objects that are created: scripts, data, graphs, etc. You can have multiple directories with different ".Data" files. Once the chapter file is created, S-Plus is invoked at the Unix prompt:


You will see

Importing Data Files Into S-Plus

One method of getting data into S-Plus for data analysis and graphing is to import the data file. The S-Plus function that allows one to do this is the "importData" function.

Using the importData function, S-Plus can import from the following file types: ASCII, dBase, Microsoft Excel, FoxPro, Gauss, Informix, Gauss, Lotus, MatLab, Oracle, Quattro Pro, windows SPSS .sav and SPSS .por, windows SAS .sd2 and SAS .tpt, .xpt, STATA, Sybase, and Systat. You can read a windows SPSS data file into S-Plus using the following:


The assignment operator "<-" assigns the output of the importData function into an objects named "data". To display the contents of your working directory use the objects function:


To display the contents of a data object, type the name of the object and hit return:


You see the following:

Using S-Plus in Batch Mode

An alternative to interactive processing in S-Plus is the "batch" processing of S-Plus scripts. This is accomplished by creating a file that contains S-Plus commands which is then submitted for processing. S-Plus has a command allowing one to shell out to the UNIX operating system. Upon completion, control reverts back to the interactive S-Plus session. Thus, one can edit a file and submit it for processing without exiting the S-Plus session. For example, one can issue the following UNIX commands at the UNIX prompt or use the exclamation mark (!) to "shell" out to the UNIX environment whereby the command is executed. For example:

This invokes the "Pico" editor within the S-Plus session.

A file is created (example.ssc) which contains: 1st line - an assignment of 10 random numbers to the data object "x", 2nd line – the contents of "x" is listed. The file is saved by the key sequence "Ctrl-O", "Ctrl-X". Control reverts back to the S-Plus session. Once back in the S-Plus session. The file can then be submitted for batch processing. Once submitted the output can viewed within the S-Plus session using the UNIX command "more". For example:

Other Useful S-Plus Operations

The History Function

The "history" function allows one to pull up a listing of commands that have been utilized during the current S-Plus session. In an S-Plus session:

The history function displays the last 10 commands used during the S-Plus session. Other uses of the history function include:

The Scan Function

The scan() function can be used to read in numeric data into a matrix. Suppose the file "data2" contains data which is stored in 3 columns. The data would be read in as follows:

                                      > data2.mat<-matrix(scan("data2"),ncol=3, byrow=T)

To read in character data, the argument what=character() must be specified:

                                      >data2.mat<-matrix(scan("data2"),ncol=3, what=character(), byrow=T)

To quit from S-Plus use the following at the Splus prompt:

                                      >q( )

Next time

Next time we’ll cover S-Plus data structures, indexing operations for these data structures, and data subsetting.  In the final installment we will cover programming constructs (e.g. writing functions, loops, branching operations).