Department of Mathematics - University of Utah

HomeStudentsMath EdSchedulesSeminars/ConferencesGraduate StudyIGERT GrantVIGRE GrantResearchPeople

S-Plus and R FAQ

Last updates: Thu Oct 13 15:29:24 2005     Fri Oct 14 11:46:19 2005     Thu Oct 20 07:50:34 2005                Valid HTML 4.0!

Table of contents

  1. What is S-Plus?
  2. What is R?
  3. What books are available for S-Plus and R?
  4. Are S-Plus and R interchangeable?
  5. What documentation is available online for S-Plus and R?
  6. What versions of S-Plus and R do we have?
  7. How do I use high-precision arithmetic?
  8. How do I make a simple 2-D function plot?
  9. How do I make a 3-D surface plot?
  10. I'm working on machine X. Why does it not have S-Plus or R?
  11. I tried to start S-Plus, but it refused because of too many concurrent users. What can I do?
  12. Is there a local mailing list for questions about S-Plus and/or R?

Questions and answers

  1.   What is S-Plus?

    S-Plus is an extension of the statistics and data-analysis language, S, developed at AT&T Bell Laboratories about 1980. S-Plus appeared about 1992, and is now supported and developed by a commercial company, Insightful Corporation.

  2.   What is R?

    R is a reimplementation of S-Plus 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.

  3.   What books are available for S-Plus and R?

    About 65 of them: see the extensive s-plus bibliography.

  4.   Are S-Plus and R interchangeable?

    Yes, to a substantial degree. Several of the books in the subject use both, and some may discuss compatibility issues.

  5.   What documentation is available online for S-Plus and R?

    The S-Plus vendor has historically provided a large collection of S-Plus documents in PDF format. For a complete list, search the FILES files in the S-Plus 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 S-Plus and R: type a question mark followed by a topic or function name. Here is an example for S-Plus:

    % 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)
    ...
    
  6.   What versions of S-Plus 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/Splus-3.4   /usr/local/bin/Splus-6.0r2
    /usr/local/bin/Splus6
    
    % ls /usr/local/bin/R /usr/local/bin/R-*
    /usr/local/bin/R        /usr/local/bin/R-1.8.0     /usr/local/bin/R-2.1.0
    /usr/local/bin/R-1.5.1  /usr/local/bin/R-1.9.1     /usr/local/bin/R-2.1.1
    /usr/local/bin/R-1.6.2  /usr/local/bin/R-2.0.0
    
    % file /usr/local/bin/Splus
    /usr/local/bin/Splus: symbolic link to `Splus-6.0r2'
    
    % file /usr/local/bin/R
    /usr/local/bin/R: symbolic link to `R-2.1.1'
    

    Evidently, for both programs, the default version is the latest one.

  7.   How do I use high-precision arithmetic?

    You cannot. S-Plus and R carry out computations in IEEE 754 double-precision arithmetic, which provides almost 16 decimal digits of precision, and a number range from about 10-324 to 10308. 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
    
  8.   How do I make a simple 2-D function plot?

    S-Plus 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 S-Plus plot() function expects vector arguments, rather than symbolic expressions, so we first create a vector of uniformly-spaced values, and then plot a vector expression:

    % Splus
    ...
    x <- seq(-5, 5, 0.001)
    plot(x,sin(x)/x)
    

    This produces a pop-up 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 format-conversion tool:

    % xwd | convert - sin-x-over-x.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 > sin-x-over-x.png
    

    The resulting snapshot is quite large, so we first make a half-size version:

    % pngtopnm sin-x-over-x.png | pnmscale -reduce 2 | \
      pnmtopng > half-size-sin-x-over-x.png
    

    The half-size image looks like this:

    sin(x)/x in S-Plus

    The curve is thick because S-Plus 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 black-on-white instead of the default white-on-black (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 data-point number that is displayed. In this plot made with the type = "l" argument, we marked five such points:

    sin(x)/x in S-Plus with marked points

    Mouse button 1 marks points, and mouse button 2 terminates the point collection. The identify() function then returns a vector containing the selected data-point 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 pop-up window with a black-on-white 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 - sin-x-over-x-r.png
    
    % pngtopnm sin-x-over-x-r.png | pnmscale -reduce 2 | \
      pnmtopng > half-size-sin-x-over-x-r.png
    

    Here is what the half-size image looks like:

    sin(x)/x in R

    The identify() function works in R just as it does with S-Plus, so we don't show a sample plot with marked points.

  9.   How do I make a 3-D surface plot?

    As with 2-D plots, S-plus 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 8-bit 21300b 0.1u 0:01
    
    % convert -scale 400x349 hat.png half-size-hat.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 half-size plot looks like this:

    hat surface plot in S-Plus

    The same plotting commands in R produce a large pop-up window with a black-on-white image. As before, we create a window dump, and then scale it to half size:

    % xwd | convert - hat-r.png
    
    % pngtopnm hat-r.png | pnmscale -reduce 2 | \
      pnmtopng > half-size-hat-r.png
    

    The half-size plot looks like this:

    hat surface plot in R
  10.   I'm working on machine X. Why does it not have S-Plus or R?

    The S-Plus 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.

  11.   I tried to start S-Plus, 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 S-Plus licenses that we purchase has normally been sufficient.

  12.   Is there a local mailing list for questions about S-Plus and/or R?

    Yes: the Splus-users list is a (currently low-volume) 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.


Contents Dept Info Outreach College of Science What's New? Newsletter

Department of Mathematics
University of Utah
155 South 1400 East, JWB 233
Salt Lake City, Utah 84112-0090
Tel: 801 581 6851, Fax: 801 581 4148
Webmaster


Entire Web                     Only http://www.math.utah.edu/