Running the UNIX Versions of Splus, R and SAS at McMaster

Department of Mathematics & Statistics
McMaster University


Index

1. Background Information

2. Running Splus on stats from the BSB Windows Lab

3. Running Splus on stats from your networked PC with Windows 95/98/2000/NT/XP

4. Running Splus on stats from your networked Macintosh

5. Running Splus on stats from a networked X-Terminal

6. Running Splus or SAS from Telnet



1. Background Information

1.1. Unix or Windows?

If you are running Splus 6 for Windows, there is a self-explanatory user interface. Saving your graphics and printing your results follow the conventions of any Windows application.

If you are running Splus 6 in the BSB Computer lab, you will have to learn how to set up a directory for your workspace each time you use Splus and you will have to save the directory by copying it to a floppy disk or by sending it by FTP to a server when you complete your Splus session, as any files you create on the local hard drive will be regarded as temporary and may be erased after you log off. Always use D:\Temp for your working files.

If you are running Splus 6 on your home computer you will have to learn how to organize your work into separate directories for different projects.

The instructions here are mainly concerned with running the UNIX version of Splus. All student UNIX accounts will be on stats. If you have an account on icarus, you also have an account on stats with the same userid and password.

Current versions of R are maintained on spruce and in the BSB Computer Lab. The instructions for running the UNIX version of Splus apply equally to R, except that directories do not need to be initialised as Chapters. UNIX, Windows and Macintosh versions of R can be downloaded at freely from http://cran.us.r-project.org/.

SAS 8.2 is available in the BSB Computer Lab and will be installed on one of the UNIX servers. Using SAS with MI/X is not recommended.

1.2. References and online resources

Because these books are a few years old, you should consult the online help to get updated function definitions.

The manuals supplied with Splus 5.1 are kept in the Mathematics & Statistics office in BSB-133. The Guide to Statistics can be signed out, the other two volumes may be consulted in the office.

The Department of Statistics at Carnegie Mellon University maintains the StatLib web site, including S Archive, an extensive library of software and extensions for the S (Splus) language, and an searchable archive of the S-news Internet discussion group.

The Department of Mathematics, Statistics and Computing Science at Dalhousie University in Halifax has prepared and excellent online Splus Tutorial.

1.3. Learning UNIX

If you are not yet familiar with the UNIX operating system used on data and stats, you should purchase a copy of UNIX: An introductory User's Guide ($4.25 from Computing and Information Systems in ABB-132), or use the online UNIX manual. You will need to know how to transfer data files to and from UNIX machines, how to manage your directories, and how to use the vi editor. In addition, knowledge of UNIX is useful because some Splus commands are similar to UNIX commands and UNIX commands can be invoked from within Splus.

1.4. Learning the UNIX vi editor

The vi editor is the default editor in Splus. It provides a very simple and efficient way to write and edit functions. The following commands are the only ones you will need to know.

Arrow Keys

Move the cursor

a

Append text to the right of the cursor

i

Insert text to the left of the cursor

<ESC>

Terminate insert or append sequences

rc

Replace current character with character c

x

Delete current character

dd

Delete current line

/string

Find next forward occurrence of string

?string

Find next backward occurrence of string

n

Find next forward occurrence of current search string

N

Find next backward occurrence of current search string

:

Switch to command mode.

Commands: wq (write and quit), q! (quit without writing), r filename (read in a file), etc.

<CR>

In insert or append: start a new line
In command mode: submit the command

Creating chapters and managing your working directories

Before you run Splus for the first time, you should create an S chapter. Make a directory called mysplus in your home or root directory, change directory into mysplus, then run CHAPTER to turn mysplus into an S chapter.

stats% mkdir mysplus
stats% cd mysplus
stats% splus CHAPTER
stats% ls -a
./      ../     .Data/

The ls -a command lists what has been installed in mysplus. You need -a ("show all") in the ls command, otherwise files and directories with names that start with "." won't be listed.

The directory .Data is the working directory for the S chapter mysplus. When you run Splus from within mysplus, .Data is your default working directory and any S objects you create in that session will, by default, be stored there.

The next time you log on, switch into directory mysplus before launching Splus.

stats% cd mysplus
stats% splus

If you want to keep work on different projects separate from each other, create an S chapter for each one and run Splus from within the chapter you want to work in.

You could make your home directory an S chapter and launch Splus from the home directory every time, but that isn't a good idea as objects from different projects will all be in the same working directory and you can easily lose track of them.

If you launch Splus from within a directory that is not an S chapter, Splus will create a new S chapter for you and the session will be run from within the new chapter. Objects from that session will be stored in a new .Data directory inside the chapter.

