Rev 6717 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
<html lang="en"><head><title>R FAQ</title><meta http-equiv="Content-Type" content="text/html"><meta name=description content="R FAQ"><meta name=generator content="makeinfo 4.0"><link href="http://texinfo.org/" rel=generator-home></head><body><html><head><TITLE>R FAQ</TITLE></head><body><h1>R FAQ</h1><h2>Frequently Asked Questions on R</h2><h2>Version 0.90-2, 1999/11/25</h2><address>Kurt Hornik</address><p><p><hr><p><h1>Table of Contents</h1><ul><li><a href="#Introduction">1 Introduction</a><ul><li><a href="#Legalese">1.1 Legalese</a><li><a href="#Obtaining%20this%20document">1.2 Obtaining this document</a><li><a href="#Citing%20this%20document">1.3 Citing this document</a><li><a href="#Notation">1.4 Notation</a><li><a href="#Feedback">1.5 Feedback</a></ul><li><a href="#R%20Basics">2 R Basics</a><ul><li><a href="#What%20is%20R%3f">2.1 What is R?</a><li><a href="#What%20machines%20does%20R%20run%20on%3f">2.2 What machines does R run on?</a><li><a href="#What%20is%20the%20current%20version%20of%20R%3f">2.3 What is the current version of R?</a><li><a href="#How%20can%20R%20be%20obtained%3f">2.4 How can R be obtained?</a><li><a href="#How%20can%20R%20be%20installed%3f">2.5 How can R be installed?</a><ul><li><a href="#How%20can%20R%20be%20installed%20(Unix)">2.5.1 How can R be installed (Unix)</a><li><a href="#How%20can%20R%20be%20installed%20(Windows)">2.5.2 How can R be installed (Windows)</a><li><a href="#How%20can%20R%20be%20installed%20(Macintosh)">2.5.3 How can R be installed (Macintosh)</a></ul><li><a href="#Are%20there%20Unix%20binaries%20for%20R%3f">2.6 Are there Unix binaries for R?</a><li><a href="#What%20documentation%20exists%20for%20R%3f">2.7 What documentation exists for R?</a><li><a href="#Citing%20R">2.8 Citing R</a><li><a href="#What%20mailing%20lists%20exist%20for%20R%3f">2.9 What mailing lists exist for R?</a><li><a href="#What%20is%20CRAN%3f">2.10 What is CRAN?</a></ul><li><a href="#R%20and%20S">3 R and S</a><ul><li><a href="#What%20is%20S%3f">3.1 What is S?</a><li><a href="#What%20is%20S-PLUS%3f">3.2 What is S-PLUS?</a><li><a href="#What%20are%20the%20differences%20between%20R%20and%20S%3f">3.3 What are the differences between R and S?</a><ul><li><a href="#Lexical%20scoping">3.3.1 Lexical scoping</a><li><a href="#Models">3.3.2 Models</a><li><a href="#Others">3.3.3 Others</a></ul><li><a href="#Is%20there%20anything%20R%20can%20do%20that%20S-PLUS%20cannot%3f">3.4 Is there anything R can do that S-PLUS cannot?</a></ul><li><a href="#R%20Web%20Interfaces">4 R Web Interfaces</a><li><a href="#R%20Add-On%20Packages">5 R Add-On Packages</a><ul><li><a href="#Which%20add-on%20packages%20exist%20for%20R%3f">5.1 Which add-on packages exist for R?</a><li><a href="#How%20can%20add-on%20packages%20be%20installed%3f">5.2 How can add-on packages be installed?</a><li><a href="#How%20can%20add-on%20packages%20be%20used%3f">5.3 How can add-on packages be used?</a><li><a href="#How%20can%20add-on%20packages%20be%20removed%3f">5.4 How can add-on packages be removed?</a><li><a href="#How%20can%20I%20create%20an%20R%20package%3f">5.5 How can I create an R package?</a><li><a href="#How%20can%20I%20contribute%20to%20R%3f">5.6 How can I contribute to R?</a></ul><li><a href="#R%20and%20Emacs">6 R and Emacs</a><ul><li><a href="#Is%20there%20Emacs%20support%20for%20R%3f">6.1 Is there Emacs support for R?</a><li><a href="#Should%20I%20run%20R%20from%20within%20Emacs%3f">6.2 Should I run R from within Emacs?</a></ul><li><a href="#R%20Miscellania">7 R Miscellania</a><ul><li><a href="#Why%20does%20R%20run%20out%20of%20memory%3f">7.1 Why does R run out of memory?</a><li><a href="#Why%20does%20sourcing%20a%20correct%20file%20fail%3f">7.2 Why does sourcing a correct file fail?</a><li><a href="#How%20can%20I%20set%20components%20of%20a%20list%20to%20NULL%3f">7.3 How can I set components of a list to NULL?</a><li><a href="#How%20can%20I%20save%20my%20workspace%3f">7.4 How can I save my workspace?</a><li><a href="#How%20can%20I%20clean%20up%20my%20workspace%3f">7.5 How can I clean up my workspace?</a><li><a href="#How%20can%20I%20get%20eval()%20and%20D()%20to%20work%3f">7.6 How can I get eval() and D() to work?</a><li><a href="#Why%20do%20my%20matrices%20lose%20dimensions%3f">7.7 Why do my matrices lose dimensions?</a><li><a href="#How%20does%20autoloading%20work%3f">7.8 How does autoloading work?</a><li><a href="#How%20should%20I%20set%20options%3f">7.9 How should I set options?</a><li><a href="#How%20do%20file%20names%20work%20in%20Windows%3f">7.10 How do file names work in Windows?</a><li><a href="#Why%20does%20plotting%20give%20a%20color%20allocation%20error%3f">7.11 Why does plotting give a color allocation error?</a><li><a href="#Is%20R%20Y2K-compliant%3f">7.12 Is R Y2K-compliant?</a></ul><li><a href="#R%20Programming">8 R Programming</a><ul><li><a href="#How%20should%20I%20write%20summary%20methods%3f">8.1 How should I write summary methods?</a><li><a href="#How%20can%20I%20debug%20dynamically%20loaded%20code%3f">8.2 How can I debug dynamically loaded code?</a><li><a href="#How%20can%20I%20inspect%20R%20objects%20when%20debugging%3f">8.3 How can I inspect R objects when debugging?</a></ul><li><a href="#R%20Bugs">9 R Bugs</a><ul><li><a href="#What%20is%20a%20bug%3f">9.1 What is a bug?</a><li><a href="#How%20to%20report%20a%20bug">9.2 How to report a bug</a></ul><li><a href="#Acknowledgments">10 Acknowledgments</a></ul><p><hr>Node:<a name="Top">Top</a>,Next:<a rel=next href="#Introduction">Introduction</a>,Previous:<a rel=previous href="#(dir)">(dir)</a>,Up:<a rel=up href="#(dir)">(dir)</a><br><ul><li><a href="#Introduction">Introduction</a>:<li><a href="#R%20Basics">R Basics</a>:<li><a href="#R%20and%20S">R and S</a>:<li><a href="#R%20Web%20Interfaces">R Web Interfaces</a>:<li><a href="#R%20Add-On%20Packages">R Add-On Packages</a>:<li><a href="#R%20and%20Emacs">R and Emacs</a>:<li><a href="#R%20Miscellania">R Miscellania</a>:<li><a href="#R%20Programming">R Programming</a>:<li><a href="#R%20Bugs">R Bugs</a>:<li><a href="#Acknowledgments">Acknowledgments</a>:</ul><p><hr>Node:<a name="Introduction">Introduction</a>,Next:<a rel=next href="#R%20Basics">R Basics</a>,Previous:<a rel=previous href="#Top">Top</a>,Up:<a rel=up href="#Top">Top</a><br><h1>1 Introduction</h1><p>This document contains answers to some of the most frequently askedquestions about R.<ul><li><a href="#Legalese">Legalese</a>:<li><a href="#Obtaining%20this%20document">Obtaining this document</a>:<li><a href="#Citing%20this%20document">Citing this document</a>:<li><a href="#Notation">Notation</a>:<li><a href="#Feedback">Feedback</a>:</ul><p><hr>Node:<a name="Legalese">Legalese</a>,Next:<a rel=next href="#Obtaining%20this%20document">Obtaining this document</a>,Previous:<a rel=previous href="#Introduction">Introduction</a>,Up:<a rel=up href="#Introduction">Introduction</a><br><h2>1.1 Legalese</h2><p>This document is free software; you can redistribute it and/or modify itunder the terms of the GNU General Public License as published by theFree Software Foundation; either version 2, or (at your option) anylater version.<p>This document is distributed in the hope that it will be useful, butWITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNUGeneral Public License for more details.<p>A copy of the GNU General Public License is available via WWW at<pre><a href="http://www.gnu.org/copyleft/gpl.html">http://www.gnu.org/copyleft/gpl.html</a>.</pre><p>You can also obtain it by writing to the Free Software Foundation, Inc.,59 Temple Place -- Suite 330, Boston, MA 02111-1307, USA.<p><hr>Node:<a name="Obtaining%20this%20document">Obtaining this document</a>,Next:<a rel=next href="#Citing%20this%20document">Citing this document</a>,Previous:<a rel=previous href="#Legalese">Legalese</a>,Up:<a rel=up href="#Introduction">Introduction</a><br><h2>1.2 Obtaining this document</h2><p>The latest version of this document is always available from<pre><a href="http://www.ci.tuwien.ac.at/~hornik/R/">http://www.ci.tuwien.ac.at/~hornik/R/</a></pre><p>From there, you can obtain versions converted to<a href="http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.txt">plain ASCII text</a>, <a href="http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.dvi.gz">DVI</a>,<a href="http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.info.gz">GNU info</a>,<a href="http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html">HTML</a>,<a href="http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.pdf">PDF</a>,<a href="http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.ps.gz">PostScript</a> aswell as the <a href="http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.texi">Texinfo source</a> used for creating all these formats using the<a href="http://texinfo.org/">GNU Texinfo system</a>.<p>You can also obtain the R FAQ from the <code>doc/FAQ</code> subdirectory of aCRAN site (<a href="#What%20is%20CRAN%3f">What is CRAN?</a>).<p><hr>Node:<a name="Citing%20this%20document">Citing this document</a>,Next:<a rel=next href="#Notation">Notation</a>,Previous:<a rel=previous href="#Obtaining%20this%20document">Obtaining this document</a>,Up:<a rel=up href="#Introduction">Introduction</a><br><h2>1.3 Citing this document</h2><p>In publications, please refer to this FAQ as Hornik (1999), "The RFAQ" and give the above, <em>official</em> URL.<p><hr>Node:<a name="Notation">Notation</a>,Next:<a rel=next href="#Feedback">Feedback</a>,Previous:<a rel=previous href="#Citing%20this%20document">Citing this document</a>,Up:<a rel=up href="#Introduction">Introduction</a><br><h2>1.4 Notation</h2><p>Everything should be pretty standard. <code>R></code> is used for the Rprompt, and a <code>$</code> for the shell prompt (where applicable).<p><hr>Node:<a name="Feedback">Feedback</a>,Previous:<a rel=previous href="#Notation">Notation</a>,Up:<a rel=up href="#Introduction">Introduction</a><br><h2>1.5 Feedback</h2><p>Feedback is of course most welcome.<p>In particular, note that I do not have access to Windows or Mac systems.Features specific to the Windows port of R are described in the<a href="http://www.stats.ox.ac.uk/pub/R/rw-FAQ.html">"Frequently Asked Questions for R for Windows"</a>. If you have information on Windows orMac systems that you think should be added to this document, please letme know.<p><hr>Node:<a name="R%20Basics">R Basics</a>,Next:<a rel=next href="#R%20and%20S">R and S</a>,Previous:<a rel=previous href="#Introduction">Introduction</a>,Up:<a rel=up href="#Top">Top</a><br><h1>2 R Basics</h1><ul><li><a href="#What%20is%20R%3f">What is R?</a>:<li><a href="#What%20machines%20does%20R%20run%20on%3f">What machines does R run on?</a>:<li><a href="#What%20is%20the%20current%20version%20of%20R%3f">What is the current version of R?</a>:<li><a href="#How%20can%20R%20be%20obtained%3f">How can R be obtained?</a>:<li><a href="#How%20can%20R%20be%20installed%3f">How can R be installed?</a>:<li><a href="#Are%20there%20Unix%20binaries%20for%20R%3f">Are there Unix binaries for R?</a>:<li><a href="#What%20documentation%20exists%20for%20R%3f">What documentation exists for R?</a>:<li><a href="#Citing%20R">Citing R</a>:<li><a href="#What%20mailing%20lists%20exist%20for%20R%3f">What mailing lists exist for R?</a>:<li><a href="#What%20is%20CRAN%3f">What is CRAN?</a>:</ul><p><hr>Node:<a name="What%20is%20R%3f">What is R?</a>,Next:<a rel=next href="#What%20machines%20does%20R%20run%20on%3f">What machines does R run on?</a>,Previous:<a rel=previous href="#R%20Basics">R Basics</a>,Up:<a rel=up href="#R%20Basics">R Basics</a><br><h2>2.1 What is R?</h2><p>R is a system for statistical computation and graphics. It consists ofa language plus a run-time environment with graphics, a debugger, accessto certain system functions, and the ability to run programs stored inscript files.<p>The design of R has been heavily influenced by two existing languages:Becker, Chambers & Wilks' S (see <a href="#What%20is%20S%3f">What is S?</a>) and Sussman's<a href="http://www.cs.indiana.edu/scheme-repository/home.html">Scheme</a>.Whereas the resulting language is very similar in appearance to S, theunderlying implementation and semantics are derived from Scheme.See <a href="#What%20are%20the%20differences%20between%20R%20and%20S%3f">What are the differences between R and S?</a>, for a discussion ofthe differences between R and S.<p>R was initially written by <a href="mailto:Ross.Ihaka@r-project.org">Ross Ihaka</a>and <a href="mailto:Robert.Gentleman@r-project.org">Robert Gentleman</a>, who areSenior Lecturers at the Department of Statistics of the University ofAuckland in Auckland, New Zealand. In addition, a large group ofindividuals has contributed to R by sending code and bug reports.<p>Since mid-1997 there has been a core group (the "R Core Team") who canmodify the R source code CVS archive. The group currently consists ofDoug Bates, Peter Dalgaard, Robert Gentleman, Kurt Hornik, Ross Ihaka,Friedrich Leisch, Thomas Lumley, Martin Maechler, Guido Masarotto, PaulMurrell, Brian Ripley, Duncan Temple Lang, and Luke Tierney.<p>R has a home page at <a href="http://stat.auckland.ac.nz/r/r.html">http://stat.auckland.ac.nz/r/r.html</a>. It isfree software distributed under a GNU-style copyleft, and an officialpart of the GNU project ("GNU S").<p><hr>Node:<a name="What%20machines%20does%20R%20run%20on%3f">What machines does R run on?</a>,Next:<a rel=next href="#What%20is%20the%20current%20version%20of%20R%3f">What is the current version of R?</a>,Previous:<a rel=previous href="#What%20is%20R%3f">What is R?</a>,Up:<a rel=up href="#R%20Basics">R Basics</a><br><h2>2.2 What machines does R run on?</h2><p>R is being developed for the Unix, Windows and Mac families of operatingsystems.<p>The current version of R will configure and build under a number ofcommon Unix platforms including i386-freebsd, i386-linux, ppc-linux,mips-sgi-irix, alpha-linux, alpha-dec-osf4, rs6000-ibm-aix,hppa-hp-hpux, sparc-linux, and sparc-sun-solaris, see the file<code>PLATFORMS</code> in the R distribution for more information.<p>If you know about other platforms, please drop us a note.<p><hr>Node:<a name="What%20is%20the%20current%20version%20of%20R%3f">What is the current version of R?</a>,Next:<a rel=next href="#How%20can%20R%20be%20obtained%3f">How can R be obtained?</a>,Previous:<a rel=previous href="#What%20machines%20does%20R%20run%20on%3f">What machines does R run on?</a>,Up:<a rel=up href="#R%20Basics">R Basics</a><br><h2>2.3 What is the current version of R?</h2><p>The current stable Unix/Windows version is 0.90.0, theunstable one is 0.99.0. Typically, new features areintroduced in the development versions; updates of stable versions arefor bug fixes mostly. The version for the Mac is pre-alpha.<p><hr>Node:<a name="How%20can%20R%20be%20obtained%3f">How can R be obtained?</a>,Next:<a rel=next href="#How%20can%20R%20be%20installed%3f">How can R be installed?</a>,Previous:<a rel=previous href="#What%20is%20the%20current%20version%20of%20R%3f">What is the current version of R?</a>,Up:<a rel=up href="#R%20Basics">R Basics</a><br><h2>2.4 How can R be obtained?</h2><p>Sources, binaries and documentation for R can be obtained via CRAN, the"Comprehensive R Archive Network" (see <a href="#What%20is%20CRAN%3f">What is CRAN?</a>).<p><hr>Node:<a name="How%20can%20R%20be%20installed%3f">How can R be installed?</a>,Next:<a rel=next href="#Are%20there%20Unix%20binaries%20for%20R%3f">Are there Unix binaries for R?</a>,Previous:<a rel=previous href="#How%20can%20R%20be%20obtained%3f">How can R be obtained?</a>,Up:<a rel=up href="#R%20Basics">R Basics</a><br><h2>2.5 How can R be installed?</h2><ul><li><a href="#How%20can%20R%20be%20installed%20(Unix)">How can R be installed (Unix)</a>:<li><a href="#How%20can%20R%20be%20installed%20(Windows)">How can R be installed (Windows)</a>:<li><a href="#How%20can%20R%20be%20installed%20(Macintosh)">How can R be installed (Macintosh)</a>:</ul><p><hr>Node:<a name="How%20can%20R%20be%20installed%20(Unix)">How can R be installed (Unix)</a>,Next:<a rel=next href="#How%20can%20R%20be%20installed%20(Windows)">How can R be installed (Windows)</a>,Previous:<a rel=previous href="#How%20can%20R%20be%20installed%3f">How can R be installed?</a>,Up:<a rel=up href="#How%20can%20R%20be%20installed%3f">How can R be installed?</a><br><h3>2.5.1 How can R be installed (Unix)</h3><p>If binaries are available for your platform (see <a href="#Are%20there%20Unix%20binaries%20for%20R%3f">Are there Unix binaries for R?</a>), you can use these, following the instructions thatcome with them.<p>Otherwise, you can compile and install R yourself, which can be donevery easily under a number of common Unix platforms (see <a href="#What%20machines%20does%20R%20run%20on%3f">What machines does R run on?</a>). The file <code>INSTALL</code> that comes with theR distribution contains instructions.<p>Note that you need a FORTRAN compiler or <code>f2c</code> in addition to a Ccompiler to build R. Also, you need Perl version 5 to build thedocumentation. If this is not available on your system, you can obtainprecompiled documentation files via CRAN.<p>In the simplest case, untar the R source code, cd to the directory thuscreated, and issue the following commands (at the shell prompt):<pre>$ ./configure$ make</pre><p>If these commands execute successfully, the R binary and a shell scriptfont-end called <code>R</code> are created and copied to the <code>bin</code>directory. You can copy the script to a place where users can invokeit, for example to <code>/usr/local/bin</code>. In addition, plain text helppages as well as HTML and LaTeX versions of the documentation arebuilt.<p>Use <kbd>make dvi</kbd> to obtain a dvi version of the R manual. Thiscreates the files <code>Manual.dvi</code> (a start of a manual) and<code>Reference.dvi</code> (an R object reference index) in the<code>doc/manual</code> subdirectory. These files can be previewed andprinted using standard programs such as <code>xdvi</code> and <code>dvips</code>.(Note that they have to be built in the source tree.)<p>Finally, use <kbd>make check</kbd> to find out whether your R system workscorrectly.<p>You can also perform a "system-wide" installation using <kbd>makeinstall</kbd>. By default, this will install to the following directories:<dl><dt><code>${prefix}/bin</code><dd>(some) executables<br><dt><code>${prefix}/man/man1</code><dd>man pages<br><dt><code>${prefix}/share/R</code><dd>all the rest (libraries, on-line help system, <small>...</small>). This is the "RHome Directory" (<code>R_HOME</code>) of the installed system.</dl><p>In the above, <code>prefix</code> is determined during configuration(typically <code>/usr/local</code>) and can be set by running <code>configure</code>with the option<pre>$ ./configure --prefix=/where/you/want/R/to/go</pre><p>(E.g., the R executable will then be installed into<code>/where/you/want/R/to/go/bin</code>.)<p><hr>Node:<a name="How%20can%20R%20be%20installed%20(Windows)">How can R be installed (Windows)</a>,Next:<a rel=next href="#How%20can%20R%20be%20installed%20(Macintosh)">How can R be installed (Macintosh)</a>,Previous:<a rel=previous href="#How%20can%20R%20be%20installed%20(Unix)">How can R be installed (Unix)</a>,Up:<a rel=up href="#How%20can%20R%20be%20installed%3f">How can R be installed?</a><br><h3>2.5.2 How can R be installed (Windows)</h3><p>The <code>bin/windows/windows-NT</code> directory of a CRAN site contains thelatest binary distributions of R for 32 bit versions of MS Windows(i.e., 95, 98 or NT), as well as binary distributions for a large numberof add-on packages from CRAN. The Windows version of R was created byRobert Gentleman, and is now being developed and maintained by<a href="mailto:Guido.Masarotto@r-project.org">Guido Masarotto</a> and<a href="mailto:Brian.Ripley@r-project.org">Brian D. Ripley</a>.<p>For most installations the installer <code>rwinst.exe</code> will be theeasiest tool to use.<p>See the <a href="http://www.stats.ox.ac.uk/pub/R/rw-FAQ.html">R Windows FAQ</a> for more details.<p><hr>Node:<a name="How%20can%20R%20be%20installed%20(Macintosh)">How can R be installed (Macintosh)</a>,Previous:<a rel=previous href="#How%20can%20R%20be%20installed%20(Windows)">How can R be installed (Windows)</a>,Up:<a rel=up href="#How%20can%20R%20be%20installed%3f">How can R be installed?</a><br><h3>2.5.3 How can R be installed (Macintosh)</h3><p>The Power Macintosh port is temporarily on hold, and currently no binarydistribution is available. We hope that this will change soon.<p><hr>Node:<a name="Are%20there%20Unix%20binaries%20for%20R%3f">Are there Unix binaries for R?</a>,Next:<a rel=next href="#What%20documentation%20exists%20for%20R%3f">What documentation exists for R?</a>,Previous:<a rel=previous href="#How%20can%20R%20be%20installed%3f">How can R be installed?</a>,Up:<a rel=up href="#R%20Basics">R Basics</a><br><h2>2.6 Are there Unix binaries for R?</h2><p>The <code>bin/linux</code> directory contains Debian 2.1 packages for the i386platform (now part of the Debian distribution and maintained by DougBates) as well as Red Hat 5.1 packages for the alpha and sparc platforms(maintained by Nassib Nasser and Vin Everett, respectively), Red Hat 6.0packages for the i386 and alpha platforms (maintained by Martyn Plummerand Naoki Takebayashi, respectively), S.u.S.E. 5.3/6.0/6.2 i386 packagesby Albrecht Gebhardt, and RPMs for the ppc platform by Alex Buerkle.<p>The <code>bin/osf</code> directory contains RPMs for alpha systems runningDigital Unix 4.0 by Albrecht Gebhardt.<p>No other binary distributions have thus far been made publicallyavailable.<p><hr>Node:<a name="What%20documentation%20exists%20for%20R%3f">What documentation exists for R?</a>,Next:<a rel=next href="#Citing%20R">Citing R</a>,Previous:<a rel=previous href="#Are%20there%20Unix%20binaries%20for%20R%3f">Are there Unix binaries for R?</a>,Up:<a rel=up href="#R%20Basics">R Basics</a><br><h2>2.7 What documentation exists for R?</h2><p>Online documentation for most of the functions and variables in Rexists, and can be printed on-screen by typing <kbd>help(<var>name</var>)</kbd>(or <kbd>?<var>name</var></kbd>) at the R prompt, where <var>name</var> is the name ofthe topic help is sought for. (In the case of unary and binaryoperators and control-flow special forms, the name may need to be bequoted.)<p>This documentation can also be made available as HTML, and as hardcopyvia LaTeX, see <a href="#How%20can%20R%20be%20installed%3f">How can R be installed?</a>. An up-to-date HTMLversion is always available for web browsing at<a href="http://stat.ethz.ch/R/manual/">http://stat.ethz.ch/R/manual/</a>.<p>An earlier attempt at an R manual ("Notes on R: A ProgrammingEnvironment for Data Analysis and Graphics"), based on the "Notes onS-PLUS" by <a href="mailto:venables@stats.adelaide.edu.au">Bill Venables</a> and<a href="mailto:D.M.Smith@lancaster.ac.uk">David Smith</a>, can be obtained as<code>Rnotes.tgz</code> (LaTeX source) in a CRAN <code>doc</code> directory.Further documentation on R and the R API are currently being written.<p>In the absence of an R manual, documentation for S/S-PLUS (see <a href="#R%20and%20S">R and S</a>) can be used in combination with this FAQ (see <a href="#What%20are%20the%20differences%20between%20R%20and%20S%3f">What are the differences between R and S?</a>). We recommend<blockquote>W. N. Venables and B. D. Ripley (1999), "Modern Applied Statistics withS-PLUS. Third Edition". Springer, ISBN 0-387-98825-4.</blockquote><p>which has a home page at <a href="http://www.stats.ox.ac.uk/pub/MASS3/">http://www.stats.ox.ac.uk/pub/MASS3/</a>providing additional material, in particular "R Complements" whichdescribe how to use the book with R. These complements provide bothdescriptions of some of the differences between R and S-PLUS, and themodifications needed to run the examples in the book. Its companionvolume on "S Programming", due in about April 2000, will provide anin-depth guide to writing software in the S language which forms thebasis of both the commercial S-PLUS and the Open Source R data analysissoftware systems.<p>More introductory books are<blockquote>P. Spector (1994), "An introduction to S and S-PLUS", Duxbury Press.<p>A. Krause and M. Olsen (1997), "The Basics of S and S-PLUS", Springer.</blockquote><p>Last, but not least, Ross' and Robert's experience in designing andimplementing R is described in:<pre>@article{,author = {Ross Ihaka and Robert Gentleman},title = {R: A Language for Data Analysis and Graphics},journal = {Journal of Computational and Graphical Statistics},year = 1996,volume = 5,number = 3,pages = {299--314}}</pre><p><hr>Node:<a name="Citing%20R">Citing R</a>,Next:<a rel=next href="#What%20mailing%20lists%20exist%20for%20R%3f">What mailing lists exist for R?</a>,Previous:<a rel=previous href="#What%20documentation%20exists%20for%20R%3f">What documentation exists for R?</a>,Up:<a rel=up href="#R%20Basics">R Basics</a><br><h2>2.8 Citing R</h2><p>To cite R in publications, use the above Ihaka & Gentleman (1996), "R:A Language for Data Analysis and Graphics", <em>Journal ofComputational and Graphical Statistics</em>, <strong>5</strong>, 299-314.<p><hr>Node:<a name="What%20mailing%20lists%20exist%20for%20R%3f">What mailing lists exist for R?</a>,Next:<a rel=next href="#What%20is%20CRAN%3f">What is CRAN?</a>,Previous:<a rel=previous href="#Citing%20R">Citing R</a>,Up:<a rel=up href="#R%20Basics">R Basics</a><br><h2>2.9 What mailing lists exist for R?</h2><p>Thanks to <a href="mailto:Martin.Maechler@r-project.org">Martin Maechler</a>, thereare three mailing lists devoted to R.<dl><dt><code>r-announce</code><dd>This list is for announcements about the development of R and theavailability of new code.<br><dt><code>r-devel</code><dd>This list is for discussions about the future of R and pre-testing ofnew versions. It is meant for those who maintain an active position inthe development of R.<br><dt><code>r-help</code><dd>The `main' R mailing list, for announcements about the development of Rand the availability of new code, questions and answers about problemsand solutions using R, enhancements and patches to the source code anddocumentation of R, comparison and compatibility with S and S-PLUS, andfor the posting of nice examples and benchmarks.</dl><p>Note that the r-announce list is gatewayed into r-help, so you don'tneed to subscribe to both of them.<p>Send email to <a href="mailto:r-help@lists.r-project.org">r-help@lists.r-project.org</a> to reach everyone onthe r-help mailing list. To subscribe (or unsubscribe) to this listsend <code>subscribe</code> (or <code>unsubscribe</code>) in the BODY of the message(not in the subject!) to <a href="mailto:r-help-request@lists.r-project.org">r-help-request@lists.r-project.org</a>.Information about the list can be obtained by sending an email with<code>info</code> as its contents to<a href="mailto:r-help-request@lists.r-project.org">r-help-request@lists.r-project.org</a>.<p>Subscription and posting to the other lists is done analogously, with`r-help' replaced by `r-announce' and `r-devel', respectively.<p>It is recommended that you send mail to r-help rather than only to the Rdevelopers (who are also subscribed to the list, of course). This maysave them precious time they can use for constantly improving R, andwill typically also result in much quicker feedback for yourself.<p>Of course, in the case of bug reports it would be very helpful to havecode which reliably reproduces the problem. Also, make sure that youinclude information on the system and version of R being used. See<a href="#R%20Bugs">R Bugs</a> for more details.<p>Archives of the above three mailing lists are made available on the netin a monthly schedule via the <code>doc/mail/mail.html</code> file in CRAN.An HTML archive of the lists are available via<a href="http://www.ens.gu.edu.au/robertk/R/">http://www.ens.gu.edu.au/robertk/R/</a>.<p>The R Core Team can be reached at <a href="mailto:r-core@lists.r-project.org">r-core@lists.r-project.org</a>for comments and reports.<p><hr>Node:<a name="What%20is%20CRAN%3f">What is CRAN?</a>,Previous:<a rel=previous href="#What%20mailing%20lists%20exist%20for%20R%3f">What mailing lists exist for R?</a>,Up:<a rel=up href="#R%20Basics">R Basics</a><br><h2>2.10 What is CRAN?</h2><p>The "Comprehensive R Archive Network" (CRAN) is a collection of siteswhich carry identical material, consisting of the R distribution(s), thecontributed extensions, documentation for R, and binaries.<p>The CRAN master site can be found at the URL<blockquote><p><table><tr align="left"><td><a href="http://cran.r-project.org/">http://cran.r-project.org/</a><td>(Austria)<br></tr></table></blockquote><p>(which is the same as <a href="http://cran.at.r-project.org/">http://cran.at.r-project.org/</a>) and iscurrently being mirrored daily at<blockquote><p><table><tr align="left"><td><a href="http://cran.dk.r-project.org/">http://cran.dk.r-project.org/</a><td>(Denmark)<br></tr><tr align="left"><td><a href="http://cran.it.r-project.org/">http://cran.it.r-project.org/</a><td>(Italy)<br></tr><tr align="left"><td><a href="http://cran.ch.r-project.org/">http://cran.ch.r-project.org/</a><td>(Switzerland)<br></tr><tr align="left"><td><a href="http://cran.uk.r-project.org/">http://cran.uk.r-project.org/</a><td>(United Kingdom)<br></tr><tr align="left"><td><a href="http://cran.us.r-project.org/">http://cran.us.r-project.org/</a><td>(USA/Wisconsin)<br></tr></table></blockquote><p>Please use the CRAN site closest to you to reduce network load.<p>From CRAN, you can obtain the latest official release of R, dailysnapshots of R (copies of the current CVS trees), as gzipped and bzippedtar files or as two gzipped tar files (ready for 1.4M floppies), awealth of additional contributed code, as well as prebuilt binaries forvarious operating systems (Linux, Nextstep, MacOS, MSWin) andpre-formatted help pages. CRAN also provides access to documentation onR, existing mailing lists and the R Bug Tracking system.<p>To "submit" to CRAN, simply upload to<a href="ftp://cran.r-project.org/incoming">ftp://cran.r-project.org/incoming</a> and send an email to<a href="mailto:wwwadmin@cran.r-project.org">wwwadmin@cran.r-project.org</a>.<blockquote><strong>Note:</strong> It is very important that you indicate the copyright(license) information (GPL, BSD, Artistic, <small>...</small>) in your submission.</blockquote><p>Please always use the URL of the master site when referring to CRAN.<p><hr>Node:<a name="R%20and%20S">R and S</a>,Next:<a rel=next href="#R%20Web%20Interfaces">R Web Interfaces</a>,Previous:<a rel=previous href="#R%20Basics">R Basics</a>,Up:<a rel=up href="#Top">Top</a><br><h1>3 R and S</h1><ul><li><a href="#What%20is%20S%3f">What is S?</a>:<li><a href="#What%20is%20S-PLUS%3f">What is S-PLUS?</a>:<li><a href="#What%20are%20the%20differences%20between%20R%20and%20S%3f">What are the differences between R and S?</a>:<li><a href="#Is%20there%20anything%20R%20can%20do%20that%20S-PLUS%20cannot%3f">Is there anything R can do that S-PLUS cannot?</a>:</ul><p><hr>Node:<a name="What%20is%20S%3f">What is S?</a>,Next:<a rel=next href="#What%20is%20S-PLUS%3f">What is S-PLUS?</a>,Previous:<a rel=previous href="#R%20and%20S">R and S</a>,Up:<a rel=up href="#R%20and%20S">R and S</a><br><h2>3.1 What is S?</h2><p>S is a very high level language and an environment for data analysis andgraphics. S was written by Richard A. Becker, John M. Chambers, andAllan R. Wilks of AT&T Bell Laboratories Statistics Research Department.<p>The primary references for S are two books by the creators of S.<ul><li>Richard A. Becker, John M. Chambers and Allan R. Wilks (1988), "The NewS Language," Chapman & Hall, London.<p>This book is often called the "<em>Blue Book</em>".</p><li>John M. Chambers and Trevor J. Hastie (1992), "Statistical Models inS," Chapman & Hall, London.<p>This is also called the "<em>White Book</em>".</ul><p>Version 4 of S, a major revision of S designed by John Chambers toimprove its usefulness at every stage of the programming process, isdescribed in <a href="http://cm.bell-labs.com/cm/ms/departments/sia/Sbook/">"Programming with Data"</a> by John M. Chambers (1998), Springer: NewYork, ISBN 0-387-98503-4.<p>In 1998, the Association for Computing Machinery presented its SoftwareSystem Award to John Chambers for the design of the S system. The ACMcitation stated that "S has forever altered the way people analyze,visualize, and manipulate data <small>...</small>. S is an elegant, widelyaccepted, and enduring software system, with conceptual integrity,thanks to the insight, taste, and effort of John Chambers." See<a href="http://netlib.bell-labs.com/cm/ms/departments/sia/S/index.html">http://netlib.bell-labs.com/cm/ms/departments/sia/S/index.html</a>for "Stages in the Evolution of S".<p>There is a huge amount of user-contributed code for S, available at the<a href="http://lib.stat.cmu.edu">S Repository</a> at CMU.<p>The <a href="http://lib.stat.cmu.edu/S/faq">"Frequently Asked Questions about S"</a> contains further information about S, but is not up-to-date.<p><hr>Node:<a name="What%20is%20S-PLUS%3f">What is S-PLUS?</a>,Next:<a rel=next href="#What%20are%20the%20differences%20between%20R%20and%20S%3f">What are the differences between R and S?</a>,Previous:<a rel=previous href="#What%20is%20S%3f">What is S?</a>,Up:<a rel=up href="#R%20and%20S">R and S</a><br><h2>3.2 What is S-PLUS?</h2><p>S-PLUS is a value-added version of S sold by Statistical Sciences,Inc. (now a division of Mathsoft, Inc.). Based on the S language,S-PLUS provides functionality in a wide variety of areas, includingrobust regression, modern non-parametric regression, time series,survival analysis, multivariate analysis, classical statistical tests,quality control, and graphics drivers. Add-on modules add additionalcapabilities for wavelet analysis, spatial statistics, GARCH models, anddesign of experiments.<p>See the <a href="http://www.mathsoft.com/splus/">MathSoft S-PLUS page</a> forfurther information.<p><hr>Node:<a name="What%20are%20the%20differences%20between%20R%20and%20S%3f">What are the differences between R and S?</a>,Next:<a rel=next href="#Is%20there%20anything%20R%20can%20do%20that%20S-PLUS%20cannot%3f">Is there anything R can do that S-PLUS cannot?</a>,Previous:<a rel=previous href="#What%20is%20S-PLUS%3f">What is S-PLUS?</a>,Up:<a rel=up href="#R%20and%20S">R and S</a><br><h2>3.3 What are the differences between R and S?</h2><ul><li><a href="#Lexical%20scoping">Lexical scoping</a>:<li><a href="#Models">Models</a>:<li><a href="#Others">Others</a>:</ul><p><hr>Node:<a name="Lexical%20scoping">Lexical scoping</a>,Next:<a rel=next href="#Models">Models</a>,Previous:<a rel=previous href="#What%20are%20the%20differences%20between%20R%20and%20S%3f">What are the differences between R and S?</a>,Up:<a rel=up href="#What%20are%20the%20differences%20between%20R%20and%20S%3f">What are the differences between R and S?</a><br><h3>3.3.1 Lexical scoping</h3><p>Whereas the developers of R have tried to stick to the S language asdefined in "The New S Language" (Blue Book, see <a href="#What%20is%20S%3f">What is S?</a>),they have adopted the evaluation model of Scheme.<p>This difference becomes manifest when <em>free</em> variables occur in afunction. Free variables are those which are neither formal parameters(occurring in the argument list of the function) nor local variables(created by assigning to them in the body of the function). Whereas S(like C) by default uses <em>static</em> scoping, R (like Scheme) hasadopted <em>lexical</em> scoping. This means the values of free variablesare determined by a set of global variables in S, but in R by thebindings that were in effect at the time the function was created.<p>Consider the following function:<pre>cube <- function(n) {sq <- function() n * nn * sq()}</pre><p>Under S, <code>sq()</code> does not "know" about the variable <code>n</code>unless it is defined globally:<pre>S> cube(2)Error in sq(): Object "n" not foundDumpedS> n <- 3S> cube(2)[1] 18</pre><p>In R, the "environment" created when <code>cube()</code> was invoked isalso looked in:<pre>R> cube(2)[1] 8</pre><p>As a more "interesting" real-world problem, suppose you want to writea function which returns the density function of the r-th orderstatistic from a sample of size n from a (continuous) distribution.For simplicity, we shall use both the cdf and pdf of the distributionas explicit arguments. (Example compiled from various postings by LukeTierney.)<p>The S-PLUS documentation for <code>call()</code> basically suggests thefollowing:<pre>dorder <- function(n, r, pfun, dfun) {f <- function(x) NULLcon <- round(exp(lgamma(n + 1) - lgamma(r) - lgamma(n - r + 1)))PF <- call(substitute(pfun), as.name("x"))DF <- call(substitute(dfun), as.name("x"))f[[length(f)]] <-call("*", con,call("*", call("^", PF, r - 1),call("*", call("^", call("-", 1, PF), n - r),DF)))f}</pre><p>Rather tricky, isn't it? The code uses the fact that in S,functions are just lists of special mode with the function body as thelast argument, and hence does not work in R (one could make the ideawork, though).<p>A version which makes heavy use of <code>substitute()</code> and seems to workunder both S and R is<pre>dorder <- function(n, r, pfun, dfun) {con <- round(exp(lgamma(n + 1) - lgamma(r) - lgamma(n - r + 1)))eval(substitute(function(x) K * PF(x)^a * (1 - PF(x))^b * DF(x),list(PF = substitute(pfun), DF = substitute(dfun),a = r - 1, b = n - r, K = con)))}</pre><p>(the <code>eval()</code> is not needed in S).<p>However, in R there is a much easier solution:<pre>dorder <- function(n, r, pfun, dfun) {con <- round(exp(lgamma(n + 1) - lgamma(r) - lgamma(n - r + 1)))function(x) {con * pfun(x)^(r - 1) * (1 - pfun(x))^(n - r) * dfun(x)}}</pre><p>This seems to be the "natural" implementation, and it works becausethe free variables in the returned function can be looked up in thedefining environment (this is lexical scope).<p>Note that what you really need is the function <em>closure</em>, i.e., thebody along with all variable bindings needed for evaluating it. Sincein the above version, the free variables in the value function are notmodified, you can actually use it in S as well if you abstract out theclosure operation into a function <code>MC()</code> (for "make closure"):<pre>dorder <- function(n, r, pfun, dfun) {con <- round(exp(lgamma(n + 1) - lgamma(r) - lgamma(n - r + 1)))MC(function(x) {con * pfun(x)^(r - 1) * (1 - pfun(x))^(n - r) * dfun(x)},list(con = con, pfun = pfun, dfun = dfun, r = r, n = n))}</pre><p>Given the appropriate definitions of the closure operator, this works inboth R and S, and is much "cleaner" than a substitute/eval solution(or one which overrules the default scoping rules by using explicitaccess to evaluation frames, as is of course possible in both R and S).<p>For R, <code>MC()</code> simply is<pre>MC <- function(f, env) f</pre><p>(lexical scope!), a version for S is<pre>MC <- function(f, env = NULL) {env <- as.list(env)if (mode(f) != "function")stop(paste("not a function:", f))if (length(env) > 0 && any(names(env) == ""))stop(paste("not all arguments are named:", env))fargs <- if(length(f) > 1) f[1:(length(f) - 1)] else NULLfargs <- c(fargs, env)if (any(duplicated(names(fargs))))stop(paste("duplicated arguments:", paste(names(fargs)),collapse = ", "))fbody <- f[length(f)]cf <- c(fargs, fbody)mode(cf) <- "function"return(cf)}</pre><p>Similarly, most optimization (or zero-finding) routines need somearguments to be optimized over and have other parameters that depend onthe data but are fixed with respect to optimization. With R scopingrules, this is a trivial problem; simply make up the function with therequired definitions in the same environment and scoping takes care ofit. With S, one solution is to add an extra parameter to the functionand to the optimizer to pass in these extras, which however can onlywork if the optimizer supports this.<p>Lexical scoping allows using function closures and maintaining localstate. A simple example (taken from Abelson and Sussman) is obtained bytyping <kbd>demo(scoping)</kbd> at the R prompt. Further information isprovided in the standard R reference "R: A Language for Data Analysisand Graphics" (see <a href="#What%20documentation%20exists%20for%20R%3f">What documentation exists for R?</a>) and a paper on"Lexical Scope and Statistical Computing" by Robert Gentleman and RossIhaka which can be obtained from the <code>doc/misc</code> directory of a CRANsite and will appear in the <em>Journal of Computational and GraphicalStatistics</em> around the beginning of 2000.<p>Lexical scoping also implies a further major difference. Whereas Sstores all objects as separate files in a directory somewhere (usually<code>.Data</code> under the current directory), R does not. All objectsin R are stored internally. When R is started up it grabs a very largepiece of memory and uses it to store the objects. R performs its ownmemory management of this piece of memory. Having everything in memoryis necessary because it is not really possible to externally maintainall relevant "environments" of symbol/value pairs. This differencealso seems to make R <em>faster</em> than S.<p>The down side is that if R crashes you will lose all the work for thecurrent session. Saving and restoring the memory "images" (thefunctions and data stored in R's internal memory at any time) can be abit slow, especially if they are big. In S this does not happen,because everything is saved in disk files and if you crash nothing islikely to happen to them. (In fact, one might conjecture that the Sdevelopers felt that the price of changing their approach to persistentstorage just to accommodate lexical scope was far too expensive.) R isstill in a beta stage, and may crash from time to time. Hence, forimportant work you should consider saving often (see <a href="#How%20can%20I%20save%20my%20workspace%3f">How can I save my workspace?</a>). Other possibilities are logging your sessions, or haveyour R commands stored in text files which can be read in using<code>source()</code>.<blockquote><strong>Note:</strong> If you run R from within Emacs (see <a href="#R%20and%20Emacs">R and Emacs</a>),you can save the contents of the interaction buffer to a file andconveniently manipulate it using <code>ess-transcript-mode</code>, as well assave source copies of all functions and data used.</blockquote><p><hr>Node:<a name="Models">Models</a>,Next:<a rel=next href="#Others">Others</a>,Previous:<a rel=previous href="#Lexical%20scoping">Lexical scoping</a>,Up:<a rel=up href="#What%20are%20the%20differences%20between%20R%20and%20S%3f">What are the differences between R and S?</a><br><h3>3.3.2 Models</h3><p>There are some differences in the modeling code, such as<ul><li>Whereas in S, you would use <code>lm(y ~ x^3)</code> to regress <code>y</code> on<code>x^3</code>, in R, you have to insulate powers of numeric vectors (using<code>I()</code>), i.e., you have to use <code>lm(y ~ I(x^3))</code>.<li>The glm family objects are implemented differently in R and S. The samefunctionality is available but the components have different names.<li>Terms objects are stored differently. In S a terms object is anexpression with attributes, in R it is a formula with attributes. Theattributes have the same names but are mostly stored differently. Themajor difference in functionality is that a terms object issubscriptable in S but not in R. If you can't imagine why this wouldmatter then you don't need to know.<li>Finally, in R <code>y~x+0</code> is an alternative to <code>y~x-1</code> forspecifying a model with no intercept. Models with no parameters at allcan be specified by <code>y~0</code>.</ul><p><hr>Node:<a name="Others">Others</a>,Previous:<a rel=previous href="#Models">Models</a>,Up:<a rel=up href="#What%20are%20the%20differences%20between%20R%20and%20S%3f">What are the differences between R and S?</a><br><h3>3.3.3 Others</h3><p>Apart from lexical scoping and its implications, R follows the Slanguage definition in the Blue Book as much as possible, and hencereally is an "implementation" of S. There are some intentionaldifferences where the behavior of S is considered "not clean". Ingeneral, the rationale is that R should help you detect programmingerrors, while at the same time being as compatible as possible with S.<p>Some known differences are the following.<ul><li>In R, if <code>x</code> is a list, then <code>x[i] <- NULL</code> and <code>x[[i]]<- NULL</code> remove the specified elements from <code>x</code>. The first ofthese is incompatible with S, where it is a no-op. (Note that you canset elements to <code>NULL</code> using <code>x[i] <- list(NULL)</code>.)<li>In S, the functions named <code>.First</code> and <code>.Last</code> in the<code>.Data</code> directory can be used for customizing, as they are executedat the very beginning and end of a session, respectively.<p>In R, the startup mechanism is as follows. R first sources the systemstartup file <code><code>$R_HOME</code>/library/base/R/Rprofile</code>. Then, itsearches for a site-wide startup profile unless the command line option<code>--no-site-file</code> was given. The name of this file is taken fromthe value of the <code>R_PROFILE</code> environment variable. If that variableis unset, the default is <code><code>$R_HOME</code>/etc/Rprofile</code>. Then,unless <code>--no-init-file</code> was given, R searches for a file called<code>.Rprofile</code> in the current directory or in the user's homedirectory (in that order) and sources it. It also loads a saved imagefrom <code>.RData</code> in case there is one (unless <code>--no-restore</code>was specified). If needed, the functions <code>.First()</code> and<code>.Last()</code> should be defined in the appropriate startup profiles.</p><li>In R, <code>T</code> and <code>F</code> are just variables being set to <code>TRUE</code>and <code>FALSE</code>, respectively, but are not reserved words as in S andhence can be overwritten by the user. (This helps e.g. when you havefactors with levels "T" or "F".) Hence, when writing code you shouldalways use <code>TRUE</code> and <code>FALSE</code>.<li>In R, <code>dyn.load()</code> can only load <em>shared libraries</em>, ascreated for example by <kbd>R SHLIB</kbd>.<li>In R, <code>attach()</code> currently only works for lists and data frames(not for directories). Also, you cannot attach at position 1.<li>Categories do not exist in R, and never will as they are deprecated nowin S. Use factors instead.<li>In R, <code>For()</code> loops are not necessary and hence not supported.<li>In R, <code>assign()</code> uses the argument <code>envir=</code> rather than<code>where=</code> as in S.<li>The random number generators are different, and the seeds have differentlength.<li>R passes integer objects to C as <code>int *</code> rather than <code>long *</code>as in S.<li>R has no single precision storage mode. However, as of version 0.65.1,there is a single precision interface to C/FORTRAN subroutines.<li>By default, <code>ls()</code> returns the names of the objects in the current(under R) and global (under S) environment, respectively. For example,given<pre>x <- 1; fun <- function() {y <- 1; ls()}</pre><p>then <code>fun()</code> returns <code>"y"</code> in R and <code>"x"</code> (together withthe rest of the global environment) in S.</p><li>R allows for zero-extent matrices (and arrays, i.e., some elements ofthe <code>dim</code> attribute vector can be 0). This has been determined auseful feature as it helps reducing the need for special-case tests forempty subsets. For example, if <code>x</code> is a matrix, <code>x[, FALSE]</code>is not <code>NULL</code> but a "matrix" with 0 columns. Hence, such objectsneed to be tested for by checking whether their <code>length()</code> is zero(which works in both R and S), and not using <code>is.null()</code>.<li>Named vectors are considered vectors in R but not in S (e.g.,<code>is.vector(c(a = 1:3))</code> returns <code>FALSE</code> in S and <code>TRUE</code>in R).<li>Data frames are not considered as matrices in R (i.e., if <code>DF</code> is adata frame, then <code>is.matrix(DF)</code> returns <code>FALSE</code> in R and<code>TRUE</code> in S).<li>R by default uses treatment contrasts in the unordered case, whereas Suses the Helmert ones. This is a deliberate difference reflecting theopinion that treatment contrasts are more natural.<li>In R, the last argument (which corresponds to the right hand side) of anassignment function must be named <code>value</code>. E.g., <code>fun(a) <-b</code> is evaluated as <code>(fun<-)(a, value = b)</code>.<li>In S, <code>substitute()</code> searches for names for substitution in thegiven expression in three places: the actual and the default argumentsof the matching call, and the local frame (in that order). R looks inthe local frame only, with the special rule to use a "promise" if avariable is not evaluated. Since the local frame is initialized with theactual arguments or the default expressions, this is usually equivalentto S, until assignment takes place.<li>In R, <code>eval(EXPR, sys.parent())</code> does not work. Instead, oneshould use <code>eval(EXPR, sys.frame(sys.parent())),</code> which also worksin S.<li>In S, the index variable in a <code>for()</code> loop is local to the insideof the loop. In R it is local to the environment where the <code>for()</code>statement is executed.<li>In S, <code>tapply(simplify=TRUE)</code> returns a vector where R returns aone-dimensional array (which can have named dimnames).</ul><p>There are also differences which are not intentional, and result frommissing or incorrect code in R. The developers would appreciate hearingabout any deficiencies you may find (in a written report fullydocumenting the difference as you see it). Of course, it would beuseful if you were to implement the change yourself and make sure itworks.<p><hr>Node:<a name="Is%20there%20anything%20R%20can%20do%20that%20S-PLUS%20cannot%3f">Is there anything R can do that S-PLUS cannot?</a>,Previous:<a rel=previous href="#What%20are%20the%20differences%20between%20R%20and%20S%3f">What are the differences between R and S?</a>,Up:<a rel=up href="#R%20and%20S">R and S</a><br><h2>3.4 Is there anything R can do that S-PLUS cannot?</h2><p>Since almost anything you can do in R has source code that you couldport to S-PLUS with little effort there will never be much you can do inR that you couldn't do in S-PLUS if you wanted to. (Note that usinglexical scoping may simplify matters considerably, though.)<p>R offers several graphics features that S-PLUS does not, such as finerhandling of line types, more convenient color handling (via palettes),gamma correction for color, and, most importantly, mathematicalannotation in plot texts, via input expressions reminiscent of TeXconstructs. Unfortunately, this feature still is mostly undocumented.The paper "An Approach to Providing Mathematical Annotation in Plots"by Paul Murrell and Ross Ihaka, which will soon appear in the<em>Journal of Computational and Graphical Statistics</em>, has moredetails on this.<p><hr>Node:<a name="R%20Web%20Interfaces">R Web Interfaces</a>,Next:<a rel=next href="#R%20Add-On%20Packages">R Add-On Packages</a>,Previous:<a rel=previous href="#R%20and%20S">R and S</a>,Up:<a rel=up href="#Top">Top</a><br><h1>4 R Web Interfaces</h1><p><strong>Rcgi</strong> is a CGI WWW interface to R by <a href="mailto:h089@mth.uea.ac.uk">Mark J Ray</a>. Recent version have the ability to use "embedded code":you can mix user input and code, allowing the HTML author to do anythingfrom load in data sets to enter most of the commands for users withoutwriting CGI scripts. Graphical output is possible in PostScript or GIFformats and the executed code is presented to the user for revision.<p>Demo and download are available from<a href="http://www.mth.uea.ac.uk/~h089/Rcgi/">http://www.mth.uea.ac.uk/~h089/Rcgi/</a>.<p><strong>Rweb</strong> is developed and maintained by<a href="mailto:jeff@math.montana.edu">Jeff Banfield</a>. The<a href="http://www.math.montana.edu/Rweb">Rweb Home Page</a> provides accessto all three versions of Rweb--a simple text entry form that returnsoutput and graphs, a more sophisticated Javascript version that providesa multiple window environment, and a set of point and click modules thatare useful for introductory statistics courses and require no knowledgeof the R language. All of the Rweb versions can analyze Web accessibledatasets if a URL is provided.<p>A paper on Rweb, providing a detailed explanation of the differentversions of Rweb and an overview of how Rweb works, was published in theJournal of Statistical Software(<a href="http://www.stat.ucla.edu/journals/jss/">http://www.stat.ucla.edu/journals/jss/</a>).<p><hr>Node:<a name="R%20Add-On%20Packages">R Add-On Packages</a>,Next:<a rel=next href="#R%20and%20Emacs">R and Emacs</a>,Previous:<a rel=previous href="#R%20Web%20Interfaces">R Web Interfaces</a>,Up:<a rel=up href="#Top">Top</a><br><h1>5 R Add-On Packages</h1><ul><li><a href="#Which%20add-on%20packages%20exist%20for%20R%3f">Which add-on packages exist for R?</a>:<li><a href="#How%20can%20add-on%20packages%20be%20installed%3f">How can add-on packages be installed?</a>:<li><a href="#How%20can%20add-on%20packages%20be%20used%3f">How can add-on packages be used?</a>:<li><a href="#How%20can%20add-on%20packages%20be%20removed%3f">How can add-on packages be removed?</a>:<li><a href="#How%20can%20I%20create%20an%20R%20package%3f">How can I create an R package?</a>:<li><a href="#How%20can%20I%20contribute%20to%20R%3f">How can I contribute to R?</a>:</ul><p><hr>Node:<a name="Which%20add-on%20packages%20exist%20for%20R%3f">Which add-on packages exist for R?</a>,Next:<a rel=next href="#How%20can%20add-on%20packages%20be%20installed%3f">How can add-on packages be installed?</a>,Previous:<a rel=previous href="#R%20Add-On%20Packages">R Add-On Packages</a>,Up:<a rel=up href="#R%20Add-On%20Packages">R Add-On Packages</a><br><h2>5.1 Which add-on packages exist for R?</h2><p>The R distribution comes with the following extra packages:<dl><dt><strong>eda</strong><dd>Exploratory Data Analysis. Currently only contains functions for robustline fitting, and median polish and smoothing.<br><dt><strong>lqs</strong><dd>Resistant regression and covariance estimation.<br><dt><strong>modreg</strong><dd>MODern REGression: smoothing and local methods.<br><dt><strong>mva</strong><dd>MultiVariate Analysis. Currently contains code for principalcomponents, canonical correlations, metric multidimensional scaling, andhierarchical and k-means clustering.<br><dt><strong>nls</strong><dd>Nonlinear regression routines.<br><dt><strong>splines</strong><dd>Regression spline functions and classes.<br><dt><strong>stepfun</strong><dd>Code for dealing with step functions, including empirical cumulativedistribution functions.<br><dt><strong>ts</strong><dd>Time series.</dl><p>The following packages are available from the CRAN <code>src/contrib</code>area.<dl><dt><strong>KernSmooth</strong><dd>Functions for kernel smoothing (and density estimation) corresponding tothe book "Kernel Smoothing" by M. P. Wand and M. C. Jones, 1995.<br><dt><strong>MASS</strong><dd>Functions and datasets from the main library of Venables and Ripley,"Modern Applied Statistics with S-PLUS". Contained in <code>VR</code>.<br><dt><strong>NISTnls</strong><dd>A set of test nonlinear least squares examples from NIST, theU.S. National Institute for Standards and Technology.<br><dt><strong>RmSQL</strong><dd>An interface between R and the mSQL database system.<br><dt><strong>Rnotes</strong><dd>The data sets for the exercises in Rnotes (see <a href="#What%20documentation%20exists%20for%20R%3f">What documentation exists for R?</a>).<br><dt><strong>acepack</strong><dd>ace (Alternating Conditional Expectations) and avas (Additivity andVAriance Stabilization for regression) for selecting regressiontransformations.<br><dt><strong>akima</strong><dd>Linear or cubic spline interpolation for irregularly gridded data.<br><dt><strong>ash</strong><dd>Programs for 1D and 2D density estimation.<br><dt><strong>bindata</strong><dd>Generation of correlated artificial binary data.<br><dt><strong>boot</strong><dd>Functions and datasets for bootstrapping from the book "BootstrapMethods and Their Applications" by A. C. Davison and D. V. Hinkley,1997, Cambridge University Press.<br><dt><strong>bootstrap</strong><dd>Software (bootstrap, cross-validation, jackknife), data and errata forthe book "An Introduction to the Bootstrap" by B. Efron andR. Tibshirani, 1993, Chapman and Hall.<br><dt><strong>cclust</strong><dd>Convex clustering methods, including k-means algorithm, on-line updatealgorithm (Hard Competitive Learning) and Neural Gas algorithm (SoftCompetitive Learning) and calculation of several indexes for finding thenumber of clusters in a data set.<br><dt><strong>chron</strong><dd>A package for working with chronological objects (times and dates).<br><dt><strong>class</strong><dd>Functions for classification (k-nearest neighbor and LVQ). Contained in<code>VR</code>.<br><dt><strong>cluster</strong><dd>Functions for cluster analysis.<br><dt><strong>coda</strong><dd>Output analysis and diagnostics for Markov Chain Monte Carlo (MCMC)simulations.<br><dt><strong>ctest</strong><dd>A collection of classical tests, including the Bartlett, Fisher,Kruskal-Wallis, Kolmogorov-Smirnov, and Wilcoxon tests.<br><dt><strong>date</strong><dd>Functions for dealing with dates. The most useful of them accepts avector of input dates in any of the forms <code>8/30/53</code>,<code>30Aug53</code>, <code>30 August 1953</code>, <small>...</small>, <code>August 30 53</code>, orany mixture of these.<br><dt><strong>e1071</strong><dd>Miscellaneous functions used at the Department of Statistics at TU Wien(E1071).<br><dt><strong>fracdiff</strong><dd>Maximum likelihood estimation of the parameters of a fractionallydifferenced ARIMA(p,d,q) model (Haslett and Raftery, Applied Statistics,1989).<br><dt><strong>funfits</strong><dd>An integrated set of functions for fitting curves and surfaces includingthin plate splines, kriging and neural networks.<br><dt><strong>gee</strong><dd>An implementation of the Liang/Zeger generalized estimating equationapproach to GLMs for dependent data.<br><dt><strong>gss</strong><dd>A comprehensive package for structural multivariate function estimationusing smoothing splines.<br><dt><strong>integrate</strong><dd>Adaptive quadrature in up to 20 dimensions.<br><dt><strong>leaps</strong><dd>A package which performs an exhaustive search for the best subsets of agiven set of potential regressors, using a branch-and-bound algorithm,and also performs searches using a number of less time-consumingtechniques.<br><dt><strong>lmtest</strong><dd>A collection of tests on the assumptions of linear regression modelsfrom the book "The linear regression model under test" by W. Kraemerand H. Sonnberger, 1986, Physica.<br><dt><strong>locfit</strong><dd>Local Regression, likelihood and density estimation.<br><dt><strong>logspline</strong><dd>Logspline density estimation.<br><dt><strong>mclust</strong><dd>Model-based cluster analysis.<br><dt><strong>mda</strong><dd>Code for mixture discriminant analysis (MDA), flexible discriminantanalysis (FDA), penalized discriminant analysis (PDA), multivariateadditive regression splines (MARS), adaptive back-fitting splines(BRUTO), and penalized regression.<br><dt><strong>mlbench</strong><dd>A collection of artificial and real-world machine learning benchmarkproblems, including the Boston housing data.<br><dt><strong>multilm</strong><dd>A basic method for fitting and testing multivariate linear models,including stabilized test procedures by Laeuter et. al.<br><dt><strong>multiv</strong><dd>Functions for hierarchical clustering, partitioning, bond energyalgorithm, Sammon mapping, PCA and correspondence analysis.<br><dt><strong>nlme</strong><dd>Fit and compare Gaussian linear and nonlinear mixed-effects models.<br><dt><strong>nnet</strong><dd>Software for single hidden layer perceptrons ("feed-forward neuralnetworks"), and for multinomial log-linear models. Contained in<code>VR</code>.<br><dt><strong>norm</strong><dd>Analysis of multivariate normal datasets with missing values.<br><dt><strong>oz</strong><dd>Functions for plotting Australia's coastline and state boundaries.<br><dt><strong>pls</strong><dd>Univariate Partial Least Squares Regression.<br><dt><strong>polymars</strong><dd>Polychotomous regression based on Multivariate Adaptive RegressionSplines.<br><dt><strong>polynom</strong><dd>A collection of functions to implement a class for univariate polynomialmanipulations.<br><dt><strong>princurve</strong><dd>Fits a principal curve to a matrix of points in arbitrary dimension.<br><dt><strong>pspline</strong><dd>Smoothing splines with penalties on order m derivatives.<br><dt><strong>quadprog</strong><dd>For solving quadratic programming problems.<br><dt><strong>quantreg</strong><dd>Compute regression quantiles and some related rank statistics.<br><dt><strong>rmeta</strong><dd>Functions for simple fixed and random effects meta-analysis fortwo-sample comparison of binary outcomes.<br><dt><strong>rpart</strong><dd>Recursive Partitioning.<br><dt><strong>sgeostat</strong><dd>An object-oriented framework for geostatistical modeling.<br><dt><strong>sm</strong><dd>Software linked to the book "Applied Smoothing Techniques for DataAnalysis: The Kernel Approach with S-PLUS Illustrations" byA. W. Bowman and A. Azzalini (1997), Oxford University Press.<br><dt><strong>spatial</strong><dd>Functions for kriging and point pattern analysis from "Modern AppliedStatistics with S-PLUS" by W. Venables and B. Ripley. Contained in<code>VR</code>.<br><dt><strong>stable</strong><dd>Density, distribution, quantile and hazard functions of a stablevariate; generalized linear models for the parameters of a stabledistribution.<br><dt><strong>stataread</strong><dd>Read and write Stata v6 <code>.dta</code> files.<br><dt><strong>survival5</strong><dd>Functions for survival analysis, version 5 (requires <strong>splines</strong>and suggests <strong>date</strong>), the main new feature being penalised(partial) likelihood.<br><dt><strong>tree</strong><dd>Classification and regression trees.<br><dt><strong>tripack</strong><dd>A constrained two-dimensional Delaunay triangulation package.<br><dt><strong>tseries</strong><dd>Additional code for time series analysis.<br><dt><strong>wavethresh</strong><dd>Software to perform 1-d and 2-d wavelet statistics and transforms.<br><dt><strong>xgobi</strong><dd>Interface to the XGobi and XGvis programs for graphical data analysis.</dl><p>See CRAN <code>src/contrib/INDEX</code> for more information.<p>There is also a CRAN <code>src/contrib/Devel</code> directory which containspackages still "under development" or depending on features onlypresent in the current development versions of R. Volunteers areinvited to give these a try, of course. This area of CRAN currentlycontains<dl><dt><strong>bats</strong><dd>Basic time series modelling functions.<br><dt><strong>dopt</strong><dd>Finding D-optimal experimental designs.<br><dt><strong>tcltk</strong><dd>Basic interface with Tcl/Tk.<br><dt><strong>timeslab</strong><dd>Time series routines.<br><dt><strong>vtcl</strong><dd>Interface to Visual Tcl.</dl><a href="mailto:jlindsey@luc.ac.be">Jim Lindsey</a> has written a collection of Rpackages for nonlinear regression and repeated measurements, consistingof <strong>event</strong> (procedures for event history analysis), <strong>gnlm</strong>(generalized nonlinear regression models), <strong>growth</strong> (normaltheory repeated measurements models), <strong>repeated</strong> (models fornon-normal repeated measurements.), and <strong>rmutil</strong> (tools forrepeated measurements). Jim's packages were used for all analyses inthe new edition of his book "Models for Repeated Measurements" (1999,Oxford University Press), and can be obtained from<a href="http://www.luc.ac.be/~jlindsey/rcode.html">http://www.luc.ac.be/~jlindsey/rcode.html</a>.<a href="mailto:pgilbert@bank-banque-canada.ca">Paul Gilbert</a> has written theDynamic Systems Estimation (DSE) Library, a multivariate time seriespackage which implements an object oriented approach to time seriesmodels (using classes and methods in R/S). The package providesstate-space models and the Kalman filter, VARMA and cointegrationmodels, and numerical differentiation. It also contains Troll models asanother class (the Troll interface is not yet functional in R). Paul'spackage <strong>dse</strong> can be obtained via<a href="http://www.bank-banque-canada.ca/pgilbert/dsedesc.htm">http://www.bank-banque-canada.ca/pgilbert/dsedesc.htm</a>.<p>More code has been posted to the r-help mailing list, and can beobtained from the mailing list archive.<p><hr>Node:<a name="How%20can%20add-on%20packages%20be%20installed%3f">How can add-on packages be installed?</a>,Next:<a rel=next href="#How%20can%20add-on%20packages%20be%20used%3f">How can add-on packages be used?</a>,Previous:<a rel=previous href="#Which%20add-on%20packages%20exist%20for%20R%3f">Which add-on packages exist for R?</a>,Up:<a rel=up href="#R%20Add-On%20Packages">R Add-On Packages</a><br><h2>5.2 How can add-on packages be installed?</h2><p>(Unix only.) The add-on packages on CRAN come as gzipped tar files(which may contain more than one package). First "unpack" the filesof interest. If you have GNU tar, you can use <kbd>tar zxf <var>name</var></kbd>,otherwise you can use <kbd>gunzip -c <var>name</var> | tar xf -</kbd>.<p>Let <var>pkgdir_1</var>, <small>...</small>, <var>pkgdir_n</var> be the (relative orabsolute) path names of the packages to be installed. (In the simplestcase, the unpacking creates a single package directory, and its name isused.) To install to the default R directory tree (the <code>library</code>subdirectory of <code>R_HOME</code>), type<pre>$ R INSTALL <var>pkgdir_1</var> <small>...</small> <var>pkgdir_n</var></pre><p>at the shell prompt. To install to another tree (e.g., your privateone), use<pre>$ R INSTALL -l <var>lib</var> <var>pkgdir_1</var> <small>...</small> <var>pkgdir_n</var></pre><p>where <var>lib</var> gives the path to the library tree to install to.<p>As of R version 0.65.1, you no longer need to explicitly unpack forinstalling; i.e., you can do <kbd>R INSTALL /path/to/pkg_ver.tar.gz</kbd>.<p>You can use several library trees of add-on packages. The easiest wayto tell R to use these is via the environment variable <code>R_LIBS</code>which should be a colon-separated list of directories at which R librarytrees are rooted. You do not have to specify the default tree in<code>R_LIBS</code>. E.g., to use a private tree in <code>$HOME/lib/R</code> and apublic site-wide tree in <code>/usr/local/lib/R/site</code>, put<pre>R_LIBS="$HOME/lib/R:/usr/local/lib/R/site"; export R_LIBS</pre><p>into your (Bourne) shell profile or your <code>~/.Renviron</code> file.<p><hr>Node:<a name="How%20can%20add-on%20packages%20be%20used%3f">How can add-on packages be used?</a>,Next:<a rel=next href="#How%20can%20add-on%20packages%20be%20removed%3f">How can add-on packages be removed?</a>,Previous:<a rel=previous href="#How%20can%20add-on%20packages%20be%20installed%3f">How can add-on packages be installed?</a>,Up:<a rel=up href="#R%20Add-On%20Packages">R Add-On Packages</a><br><h2>5.3 How can add-on packages be used?</h2><p>To find out which additional packages are available on your system, type<pre>library()</pre><p>at the R prompt.<p>This produces something like<pre>Packages in `/home/me/lib/R':mystuff My own R functions, nicely packaged but not documentedPackages in `/usr/local/lib/R/library':MASS Main package of Venables and Ripley's MASSbase The R base packageclass Functions for classificationcluster Functions for clusteringctest Classical testsdate Functions for handling dateseda Exploratory Data Analysisgee Generalized Estimating Equation modelslme Linear mixed effects librarylocfit Local regression, likelihood and density estimationlqs Resistant regression and covariance estimationmodreg Modern regression: smoothing and local methodsmva Classical Multivariate Analysisnls Nonlinear regressionnnet Software for feed-forward neural networks with a singlehidden layer and for multinomial log-linear models.splines Regression spline functions and classesstepfun Step functions, including empirical distributionssurvival5 Survival analysists Time series functions</pre><p>You can "load" the installed package <var>pkg</var> by<pre>library(<var>pkg</var>)</pre><p>You can then find out which functions it provides by typing one of<pre>help(package = <var>pkg</var>)library(help = <var>pkg</var>)</pre><p>You can unload the loaded package <var>pkg</var> by<pre>detach("package:<var>pkg</var>")</pre><p><hr>Node:<a name="How%20can%20add-on%20packages%20be%20removed%3f">How can add-on packages be removed?</a>,Next:<a rel=next href="#How%20can%20I%20create%20an%20R%20package%3f">How can I create an R package?</a>,Previous:<a rel=previous href="#How%20can%20add-on%20packages%20be%20used%3f">How can add-on packages be used?</a>,Up:<a rel=up href="#R%20Add-On%20Packages">R Add-On Packages</a><br><h2>5.4 How can add-on packages be removed?</h2><p>To remove the packages <var>pkg_1</var>, <small>...</small>, <var>pkg_n</var> from thedefault library or the library <var>lib</var>, do<pre>$ R REMOVE <var>pkg_1</var> <small>...</small> <var>pkg_n</var></pre><p>or<pre>$ R REMOVE -l <var>lib</var> <var>pkg_1</var> <small>...</small> <var>pkg_n</var></pre><p>respectively.<p><hr>Node:<a name="How%20can%20I%20create%20an%20R%20package%3f">How can I create an R package?</a>,Next:<a rel=next href="#How%20can%20I%20contribute%20to%20R%3f">How can I contribute to R?</a>,Previous:<a rel=previous href="#How%20can%20add-on%20packages%20be%20removed%3f">How can add-on packages be removed?</a>,Up:<a rel=up href="#R%20Add-On%20Packages">R Add-On Packages</a><br><h2>5.5 How can I create an R package?</h2><p>A package consists of a subdirectory containing the files<code>DESCRIPTION</code>, <code>INDEX</code>, and <code>TITLE</code>, and thesubdirectories <code>R</code>, <code>data</code>, <code>exec</code>, <code>inst</code>,<code>man</code> and <code>src</code> (some of which can be missing).<p>The <code>DESCRIPTION</code> file contains basic information about the packagein the following format:<pre>Package: e1071Version: 0.7-3Author: Compiled by Fritz Leisch <Friedrich.Leisch@ci.tuwien.ac.at>.Description: Miscellaneous functions used at the Department ofStatistics at TU Wien (E1071).Depends:License: GPL version 2 or later</pre><p>The license field should contain an explicit statement or a well-knownabbreviation (such as <code>GPL</code>, <code>LGPL</code>, <code>BSD</code> and<code>Artistic</code>), maybe followed by a reference to the actual licensefile. It is very important that you include this information!Otherwise, it may not even be legally correct for others to distributecopies of the package.<p>The <code>TITLE</code> file contains a line giving the name of the packageand a brief description. <code>INDEX</code> contains a line for eachsufficiently interesting object in the package, giving its name and adescription (functions such as print methods not usually calledexplicitly might not be included). Note that you can automaticallycreate this file using something like <code>R CMD Rdindex man/*.Rd >INDEX</code> provided that Perl is available on your system.<p>The <code>R</code> subdirectory contains code files. The code files to beinstalled must start with a (lower- or uppercase) letter and have one ofthe extensions <code>.R</code>, <code>.S</code>, <code>.q</code>, <code>.r</code>, or <code>.s</code>.We recommend using <code>.R</code>, as this extension seems to be not used byany other software. It should be possible to read in the files using<code>source()</code>, so R objects must be created by assignments. Note thatthere has to be no connection between the name of the file and the Robjects created by it. If necessary, one of these files (historically<code>zzz.R</code>) should use <code>library.dynam()</code> <em>inside</em><code>.First.lib()</code> to load compiled code.<p>The <code>man</code> subdirectory should contain documentation files for theobjects in the package. The documentation files to be installed mustalso start with a (lower- or uppercase) letter and have the extension<code>.Rd</code> (the default) or <code>.rd</code>.<p>C or FORTRAN source and optionally a <code>Makefile</code> for the compiledcode is in <code>src</code>. Note that the <code>Makefile</code> most likely is notneeded.<p>The <code>data</code> subdirectory is for additional data files the packagemakes available for loading using <code>data()</code>. Currently, data filescan have one of three types as indicated by their extension: plain Rcode (<code>.R</code> or <code>.r</code>), tables (<code>.tab</code>, <code>.txt</code>, or<code>.csv</code>), or <code>save()</code> images (<code>.RData</code> or <code>.rda</code>).The subdirectory should contain a <code>00Index</code> file that describesthe datasets available.<p>The contents of the <code>inst</code> subdirectory will be copied recursivelyto the installation directory.<p>Finally, <code>exec</code> could contain additional executables the packageneeds, typically Shell or Perl scripts. This mechanism is currently notused by any package, and still experimental.<p>You can also provide (Bourne) shell scripts <code>configure</code> and<code>cleanup</code> for configuration before installation (such as checkingfor additional software that might be needed by the package), andremoving the files created in this process. See the add-on package<strong>e1071</strong> on CRAN for an example of this mechanism.<p>See the documentation for <code>library()</code> for more information.<p>The web page <a href="http://www.biostat.washington.edu/~thomas/Rlib.html">http://www.biostat.washington.edu/~thomas/Rlib.html</a>maintained by Thomas Lumley provides information on porting S packagesto R.<p>See <a href="#What%20is%20CRAN%3f">What is CRAN?</a>, for information on uploading a package to CRAN.<p><hr>Node:<a name="How%20can%20I%20contribute%20to%20R%3f">How can I contribute to R?</a>,Previous:<a rel=previous href="#How%20can%20I%20create%20an%20R%20package%3f">How can I create an R package?</a>,Up:<a rel=up href="#R%20Add-On%20Packages">R Add-On Packages</a><br><h2>5.6 How can I contribute to R?</h2><p>R is in active development and there is always a risk of bugs creepingin. Also, the developers do not have access to all possible machinescapable of running R. So, simply using it and communicating problems iscertainly of great value.<p>One place where functionality is still missing is the modeling softwareas described in "Statistical Models in S" (see <a href="#What%20is%20S%3f">What is S?</a>);Generalized Additive Models (<strong>gam</strong>) and some of the nonlinearmodeling code are not there yet.<p>See also the <code>PROJECTS</code> file in the top level R source directory.<p>Many (more) of the packages available at the Statlib S Repository mightbe worth porting to R.<p>If you are interested in working on any of these projects, please notify<a href="mailto:Kurt.Hornik@r-project.org">Kurt Hornik</a>.<p><hr>Node:<a name="R%20and%20Emacs">R and Emacs</a>,Next:<a rel=next href="#R%20Miscellania">R Miscellania</a>,Previous:<a rel=previous href="#R%20Add-On%20Packages">R Add-On Packages</a>,Up:<a rel=up href="#Top">Top</a><br><h1>6 R and Emacs</h1><ul><li><a href="#Is%20there%20Emacs%20support%20for%20R%3f">Is there Emacs support for R?</a>:<li><a href="#Should%20I%20run%20R%20from%20within%20Emacs%3f">Should I run R from within Emacs?</a>:</ul><p><hr>Node:<a name="Is%20there%20Emacs%20support%20for%20R%3f">Is there Emacs support for R?</a>,Next:<a rel=next href="#Should%20I%20run%20R%20from%20within%20Emacs%3f">Should I run R from within Emacs?</a>,Previous:<a rel=previous href="#R%20and%20Emacs">R and Emacs</a>,Up:<a rel=up href="#R%20and%20Emacs">R and Emacs</a><br><h2>6.1 Is there Emacs support for R?</h2><p>There is an Emacs package which provides a standard interface betweenstatistical programs and statistical processes called ESS ("EmacsSpeaks Statistics"). It is intended to provide assistance forinteractive statistical programming and data analysis. Languagessupported include: S dialects (S 3/4, S-PLUS 3.x/4.x/5.x, and R),LispStat dialects (XLispStat, ViSta), SAS, Stata, SPSS dialects (SPSS,Fiasco) and SCA.<p>ESS grew out of the desire for bug fixes and extensions to S-mode 4.8(which was a GNU Emacs interface to S/S-PLUS version 3 only). Thecurrent set of developers desired support for XEmacs, R, S4, and MSWindows. In addition, with new modes being developed for R, Stata, andSAS, it was felt a unifying interface and framework for the userinterface, would benefit both the user and the developer, by helpingboth groups conform to standard Emacs usage. The end result is anincrease in efficiency for statistical programming and data analysis,over the usual tools.<p>R support contains code for editing R source code (syntactic indentationand highlighting of source code, partial evaluations of code, loadingand error-checking of code, and source code revision maintenance) anddocumentation (syntactic indentation and highlighting of source code,sending Examples to running ESS process, and previewing), interactingwith an inferior R process from within Emacs (command-line editing,searchable command history, command-line completion of R object and filenames, quick access to object and search lists, transcript recording,and an interface to the help system), and transcript manipulation(recording and saving transcript files, manipulating and editing savedtranscripts, and re-evaluating commands from transcript files).<p>The latest versions of ESS are available from<a href="http://ess.stat.wisc.edu/pub/ESS/">http://ess.stat.wisc.edu/pub/ESS/</a> or<a href="ftp://ess.stat.wisc.edu/pub/ESS/">ftp://ess.stat.wisc.edu/pub/ESS/</a>, or via CRAN. The HTML versionof the documentation can be found at <a href="http://stat.ethz.ch/ESS/">http://stat.ethz.ch/ESS/</a>.<p>ESS comes with detailed installation instructions.<p>For help with ESS, send email to <a href="mailto:ESS-help@stat.ethz.ch">ESS-help@stat.ethz.ch</a>.<p>Please send bug reports and suggestions on ESS to<a href="mailto:ESS-bugs@stat.math.ethz.ch">ESS-bugs@stat.math.ethz.ch</a>. The easiest way to do this from iswithin Emacs by typing <kbd>M-x ess-submit-bug-report</kbd> or using the[ESS] or [iESS] pulldown menus.<p><hr>Node:<a name="Should%20I%20run%20R%20from%20within%20Emacs%3f">Should I run R from within Emacs?</a>,Previous:<a rel=previous href="#Is%20there%20Emacs%20support%20for%20R%3f">Is there Emacs support for R?</a>,Up:<a rel=up href="#R%20and%20Emacs">R and Emacs</a><br><h2>6.2 Should I run R from within Emacs?</h2><p>Yes, <em>definitely</em>. Inferior R mode provides a readline/historymechanism, object name completion, and syntax-based highlighting of theinteraction buffer using Font Lock mode, as well as a very convenientinterface to the R help system.<p>Of course, it also integrates nicely with the mechanisms for editing Rsource using Emacs. One can write code in one Emacs buffer and sendwhole or parts of it for execution to R; this is helpful for both dataanalysis and programming. One can also seamlessly integrate with arevision control system, in order to maintain a log of changes in yourprograms and data, as well as to allow for the retrieval of pastversions of the code.<p>In addition, it allows you to keep a record of your session, which canalso be used for error recovery through the use of the transcript mode.<p>To specify command line arguments for the inferior R process, use<kbd>C-u M-x R</kbd> for starting R. This prompts you for the arguments; inparticular, you can increase the memory size this way (see <a href="#Why%20does%20R%20run%20out%20of%20memory%3f">Why does R run out of memory?</a>).<p><hr>Node:<a name="R%20Miscellania">R Miscellania</a>,Next:<a rel=next href="#R%20Programming">R Programming</a>,Previous:<a rel=previous href="#R%20and%20Emacs">R and Emacs</a>,Up:<a rel=up href="#Top">Top</a><br><h1>7 R Miscellania</h1><ul><li><a href="#Why%20does%20R%20run%20out%20of%20memory%3f">Why does R run out of memory?</a>:<li><a href="#Why%20does%20sourcing%20a%20correct%20file%20fail%3f">Why does sourcing a correct file fail?</a>:<li><a href="#How%20can%20I%20set%20components%20of%20a%20list%20to%20NULL%3f">How can I set components of a list to NULL?</a>:<li><a href="#How%20can%20I%20save%20my%20workspace%3f">How can I save my workspace?</a>:<li><a href="#How%20can%20I%20clean%20up%20my%20workspace%3f">How can I clean up my workspace?</a>:<li><a href="#How%20can%20I%20get%20eval()%20and%20D()%20to%20work%3f">How can I get eval() and D() to work?</a>:<li><a href="#Why%20do%20my%20matrices%20lose%20dimensions%3f">Why do my matrices lose dimensions?</a>:<li><a href="#How%20does%20autoloading%20work%3f">How does autoloading work?</a>:<li><a href="#How%20should%20I%20set%20options%3f">How should I set options?</a>:<li><a href="#How%20do%20file%20names%20work%20in%20Windows%3f">How do file names work in Windows?</a>:<li><a href="#Why%20does%20plotting%20give%20a%20color%20allocation%20error%3f">Why does plotting give a color allocation error?</a>:<li><a href="#Is%20R%20Y2K-compliant%3f">Is R Y2K-compliant?</a>:</ul><p><hr>Node:<a name="Why%20does%20R%20run%20out%20of%20memory%3f">Why does R run out of memory?</a>,Next:<a rel=next href="#Why%20does%20sourcing%20a%20correct%20file%20fail%3f">Why does sourcing a correct file fail?</a>,Previous:<a rel=previous href="#R%20Miscellania">R Miscellania</a>,Up:<a rel=up href="#R%20Miscellania">R Miscellania</a><br><h2>7.1 Why does R run out of memory?</h2><p>R (currently) uses a <em>static</em> memory model. This means that whenit starts up, it asks the operating system to reserve a fixed amount ofmemory for it. The size of this chunk cannot be changed subsequently.Hence, it can happen that not enough memory was allocated, e.g., whentrying to read large data sets into R.<p>In these cases, you should restart R with more memory available, usingthe command line options <code>--nsize</code> and <code>--vsize</code>. Tounderstand these options, one needs to know that R maintains separateareas for fixed and variable sized objects. The first of these isallocated as an array of "cons cells" (Lisp programmers will know whatthey are, others may think of them as the building blocks of thelanguage itself, parse trees, etc.), and the second are thrown on a"heap". The <code>--nsize</code> option can be used to specify the numberof cons cells which R is to use (the default is 250000), and the<code>--vsize</code> option to specify the size of the vector heap in bytes(the default is 6 MB). Boths options must either be integers orintegers ending with <code>M</code>, <code>K</code>, or <code>k</code> meaning `Mega'(2^20), (computer) `Kilo' (2^10), or regular `kilo' (1000).<p>E.g., to read in a table of 5000 observations on 40 numeric variables,<code>R --vsize 6M</code> should do (which currently is the default).<p>Note that the information on where to find vectors and strings on theheap is stored using cons cells. Thus, it may also be necessary toallocate more space for cons cells in order to perform computations withvery "large" variable-size objects.<p>You can find out the current memory consumption (the proportion of heapand cons cells used) by typing <kbd>gc()</kbd> at the R prompt. This mayhelp you in finding out whether to increase <code>--vsize</code> or<code>--nsize</code>. Note that following <kbd>gcinfo(TRUE)</kbd>, automaticgarbage collection always prints memory use statistics.<p>As of version 0.62.3, R will tell you whether you ran out of cons orheap memory.<p>The defaults for <code>--nsize</code> and <code>--vsize</code> can be changed bysetting the environment variables <code>R_NSIZE</code> and <code>R_VSIZE</code>respectively, perhaps most conveniently on Unix in the R environmentfile (<code>~/.Renviron</code> by default).<p>When using <code>read.table()</code>, the memory requirements are in facthigher than anticipated, because the file is first read in as one longstring which is then split again. Use <code>scan()</code> if possible incase you run out of memory when reading in a large table.<p><hr>Node:<a name="Why%20does%20sourcing%20a%20correct%20file%20fail%3f">Why does sourcing a correct file fail?</a>,Next:<a rel=next href="#How%20can%20I%20set%20components%20of%20a%20list%20to%20NULL%3f">How can I set components of a list to NULL?</a>,Previous:<a rel=previous href="#Why%20does%20R%20run%20out%20of%20memory%3f">Why does R run out of memory?</a>,Up:<a rel=up href="#R%20Miscellania">R Miscellania</a><br><h2>7.2 Why does sourcing a correct file fail?</h2><p>R sometimes has problems parsing a file which does not end in a newline.This can happen for example when Emacs is used for editing the file and<code>next-line-add-newlines</code> is set to <code>nil</code>. To avoid theproblem, either set <code>require-final-newline</code> to a non-<code>nil</code>value in one of your Emacs startup files, or make sure R-mode (see <a href="#Is%20there%20Emacs%20support%20for%20R%3f">Is there Emacs support for R?</a>) is used for editing R source files (whichlocally ensures this setting).<p>Earlier R versions had a similar problem when reading in data files, butthis should have been taken care of now.<p><hr>Node:<a name="How%20can%20I%20set%20components%20of%20a%20list%20to%20NULL%3f">How can I set components of a list to NULL?</a>,Next:<a rel=next href="#How%20can%20I%20save%20my%20workspace%3f">How can I save my workspace?</a>,Previous:<a rel=previous href="#Why%20does%20sourcing%20a%20correct%20file%20fail%3f">Why does sourcing a correct file fail?</a>,Up:<a rel=up href="#R%20Miscellania">R Miscellania</a><br><h2>7.3 How can I set components of a list to NULL?</h2><p>You can use<pre>x[i] <- list(NULL)</pre><p>to set component <code>i</code> of the list <code>x</code> to <code>NULL</code>, similarlyfor named components. Do not set <code>x[i]</code> or <code>x[[i]]</code> to<code>NULL</code>, because this will remove the corresponding component fromthe list.<p>For dropping the row names of a matrix <code>x</code>, it may be easier to use<code>rownames(x) <- NULL</code>, similarly for column names.<p><hr>Node:<a name="How%20can%20I%20save%20my%20workspace%3f">How can I save my workspace?</a>,Next:<a rel=next href="#How%20can%20I%20clean%20up%20my%20workspace%3f">How can I clean up my workspace?</a>,Previous:<a rel=previous href="#How%20can%20I%20set%20components%20of%20a%20list%20to%20NULL%3f">How can I set components of a list to NULL?</a>,Up:<a rel=up href="#R%20Miscellania">R Miscellania</a><br><h2>7.4 How can I save my workspace?</h2><p><code>save.image()</code> saves the objects in the user's <code>.GlobalEnv</code> tothe file <code>.RData</code> in the R startup directory. (This is also whathappens after <kbd>q("yes")</kbd>.) Using <code>save.image(<var>file</var>)</code> onecan save the image under a different name.<p><hr>Node:<a name="How%20can%20I%20clean%20up%20my%20workspace%3f">How can I clean up my workspace?</a>,Next:<a rel=next href="#How%20can%20I%20get%20eval()%20and%20D()%20to%20work%3f">How can I get eval() and D() to work?</a>,Previous:<a rel=previous href="#How%20can%20I%20save%20my%20workspace%3f">How can I save my workspace?</a>,Up:<a rel=up href="#R%20Miscellania">R Miscellania</a><br><h2>7.5 How can I clean up my workspace?</h2><p>To remove all objects in the currently active environment (typically<code>.GlobalEnv</code>), you can do<pre>rm(list = ls(all = TRUE))</pre><p>(Without <code>all = TRUE</code>, only the objects with names not startingwith a `.' are removed.)<p><hr>Node:<a name="How%20can%20I%20get%20eval()%20and%20D()%20to%20work%3f">How can I get eval() and D() to work?</a>,Next:<a rel=next href="#Why%20do%20my%20matrices%20lose%20dimensions%3f">Why do my matrices lose dimensions?</a>,Previous:<a rel=previous href="#How%20can%20I%20clean%20up%20my%20workspace%3f">How can I clean up my workspace?</a>,Up:<a rel=up href="#R%20Miscellania">R Miscellania</a><br><h2>7.6 How can I get eval() and D() to work?</h2><p>Strange things will happen if you use <code>eval(print(x), envir = e)</code>or <code>D(x^2, "x")</code>. The first one will either tell you that"<code>x</code>" is not found, or print the value of the wrong <code>x</code>.The other one will likely return zero if <code>x</code> exists, and an errorotherwise.<p>This is because in both cases, the first argument is evaluated in thecalling environment first. The result (which should be an object ofmode `expression' or `call') is then evaluated or differentiated. Whatyou (most likely) really want is obtained by "quoting" the firstargument upon surrounding it with <code>expression()</code>. For example,<pre>R> D(expression(x^2), "x")2 * x</pre><p>Although this behavior may initially seem to be rather strange, isperfectly logical. The "intuitive" behavior could easily beimplemented, but problems would arise whenever the expression iscontained in a variable, passed as a parameter, or is the result of afunction call. Consider for instance the semantics in cases like<pre>D2 <- function(e, n) D(D(e, n), n)</pre><p>or<pre>g <- function(y) eval(substitute(y), sys.frame(sys.parent(n = 2)))g(a * b)</pre><p>See the help pages for more examples.<p><hr>Node:<a name="Why%20do%20my%20matrices%20lose%20dimensions%3f">Why do my matrices lose dimensions?</a>,Next:<a rel=next href="#How%20does%20autoloading%20work%3f">How does autoloading work?</a>,Previous:<a rel=previous href="#How%20can%20I%20get%20eval()%20and%20D()%20to%20work%3f">How can I get eval() and D() to work?</a>,Up:<a rel=up href="#R%20Miscellania">R Miscellania</a><br><h2>7.7 Why do my matrices lose dimensions?</h2><p>When a matrix with a single row or column is created by a subscriptingoperation, e.g., <code>row <- mat[2, ]</code>, it is by default turned into avector. In a similar way if an array with dimension, say, 2 x 3 x 1 x 4 is created by subscripting it will be coerced into a 2 x 3 x 4array, losing the unnecessary dimension. After much discussion this hasbeen determined to be a <em>feature</em>.<p>To prevent this happening, add the option <code>drop = FALSE</code> to thesubscripting. For example,<pre>rowmatrix <- mat[2, , drop = FALSE] # creates a row matrixcolmatrix <- mat[, 2, drop = FALSE] # creates a column matrixa <- b[1, 1, 1, drop = FALSE] # creates a 1 x 1 x 1 array</pre><p>The <code>drop = FALSE</code> option should be used defensively whenprogramming. For example, the statement<pre>somerows <- mat[index, ]</pre><p>will return a vector rather than a matrix if <code>index</code> happens tohave length 1, causing errors later in the code. It should probably berewritten as<pre>somerows <- mat[index, , drop = FALSE]</pre><p><hr>Node:<a name="How%20does%20autoloading%20work%3f">How does autoloading work?</a>,Next:<a rel=next href="#How%20should%20I%20set%20options%3f">How should I set options?</a>,Previous:<a rel=previous href="#Why%20do%20my%20matrices%20lose%20dimensions%3f">Why do my matrices lose dimensions?</a>,Up:<a rel=up href="#R%20Miscellania">R Miscellania</a><br><h2>7.8 How does autoloading work?</h2><p>R has a special environment called <code>.AutoloadEnv</code>. Using<kbd>autoload(<var>name</var>, <var>pkg</var>)</kbd>, where <var>name</var> and<var>pkg</var> are strings giving the names of an object and the packagecontaining it, stores some information in this environment. When Rtries to evaluate <var>name</var>, it loads the corresponding package<var>pkg</var> and reevaluates <var>name</var> in the new package'senvironment.<p>Using this mechanism makes R behave as if the package was loaded, butdoes not occupy memory (yet).<p>See the help page for <code>autoload()</code> for a very nice example.<p><hr>Node:<a name="How%20should%20I%20set%20options%3f">How should I set options?</a>,Next:<a rel=next href="#How%20do%20file%20names%20work%20in%20Windows%3f">How do file names work in Windows?</a>,Previous:<a rel=previous href="#How%20does%20autoloading%20work%3f">How does autoloading work?</a>,Up:<a rel=up href="#R%20Miscellania">R Miscellania</a><br><h2>7.9 How should I set options?</h2><p>The function <code>options()</code> allows setting and examining a variety ofglobal "options" which affect the way in which R computes and displaysits results. The variable <code>.Options</code> holds the current values ofthese options, but should never directly be assigned to unless you wantto drive yourself crazy--simply pretend that it is a "read-only"variable.<p>For example, given<pre>test1 <- function(x = pi, dig = 3) {oo <- options(digits = dig); on.exit(options(oo));cat(.Options$digits, x, "\n")}test2 <- function(x = pi, dig = 3) {.Options$digits <- digcat(.Options$digits, x, "\n")}</pre><p>we obtain:<pre>R> test1()3 3.14R> test2()3 3.141593</pre><p>What is really used is the <em>global</em> value of <code>.Options</code>, andusing <kbd>options(OPT = VAL)</kbd> correctly updates it. Local copies of<code>.Options</code>, either in <code>.GlobalEnv</code> or in a functionenvironment (frame), are just silently disregarded.<p><hr>Node:<a name="How%20do%20file%20names%20work%20in%20Windows%3f">How do file names work in Windows?</a>,Next:<a rel=next href="#Why%20does%20plotting%20give%20a%20color%20allocation%20error%3f">Why does plotting give a color allocation error?</a>,Previous:<a rel=previous href="#How%20should%20I%20set%20options%3f">How should I set options?</a>,Up:<a rel=up href="#R%20Miscellania">R Miscellania</a><br><h2>7.10 How do file names work in Windows?</h2><p>As R uses C-style string handling, <code>\</code> is treated as an escapecharacter, so that for example one can enter a newline as <code>\n</code>.When you really need a <code>\</code>, you have to escape it with another<code>\</code>.<p>Thus, in filenames use something like <code>"c:\\data\\money.dat"</code>. Youcan also replace <code>\</code> by <code>/</code> (<code>"c:/data/money.dat"</code>).<p><hr>Node:<a name="Why%20does%20plotting%20give%20a%20color%20allocation%20error%3f">Why does plotting give a color allocation error?</a>,Next:<a rel=next href="#Is%20R%20Y2K-compliant%3f">Is R Y2K-compliant?</a>,Previous:<a rel=previous href="#How%20do%20file%20names%20work%20in%20Windows%3f">How do file names work in Windows?</a>,Up:<a rel=up href="#R%20Miscellania">R Miscellania</a><br><h2>7.11 Why does plotting give a color allocation error?</h2><p>Sometimes plotting, e.g., when running <code>demo(image)</code>, results in"Error: color allocation error". This is an X problem, and onlyindirectly related to R. It occurs when applications started prior to Rhave used all the available colors. (How many colors are availabledepends on the X configuration; sometimes only 256 colors can be used.)<p>One application which is notorious for "eating" colors is Netscape.If the problem occurs when Netscape is running, try (re)starting it witheither the <code>-no-install</code> (to use the default colormap) or the<code>-install</code> (to install a private colormap) option.<p>You could also set the <code>colortype</code> of <code>X11()</code> to `pseudo.cube'rather than the default `pseudo'. See the help page for <code>X11()</code>for more information.<p><hr>Node:<a name="Is%20R%20Y2K-compliant%3f">Is R Y2K-compliant?</a>,Previous:<a rel=previous href="#Why%20does%20plotting%20give%20a%20color%20allocation%20error%3f">Why does plotting give a color allocation error?</a>,Up:<a rel=up href="#R%20Miscellania">R Miscellania</a><br><h2>7.12 Is R Y2K-compliant?</h2><p>We expect R to be Y2K compliant when compiled and run on a Y2K compliantsystem. In particular R does not internally represent or manipulatedates as two-digit quantities. However, no guarantee of Y2K complianceis provided for R. R is free software and comes with <em>no warrantywhatsover</em>.<p>R, like any other programming language, can be used to write programsand manipulate data in ways that are not Y2K compliant.<p><hr>Node:<a name="R%20Programming">R Programming</a>,Next:<a rel=next href="#R%20Bugs">R Bugs</a>,Previous:<a rel=previous href="#R%20Miscellania">R Miscellania</a>,Up:<a rel=up href="#Top">Top</a><br><h1>8 R Programming</h1><ul><li><a href="#How%20should%20I%20write%20summary%20methods%3f">How should I write summary methods?</a>:<li><a href="#How%20can%20I%20debug%20dynamically%20loaded%20code%3f">How can I debug dynamically loaded code?</a>:<li><a href="#How%20can%20I%20inspect%20R%20objects%20when%20debugging%3f">How can I inspect R objects when debugging?</a>:</ul><p><hr>Node:<a name="How%20should%20I%20write%20summary%20methods%3f">How should I write summary methods?</a>,Next:<a rel=next href="#How%20can%20I%20debug%20dynamically%20loaded%20code%3f">How can I debug dynamically loaded code?</a>,Previous:<a rel=previous href="#R%20Programming">R Programming</a>,Up:<a rel=up href="#R%20Programming">R Programming</a><br><h2>8.1 How should I write summary methods?</h2><p>Suppose you want to provide a summary method for class <code>foo</code>. Then<code>summary.foo()</code> should not print anything, but return an object ofclass <code>summary.foo</code>, <em>and</em> you should write a method<code>print.summary.foo()</code> which nicely prints the summary informationand invisibly returns its object. This approach is preferred overhaving <code>summary.foo()</code> print summary information and returnsomething useful, as sometimes you need to grab something computed by<code>summary()</code> inside a function or similar. In such cases you don'twant anything printed.<p><hr>Node:<a name="How%20can%20I%20debug%20dynamically%20loaded%20code%3f">How can I debug dynamically loaded code?</a>,Next:<a rel=next href="#How%20can%20I%20inspect%20R%20objects%20when%20debugging%3f">How can I inspect R objects when debugging?</a>,Previous:<a rel=previous href="#How%20should%20I%20write%20summary%20methods%3f">How should I write summary methods?</a>,Up:<a rel=up href="#R%20Programming">R Programming</a><br><h2>8.2 How can I debug dynamically loaded code?</h2><p>According to Doug Bates, the secret of symbolic debugging of dynamicallyloaded code is to<ul><li>Call the debugger on the R executable. In the shell, you can e.g. use<kbd>R -d gdb</kbd>; see below for debugging from within Emacs.<li>Start the R program.<li>At the R prompt, use <code>dyn.load()</code> to load your library.<li>Send an interrupt signal. Inside of GUD mode in Emacs, you send<kbd>C-c C-c</kbd>. This will put you back to the debugger prompt.<li>Set the breakpoints in your code.<li>Continue execution of R by typing <kbd>signal 0<RET></kbd>.</ul><p>When using GUD mode for debugging from within Emacs, you may find itmost convenient to use the directory with your code in it as the currentworking directory and then make a symbolic link from that directory tothe R executable. That way <code>.gdbinit</code> can stay in the directorywith the code and be used to set up the environment and the search pathsfor the source, e.g. as follows:<pre>set env R_HOME /opt/Rset env R_PAPERSIZE letterset env R_PRINTCMD lprdir /opt/R/src/appldir /opt/R/src/maindir /opt/R/src/nmathdir /opt/R/src/unix</pre><p><hr>Node:<a name="How%20can%20I%20inspect%20R%20objects%20when%20debugging%3f">How can I inspect R objects when debugging?</a>,Previous:<a rel=previous href="#How%20can%20I%20debug%20dynamically%20loaded%20code%3f">How can I debug dynamically loaded code?</a>,Up:<a rel=up href="#R%20Programming">R Programming</a><br><h2>8.3 How can I inspect R objects when debugging?</h2><p>In the C implementation underlying R, all objects are so-called SEXPs(from Lisp's "S-expressions" which comes from "symbolicexpression"), which are pointers to data structures called SEXPRECs.(See the file <code>src/include/Rinternals.h</code> in the R sources for thedefinition of the SEXPREC type.) For example, let<pre>R> DF <- data.frame(a = 1:3, b = 4:6)</pre><p>By setting a breakpoint at <code>do_get</code> and typing <kbd>get("DF")</kbd> atthe R prompt, one can find out the address in memory of <code>DF</code>, e.g.<pre>Value returned is $1 = (SEXPREC *) 0x40583e1c(gdb) p *$1$2 = {sxpinfo = {type = 19, obj = 1, named = 1, gp = 0,mark = 0, debug = 0, trace = 0, = 0},attrib = 0x40583e80,u = {vecsxp = {length = 2,type = {c = 0x40634700 "0>X@D>X@0>X@", i = 0x40634700,f = 0x40634700, z = 0x40634700, s = 0x40634700},truelength = 1075851272,},primsxp = {offset = 2},symsxp = {pname = 0x2, value = 0x40634700, internal = 0x40203008},listsxp = {carval = 0x2, cdrval = 0x40634700, tagval = 0x40203008},envsxp = {frame = 0x2, enclos = 0x40634700},closxp = {formals = 0x2, body = 0x40634700, env = 0x40203008},promsxp = {value = 0x2, expr = 0x40634700, env = 0x40203008}}}</pre><p>(Debugger output reformatted for better legibility).<p>Using <code>PrintValue()</code> one can "inspect" the values of the variouselements of the SEXP, e.g.,<pre>(gdb) p PrintValue($1->attrib)$names[1] "a" "b"$row.names[1] "1" "2" "3"$class[1] "data.frame"$3 = void</pre><p>(Make sure, however, to use <code>PrintValue()</code> on SEXPs with the `obj'bit turned on only.)<p>To find out where exactly the corresponding information is stored, oneneeds to go "deeper":<pre>(gdb) set $a = $1->attrib(gdb) p $a->u.listsxp.tagval->u.symsxp.pname->u.vecsxp.type.c$4 = 0x405d40e8 "names"(gdb) p $a->u.listsxp.carval->u.vecsxp.type.s[1]->u.vecsxp.type.c$5 = 0x40634378 "b"(gdb) p $1->u.vecsxp.type.s[0]->u.vecsxp.type.i[0]$6 = 1(gdb) p $1->u.vecsxp.type.s[1]->u.vecsxp.type.i[1]$7 = 5</pre><p><hr>Node:<a name="R%20Bugs">R Bugs</a>,Next:<a rel=next href="#Acknowledgments">Acknowledgments</a>,Previous:<a rel=previous href="#R%20Programming">R Programming</a>,Up:<a rel=up href="#Top">Top</a><br><h1>9 R Bugs</h1><ul><li><a href="#What%20is%20a%20bug%3f">What is a bug?</a>:<li><a href="#How%20to%20report%20a%20bug">How to report a bug</a>:</ul><p><hr>Node:<a name="What%20is%20a%20bug%3f">What is a bug?</a>,Next:<a rel=next href="#How%20to%20report%20a%20bug">How to report a bug</a>,Previous:<a rel=previous href="#R%20Bugs">R Bugs</a>,Up:<a rel=up href="#R%20Bugs">R Bugs</a><br><h2>9.1 What is a bug?</h2><p>If R executes an illegal instruction, or dies with an operating systemerror message that indicates a problem in the program (as opposed tosomething like "disk full"), then it is certainly a bug. If you call<code>.Internal()</code>, <code>.External()</code>, <code>.C()</code> or <code>.Fortran()</code>yourself (or in a function you wrote), you can always crash R by usingwrong argument types (modes). This is not a bug.<p>Taking forever to complete a command can be a bug, but you must makecertain that it was really R's fault. Some commands simply take a longtime. If the input was such that you <em>know</em> it should have beenprocessed quickly, report a bug. If you don't know whether the commandshould take a long time, find out by looking in the manual or by askingfor assistance.<p>If a command you are familiar with causes an R error message in a casewhere its usual definition ought to be reasonable, it is probably abug. If a command does the wrong thing, that is a bug. But be sure youknow for certain what it ought to have done. If you aren't familiarwith the command, or don't know for certain how the command is supposedto work, then it might actually be working right. Rather than jumpingto conclusions, show the problem to someone who knows for certain.<p>Finally, a command's intended definition may not be best for statisticalanalysis. This is a very important sort of problem, but it is also amatter of judgment. Also, it is easy to come to such a conclusion outof ignorance of some of the existing features. It is probably best notto complain about such a problem until you have checked thedocumentation in the usual ways, feel confident that you understand it,and know for certain that what you want is not available. If you arenot sure what the command is supposed to do after a careful reading ofthe manual this indicates a bug in the manual. The manual's job is tomake everything clear. It is just as important to report documentationbugs as program bugs. However, we know that the introductorydocumentation is seriously inadequate, so you don't need to report this.<p>If the online argument list of a function disagrees with the manual, oneof them must be wrong, so report the bug.<p><hr>Node:<a name="How%20to%20report%20a%20bug">How to report a bug</a>,Previous:<a rel=previous href="#What%20is%20a%20bug%3f">What is a bug?</a>,Up:<a rel=up href="#R%20Bugs">R Bugs</a><br><h2>9.2 How to report a bug</h2><p>When you decide that there is a bug, it is important to report it and toreport it in a way which is useful. What is most useful is an exactdescription of what commands you type, starting with the shell commandto run R, until the problem happens. Always include the version of R,machine, and operating system that you are using; type <kbd>version</kbd> inR to print this.<p>The most important principle in reporting a bug is to report<em>facts</em>, not hypotheses or categorizations. It is always easier toreport the facts, but people seem to prefer to strain to positexplanations and report them instead. If the explanations are based onguesses about how R is implemented, they will be useless; others willhave to try to figure out what the facts must have been to lead to suchspeculations. Sometimes this is impossible. But in any case, it isunnecessary work for the ones trying to fix the problem.<p>For example, suppose that on a data set which you know to be quite largethe command<pre>R> data.frame(x, y, z, monday, tuesday)</pre><p>never returns. Do not report that <code>data.frame()</code> fails for largedata sets. Perhaps it fails when a variable name is a day of the week.If this is so then when others got your report they would try out the<code>data.frame()</code> command on a large data set, probably with no day ofthe week variable name, and not see any problem. There is no way in theworld that others could guess that they should try a day of the weekvariable name.<p>Or perhaps the command fails because the last command you used was amethod for <code>"["()</code> that had a bug causing R's internal datastructures to be corrupted and making the <code>data.frame()</code> commandfail from then on. This is why others need to know what other commandsyou have typed (or read from your startup file).<p>It is very useful to try and find simple examples that produceapparently the same bug, and somewhat useful to find simple examplesthat might be expected to produce the bug but actually do not. If youwant to debug the problem and find exactly what caused it, that iswonderful. You should still report the facts as well as any explanationsor solutions. Please include an example that reproduces the problem,preferably the simplest one you have found.<p>Invoking R with the <code>--vanilla</code> option may help in isolating abug. This ensures that the site profile and saved data files are notread.<p>On Unix systems a bug report can be generated using the function<code>bug.report()</code>. This automatically includes the version informationand sends the bug to the correct address. Alternatively the bug reportcan be emailed to <a href="mailto:r-bugs@lists.r-project.org">r-bugs@lists.r-project.org</a> or submitted to the Webpage at <a href="http://bugs.r-project.org">http://bugs.r-project.org</a>.<p>Bug reports on contributed packages should perhaps be sent to thepackage maintainer rather than to r-bugs.<p><hr>Node:<a name="Acknowledgments">Acknowledgments</a>,Previous:<a rel=previous href="#R%20Bugs">R Bugs</a>,Up:<a rel=up href="#Top">Top</a><br><h1>10 Acknowledgments</h1><p>Of course, many many thanks to Robert and Ross for the R system, and tothe package writers and porters for adding to it.<p>Special thanks go to Doug Bates, Peter Dalgaard, Paul Gilbert, FritzLeisch, Jim Lindsey, Thomas Lumley, Martin Maechler, Brian D. Ripley,Anthony Rossini, and Andreas Weingessel for their comments which helpedme improve this FAQ.<p>More to some soon <small>...</small></body></html>