
Last updates: Thu Oct 13 15:29:24 2005 Fri Oct 14 11:46:19 2005 Thu Oct 20 07:50:34 2005
SPlus is an extension of the statistics and dataanalysis language, S, developed at AT&T Bell Laboratories about 1980. SPlus appeared about 1992, and is now supported and developed by a commercial company, Insightful Corporation.
R is a reimplementation of SPlus developed by a team of researchers and freely distributed under the GNU General Public License and available on the Web as The R Project for Statistical Computing, including the notable, and large, Comprehensive R Archive Network with hundreds of additional packages.
What books are available for SPlus and R?
About 65 of them: see the extensive splus bibliography.
Are SPlus and R interchangeable?
Yes, to a substantial degree. Several of the books in the subject use both, and some may discuss compatibility issues.
What documentation is available online for SPlus and R?
The SPlus vendor has historically provided a large collection of SPlus documents in PDF format. For a complete list, search the FILES files in the SPlus installation tree:
% fgrep .pdf /usr/local/sys/splus/splus*/FILES /usr/local/sys/splus/splus60_r2/doc/getstart.pdf /usr/local/sys/splus/splus60_r2/doc/instman.pdf /usr/local/sys/splus/splus60_r2/doc/pguide.pdf ...
The R Project team has several online manuals in HTML and PDF.
There is also online help inside SPlus and R: type a question mark followed by a topic or function name. Here is an example for SPlus:
% Splus ... > ? sqrt Exponential Functions DESCRIPTION: Returns the exponential, logarithm, or square root of the input. USAGE: exp(x) log(x) logb(x, base=exp(1)) log10(x) sqrt(x) ...
What versions of SPlus and R do we have?
We maintain several historical versions of these systems. You can see what they are like this:
% which Splus R /usr/local/bin/Splus /usr/local/bin/R % ls /usr/local/bin/Splus* /usr/local/bin/Splus /usr/local/bin/Splus3.4 /usr/local/bin/Splus6.0r2 /usr/local/bin/Splus6 % ls /usr/local/bin/R /usr/local/bin/R* /usr/local/bin/R /usr/local/bin/R1.8.0 /usr/local/bin/R2.1.0 /usr/local/bin/R1.5.1 /usr/local/bin/R1.9.1 /usr/local/bin/R2.1.1 /usr/local/bin/R1.6.2 /usr/local/bin/R2.0.0 % file /usr/local/bin/Splus /usr/local/bin/Splus: symbolic link to `Splus6.0r2' % file /usr/local/bin/R /usr/local/bin/R: symbolic link to `R2.1.1'
Evidently, for both programs, the default version is the latest one.
How do I use highprecision arithmetic?
You cannot. SPlus and R carry out computations in IEEE 754 doubleprecision arithmetic, which provides almost 16 decimal digits of precision, and a number range from about 10^{324} to 10^{308}. Neither supports computation at higher precision.
You can, however, use them as simple symbolic calculators:
% R ... > sqrt(pi/2) * sin(3.5*pi) * exp(3.5) [1] 0.03784681 > print(sqrt(pi/2) * sin(3.5*pi) * exp(3.5), digits = 16) [1] 0.03784680755312850 > options(digits = 16) > sqrt(pi/2) * sin(3.5*pi) * exp(3.5) [1] 0.03784680755312850
How do I make a simple 2D function plot?
SPlus is particularly rich in graphical display of data, a task that was a major design goal of the language. However, in this FAQ, we only demonstrate simple examples.
The SPlus plot() function expects vector arguments, rather than symbolic expressions, so we first create a vector of uniformlyspaced values, and then plot a vector expression:
% Splus ... x < seq(5, 5, 0.001) plot(x,sin(x)/x)
This produces a popup window from which we can make a screen dump by running the X Window Dump command in a separate terminal window, piping its output into the ImageMagick formatconversion tool:
% xwd  convert  sinxoverx.png
xwd waits for you to move the pointer into the desired window and click the mouse to make the snapshot.
Another way to make the screen dump is to convert it to Portable Network Map (PNM) format, and then to PNG format:
% xwd  xwdtopnm  pnmtopng > sinxoverx.png
The resulting snapshot is quite large, so we first make a halfsize version:
% pngtopnm sinxoverx.png  pnmscale reduce 2  \ pnmtopng > halfsizesinxoverx.png
The halfsize image looks like this:
The curve is thick because SPlus and R by default plot a crosshair at each point. With an extra argument in the plot() call, we can connect the points with line segments instead:
> plot(x, sin(xx)/xx, type="l")
The plot is similar to the one shown above, except that the curve is thin.
The Options > Color Scheme menu path allows you to select blackonwhite instead of the default whiteonblack (chosen because it makes color easier to see).
The Options > Printing menu path menu lets you choose landscape or portrait orientation, output to either PostScript or HP LaserJet formats, and the command to use for `printing', which might be something like cat > myplot.eps to instead save in a file. The PostScript plot is black on white, independent of the original color scheme.
Although you cannot interact directly with the plot to change its appearance, you can mark points on the plot with the help of the identify() function:
> identify(x, sin(x)/x)
Mouse clicks in the plot window then report a datapoint number that is displayed. In this plot made with the type = "l" argument, we marked five such points:
Mouse button 1 marks points, and mouse button 2 terminates the point collection. The identify() function then returns a vector containing the selected datapoint numbers:
> identify(x, sin(x)/x) [1] 172 315 639 941 1100
A typical use of such a result is the visual identification of outliers in experimental data.
The same plotting commands in R produce a large popup window with a blackonwhite image. Unfortunately, the ImageMagick convert utility loses the axis labeling when it scales the image to half size, so we use the NetPBM tools instead:
% xwd  convert  sinxoverxr.png % pngtopnm sinxoverxr.png  pnmscale reduce 2  \ pnmtopng > halfsizesinxoverxr.png
Here is what the halfsize image looks like:
The identify() function works in R just as it does with SPlus, so we don't show a sample plot with marked points.
How do I make a 3D surface plot?
As with 2D plots, Splus creates surfaces by plotting points, not functions, so you have to create suitable coordinate arrays first:
% Splus ... > x < seq(12, 12, 1/8) > y < x > z < matrix(0,length(x),length(y)) > for (i in 1:length(x)) + for (j in 1:length(y)) + z[i,j] < sin(sqrt(x[i]^2 + y[j]^2)) / sqrt(x[i]^2 + y[j]^2) > persp(x,y,z)
We can make a snapshot like this:
% xwd  convert  hat.png
Next, we make a companion file of half the original size like this:
% identify hat.png hat.png PNG 800x697 PseudoClass 5c 8bit 21300b 0.1u 0:01 % convert scale 400x349 hat.png halfsizehat.png
When scaling an image that has a dimension that is an odd number of pixels, round the scaled value upward: thus, 697 / 2 > 349.
The halfsize plot looks like this:
The same plotting commands in R produce a large popup window with a blackonwhite image. As before, we create a window dump, and then scale it to half size:
% xwd  convert  hatr.png % pngtopnm hatr.png  pnmscale reduce 2  \ pnmtopng > halfsizehatr.png
The halfsize plot looks like this:
I'm working on machine X. Why does it not have SPlus or R?
The SPlus vendor supports only a few of the architectures that we have, and because each platform costs additional license fees, we provide it only on Sun Solaris SPARC systems.
While R is freely available, it is a large and complex system (more than 265,000 lines of C and 146,000 lines of Fortran), and there are frequently build problems on several platforms. We have at least one version of each of our systems (although the latest version does not build on all of them), except for Apple Mac OS X, where no build attempt has yet succeeded.
I tried to start SPlus, but it refused because of too many concurrent users. What can I do?
Wait a half hour or so, and then retry. If the problem persists, ask systems staff for help. The number of SPlus licenses that we purchase has normally been sufficient.
Is there a local mailing list for questions about SPlus and/or R?
Yes: the Splususers list is a (currently lowvolume) list where such questions may be posted, and there is an archive of past postings available from a link near the top of its Web page.