This means that, unless you have made every directory an S chapter, every time you run Splus you may create a new chapter. This is probably not what you want to happen. Your work will be spread over too many chapters. It is better to define a small number of chapters corresponding to specific projects.

If there are objects in a chapter Schapter2462 that you want to use in a later session, there are three ways to get at them. One is to run Splus from within Schapter2462.

stats% cd Schapter2462
stats% splus

A second way, if you have in the meantime created a chapter called mysplus, is to launch Splus from directory mysplus then attach the Schapter2462 chapter to the search path for this session. Do this with the Splus command attach("../Schapter2462"). Use detach("../Schapter2462") if later you want to remove it from the search path. Use search() to see what directories and objects are in the search path at any time. Consult an S reference manual or online help to learn more about search paths and the attach and detach functions.

The third way, not recommended, is to copy objects from the .Data directory of one chapter to the .Data directory of the other chapter, using the UNIX mv or cp commands.

If you have written your own library of Splus functions to use with several different projects, you can store the functions in their own S chapter, then attach that chapter when you run Splus from any other chapter.


2. Running Splus on stats from the BSB Windows Lab

2.1. Running an Splus session

Log onto Windows 95 with your BSB Windows Lab userid (usually the same as your mcmail or muss userid) and password. Your course folder (STATS 4M3 or STATS 4P3, e.g.) will have a shortcut to X-Win32 called "Stats", preconfigured to connect to stats.math.mcmaster.ca. Double-click on this icon, enter your stats userid and password when prompted, and an X-term window to stats will be opened.

If an X-term window doesn't appear within a reasonable time, go back to the X-Win32 taskbar button to "Show Messages". If the error message is "login incorrect", you made an error on your stats userid or password: start the session again and enter the correct userid and password when prompted.

Within the X-term window you are in an X-Windows environment. You may have to use the Delete key instead of Backspace to erase typing. X-Windows assumes you have a three-button mouse. You can select text with the left mouse button, then insert the selection at the current cursor position by clicking on the middle button: with a two-button mouse, hit the left and right mouse buttons together to emulate the middle button.

To launch Splus, make sure that the directory you are in is an S Chapter (see §1.5 if you are not sure how to do this) and enter splus at the prompt. A graphics window will open automatically when it is needed.

When using interactive graphics functions such as spin() and brush(), hold the mouse button down over a point until the point is selected. A quick click is sometimes not enough.

When you are done your Splus session, enter q() to quit Splus. Close the X-term window by clicking on its button on the taskbar, then selecting "Close" from the pop-up menu. Exit X-Win32 by clicking on its button on the taskbar, then selecting "Close" from the pop-up menu.

2.2. Sizing the Motif graphics window

You may find that the default graphics window is inconveniently large. You can resize the window but Splus graphics are optimized for the initial window size and won't look as nice in a resized window. You can over-ride the default window size by saving your preferred size (in this case, 500 pixels wide and 375 pixels high) in an object with an easy-to-remember name such as

> x11.myterm <- c("-xrm 'sgraphMotif*canvas.width:500'", 
                "-xrm 'sgraphMotif*canvas.height:375'")

and begin your Splus session by opening a new Motif graphics window with that object as an argument.

> motif(x11.myterm)

Since x11.myterm remains in your directory, you won't need to redefine it unless you want to change your preferences.

2.3. Printing

The menu of the Motif graphics window includes Printing Options and a Print command. If you have access to the PostScript printer in BSB-102, edit the Printing Command line to be just lpr. Selecting Print from the Motif menu will send a full-page PostScript version of the current graph to the printer in BSB-102 and leave the corresponding PostScript file in your stats directory. Undergraduate students will not have access to BSB-102.

PostScript files can be printed with GhostScript in the BSB Windows Lab. You will find a Shortcut to GSview in your course folder. In Splus, set the graphics device to be postscript("myplots.ps") and redraw any graphs you want printed. After you quit Splus, use ftp to transfer myplots.ps as an ASCII file to d:\temp on the PC, then either double-click on the file (if it has extension .ps) or drag and drop the file onto GSview. The PostScript graph will be displayed in GSview and you can use Print from the GSview File menu to send it to a printer in the BSB Windows Lab.

If the edge of your graph gets clipped when it is printed, you can make the graph smaller on the page. For example, to print in landscape mode on US Letter paper, you could try postscript("myplots.ps", width=9, height=7).

A more convenient way to print your graphs in the BSB Windows Lab is to bring the graphics window to the front and copy it to the Clipboard with Alt-PrintScreen or with the X-Win32 Copy command. Paste the image into a word processor such as Word or WordPad. Organize your graphs in the word processor, then print the word processor document. This is a good way to incorporate your graphics into a written report. The images will be bitmaps at screen resolution but that will be adequate for most purposes.

There are two ways to save and print session text. Text can be copied from the X-term window to a word processor, or you can use the sink() function to route Splus output to a file on stats, to be printed later.


3. Running Splus on stats from your networked PC with Windows 95/98/2000/NT/XP

3.1. Install and configure X-Win32

You can get a free evaluation copy of X-Win32 from StarNet Communications Corp. Sessions are limited to 30 minutes.

http://www.starnet.com/

Install X-Win32. Open X-Util32 and define a new session called "stats". Configure the session exactly as shown below. You can enter your stats userid and password here but this is not advisable as anyone who had access to your PC could get into your stats account without knowing your password. If you leave these fields blank, you will be prompted for userid and password when you connect to stats.

If you are connecting from off-campus, you will need to use X-Win32 5.4 (or higher) that supports SSH Secure Shell, and use ssh rather than rexec as the Connect Method.

If this configuration doesn't work, you could try $MYIP:0.0 instead of $DISPLAY in the Command line.

The following instructions should allow you to connect from a networked PC running Windows XP.

Go to the Windows XP Start Menu. From Start > Connect to > Show all connections, select the connection you will use and, under Properties > Advanced, disable the XP firewall. Disconnect if connected, then Connect.

If you need to know the Client IP address, you can get it from Details of that connection. If you have a dynamic IP address, it will be different every time you connect.

In XConfig, the Display tab may give you a choice of IP addresses; choose the Client IP address. Run the Wizard to set up your Xwin32 session. The Connect Method should be ssh. The Command to choose the display is

xterm -ls -display $MYIP:0

At the Security tab, add to the X-Host list the name or IP address of the host you wish to connect to.

You should now be able to launch the Xwin session from Xwin32. If it fails, try opening a SSH telnet session on the host, then enter the command

xterm –ls –display xxx.xxx.xxx.xxx:0

from the telnet session, where xxx.xxx.xxx.xxx is the current Client IP address.

When you have finished using X-Win32, it is advisable to disconnect from the network and re-enable the Windows XP firewall.

3.2. Running an Splus session

To initiate a session, open X-Win32, click on its button on the taskbar, select the session "stats" from the pop-up menu, and an X-term window to stats will be opened.

If an X-term window doesn't appear within a reasonable time, go back to the X-Win32 taskbar button to "Show Messages". If the error message is "login incorrect", you made an error on your stats userid or password. If you saved your userid and password when you created the session in X-Util32, you must go back to X-Util32 and edit the session "stats"; otherwise, start the session again and enter the correct userid and password when prompted. If the message is about an invalid IP number, it means that X-Win32 didn't get the correct IP number from Windows. This can usually be corrected by closing and restarting X-Win32.

Within the X-term window you are in an X-Windows environment. You may have to use the Delete key instead of Backspace to erase typing. X-Windows assumes you have a three-button mouse. You can select text with the left mouse button, then insert the selection at the current cursor position by clicking on the middle button: with a two-button mouse, hit the left and right mouse buttons together to emulate the middle button.

To launch Splus, make sure that the directory you are in is an S Chapter (see §1.5 if you are not sure how to do this) and enter splus at the prompt. A graphics window will open automatically when it is needed.

When using interactive graphics functions such as spin() and brush(), hold the mouse button down over a point until the point is selected. A quick click is sometimes not enough.

When you are done your Splus session, enter q() to quit Splus. Close the X-term window by clicking on its button on the taskbar, then selecting "Close" from the pop-up menu. Exit X-Win32 by clicking on its button on the taskbar, then selecting "Close" from the pop-up menu.

3.3. Sizing the Motif graphics window

You may find that the default graphics window is inconveniently large. You can resize the window but Splus graphics are optimized for the initial window size and won't look as nice in a resized window. You can over-ride the default window size by saving your preferred size (in this case, 500 pixels wide and 375 pixels high) in an object with an easy-to-remember name such as

> x11.myterm <- c("-xrm 'sgraphMotif*canvas.width:500'", 
                "-xrm 'sgraphMotif*canvas.height:375'")

and begin your Splus session by opening a new Motif graphics window with that object as an argument.

> motif(x11.myterm)

Since x11.myterm remains in your directory, you won't need to redefine it unless you want to change your preferences.

3.4. Printing

The menu of the Motif graphics window includes Printing Options and a Print command. If you have access to the PostScript printer in BSB-102, edit the Printing Command line to be just lpr. Selecting Print from the menu will send a full-page PostScript version of the current graph to the printer in BSB-102 and leave the corresponding PostScript file in your stats directory. Undergraduate students will not have access to BSB-102.

If you have a PostScript printer attached to your PC, you can set the Splus graphics device to be postscript("myplots.ps") and redraw any graphs you want printed. After you quit the Splus session, use ftp to transfer the file myplots.ps as an ASCII file from stats to your PC, then send it to the attached printer.

If you have non-PostScript printer, you may be able to print with GhostScript. A free copy is available from http://www.cs.wisc.edu/~ghost/. Transfer the file to your PC, then either double-click on the file (if it has extension .ps) or drag and drop the file onto GSview. The PostScript graph will be displayed in GSview and you can use Print from the GSview File menu to send it to your printer.

If the edge of your graph gets clipped when it is printed, you can make the graph smaller on the page. For example, to print in landscape mode on US Letter paper, you could try postscript("myplots.ps", width=9, height=7).

A more convenient way to print your graphs is to bring the graphics window to the front and copy it to the Clipboard with Alt-PrintScreen or with the X-Win32 Copy command. Paste the image into your word processor. Organize your graphs in the word processor, then print the word processor document. This is a good way to incorporate your graphics into a written report. The images will be bitmaps at screen resolution but that will be adequate for most purposes.

There are two ways to print session text. Text can be copied from the X-term window to a word processor, or you can use the sink() function to route Splus output to a file on stats, to be printed later.


4. Running Splus on stats from your networked Macintosh

4.1. Install and configure MI/X

You can get a copy of the freeware X-term emulator MI/X from MicroImages at

http://tnt.microimages.com/www/html/freestuf/mix/

Install MI/X. You will need some additional fonts to run Splus. Click here to get the fonts; you will find instructions for installing the fonts in the "MI/X fonts README" file that comes with them. More information can be found in the MI/X FAQ.

You also need to have Telnet installed on your Macintosh.

Open MI/X and set the Preferences as follows.

4.2. Running an Splus session

To initiate a session, open MI/X, open Telnet, and start a stats.math.mcmaster.ca session in Telnet. In the Telnet session, enter the xterm command

stats% xterm -display 130.113.192.141:0.0

with "130.113.192.141" replaced by the current IP number or the Internet name of your Macintosh. If the IP number or name is fixed, you could define an alias to this command in your .cshrc file. If the IP number is assigned dynamically (e.g. by the enhanced modem pool), use "Send IP number" from the Telnet "Network" menu to insert your current IP number each time you type the command.

You might also find that the command

stats% xterm -display $DISPLAY

works, in which case you won't need to supply the current or fixed IP number each time.

Switch to MI/X and use the mouse to place the new X-Window in the MI/X window. Within this window you are in an X-Windows environment. You may have to use the Delete key instead of Backspace to erase typing. X-Windows assumes you have a three-button mouse. You can select text with the left mouse button, then insert the selection at the current cursor position by clicking on the middle button: with a Macintosh one-button mouse, use Option-Mouse Button to emulate the middle button.

To launch Splus, make sure that the directory you are in is an S Chapter (see §1.5 if you are not sure how to do this) and enter splus at the prompt. A graphics window will open automatically when it is needed. This graphics window is more or less compatible with Splus but note that spin() will not work correctly and you may find other inconsistencies.

When you are done your Splus session, enter q() to quit Splus. Close the X-term window and quit MI/X by entering Control-C in the Telnet window. Log off the stats session as usual by typing logout in the Telnet window.

4.3. Sizing the Motif graphics window

You may find that the default graphics window is inconveniently large. You can resize the window but Splus graphics are optimized for the initial window size and won't look as nice in a resized window. You can over-ride the default window size by saving your preferred size (in this case, 500 pixels wide and 375 pixels high) in an object with an easy-to-remember name such as

> x11.myterm <- c("-xrm 'sgraphMotif*canvas.width:500'", 
                "-xrm 'sgraphMotif*canvas.height:375'")

and begin your Splus session by opening a new Motif graphics window with that object as an argument.

> motif(x11.myterm)

Since x11.myterm remains in your directory, you won't need to redefine it unless you want to change your preferences.

4.4. Printing

The menu of the Motif graphics window includes Printing Options and a Print command. If you have access to the PostScript printer in BSB-102, edit the Printing Command line to be just lpr. Selecting Print from the menu will send a full-page PostScript version of the current graph to the printer in BSB-102 and leave the corresponding PostScript file in your stats directory. Undergraduate students will not have access to BSB-102.

If you have a PostScript printer attached to your Macintosh, you can set the Splus graphics device to be postscript("myplots.ps") and redraw any graphs you want printed. After you quit the Splus session, use ftp to transfer the file myplots.ps from stats to your Macintosh, then use the Desktop Printer or a utility such as DropPS to send it to the attached printer.

If the edge of your graph gets clipped when it is printed, you can make the graph smaller on the page. For example, to print in landscape mode on US Letter paper, you could try postscript("myplots.ps", width=9, height=7).

The only way to save session text is to use the sink() function to route Splus output to a file on stats. You can't Copy/Paste between the MI/X windows and other Macintosh applications. You can use Command-Shift-3 to save an image of the entire screen, but you can't save the Motif graphics window on its own.


5. Running Splus on stats from a networked X-Term

5.1. Running an Splus session

After you log onto the X-Term, you may or may not have to give xhost and setenv DISPLAY commands to tell stats where to put the graphics window. This depends on how the X-Term is connected to stats. If you omit the commands and the Motif graphics window opens when it should, you didn't need them.

Suppose that you are on an X-Term connected to icarus. Before connecting to stats, tell icarus that you will be using it as an X-Windows host for stats.

icarus% xhost stats

If you don't know the identity of the X-Term, ask icarus to tell you.

icarus% echo $DISPLAY

Icarus will respond with the terminal identity, something like ncd-math12:0.

Connect to stats with

icarus% telnet stats

and log onto stats as usual. Tell stats the identity of the terminal you are using:

stats% setenv DISPLAY ncd-math12:0.0

using, of course, the appropriate identifier, which will not necessarily be ncd-math12:0.0.

To launch Splus, make sure that the directory you are in is an S Chapter (see §1.5 if you are not sure how to do this) and enter splus at the prompt. A graphics window will open automatically when it is needed. The default Motif graphics window is an appropriate size for most X-Terms.

When you are done your Splus session, enter q() to quit Splus. Log off the stats session as usual by typing logout in the telnet session window.

5.2. Printing

The menu of the Motif graphics window includes Printing Options and a Print command. If you have access to the PostScript printer in BSB-102, edit the Printing Command line to be just lpr. Selecting Print from the menu will send a full-page PostScript version of the current graph to the printer in BSB-102 and leave the corresponding PostScript file in your stats directory. Undergraduate students will not have access to BSB-102.

The only way to save session text is to use the sink() function to route Splus output to a file on stats.

 
6. Running Splus or SAS from Telnet

6.1. Running an Splus session

Log onto stats. To launch Splus, make sure that the directory you are in is an S Chapter (see §1.5 if you are not sure how to do this) and enter splus at the prompt. For graphics, issue the command printer(); graphs will appear in the current window. Since this isn't a graphics window, these will be rough "typewriter" graphics. The graph will appear after the next graphics call, after the next change in graphics device, or after you quit Splus, whichever comes first.

When you are done your Splus session, enter q() to quit Splus. Log off the stats session as usual by typing logout in the telnet session window.

6.2. The Tektronix 4014 graphics window

Splus 3.2 on data and Macintosh Telnet support Tektronix 4014 screen graphics; Splus 5.1 on stats does not. Configure Macintosh Telnet to enable Tektronix 4014 emulation; the settings are found from the menu under Edit/Preference/Sessions. In Splus, issue the command tek4014(). Each graph will open a new window. You can Copy or Print a graphics window when it is the front window. After the graph is finished and before entering more commands, return the Telnet session window to the front by clicking on it; otherwise the next output will be written to the graphics window.

6.3. Printing

Set the graphics device to be postscript("myplots.ps") and redraw any graphs you want printed. After you quit Splus, the command lpr myplots.ps will send the graphs to the printer in BSB-102. Undergraduate students will not have access to BSB-102.

There are two ways to save and print session text. Text can be copied from the Telnet window to a word processor on your desktop computer, or you can use the sink() function to route Splus output to a file on stats, to be printed later.

6.4 Running a SAS session

In UNIX, move to the directory you wish to be your working directory. Use the vi or pico editors to write your SAS script in a file called xxxx.sas. Submit the script with the command sas xxxx. The log of your session will be found in xxxx.log; use cat xxxx.log, pico xxxx.log or vi xxxx.log to inspect the file. If your session ran successfully, the output will be in xxxx.lst and again you can use cat xxxx.lst, pico xxxx.lst or vi xxxx.lst to inspect the file.


Notes prepared by Peter Macdonald
Send your comments, corrections and suggestions to
pdmmac@mcmaster.ca
Dr Macdonald's Courses
Department of Mathematics & Statistics
Last updated 2002-10-21