HEX
Server: Apache/2.4.46 (Win64) OpenSSL/1.1.1j PHP/8.4.25
System: Windows NT DESKTOP-4TAV2RJ 10.0 build 19045 (Windows 10) AMD64
User: fred (0)
PHP: 8.4.25
Disabled: NONE
Upload Files
File: C:/Program Files/R/R-4.4.0/doc/manual/R-FAQ.html
<!DOCTYPE html>
<html>
<!-- Created by GNU Texinfo 7.1, https://www.gnu.org/software/texinfo/ -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>R FAQ</title>

<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="R FAQ">
<meta name="keywords" content="R FAQ">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="texi2any">
<meta name="viewport" content="width=device-width,initial-scale=1">

<link href="#Top" rel="start" title="Top">
<link href="#SEC_Contents" rel="contents" title="Table of Contents">
<link href="#Introduction" rel="next" title="Introduction">
<style type="text/css">
<!--
a.copiable-link {visibility: hidden; text-decoration: none; line-height: 0em}
div.display {margin-left: 3.2em}
div.example {margin-left: 3.2em}
kbd.kbd {font-style: oblique}
kbd.key {font-style: normal}
pre.display-preformatted {font-family: inherit}
span.r {font-family: initial; font-weight: normal; font-style: normal}
span:hover a.copiable-link {visibility: visible}
ul.mark-bullet {list-style-type: disc}
ul.toc-numbered-mark {list-style: none}
body {
    margin-left: 5%;
    margin-right: 5%;
}

h1 {             
    background: white;
    color: rgb(25%, 25%, 25%);
    font-family: monospace;
    font-size: xx-large;
    text-align: center;
}

h2 {
    background: white;
    color: rgb(40%, 40%, 40%);
    font-family: monospace;
    font-size: x-large;
    text-align: center;
}

h3 {
    background: white;
    color: rgb(40%, 40%, 40%);
    font-family: monospace;
    font-size: large;
}

h4 {
    background: white;
    color: rgb(40%, 40%, 40%);
    font-family: monospace;
}

span.samp {
    font-family: monospace;
}

span.command {
    font-family: monospace;
}

span.option {
    font-family: monospace;
}

span.file {
    font-family: monospace;
}

span.env {
    font-family: monospace;
}

ul {
    margin-top: 0.25ex;
    margin-bottom: 0.25ex;
}

li {
    margin-top: 0.25ex;
    margin-bottom: 0.25ex;
}

p {
    margin-top: 0.6ex;
    margin-bottom: 1.2ex;
}

/* hide top navigation bar in Texinfo >= 6.8 output */
#Top > .header, #Top > .nav-panel {
    display: none
}

-->
</style>


</head>

<body lang="en">




























<div class="top-level-extent" id="Top">
<div class="nav-panel">
<p>
Next: <a href="#Introduction" accesskey="n" rel="next">Introduction</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
</div>
<h1 class="top" id="R-FAQ"><span>R FAQ<a class="copiable-link" href="#R-FAQ"> &para;</a></span></h1>

<p>This document contains answers to some of the most frequently asked
questions about R.
</p>

<div class="element-contents" id="SEC_Contents">
<h2 class="contents-heading">Table of Contents</h2>

<div class="contents">

<ul class="toc-numbered-mark">
  <li><a id="toc-Introduction-1" href="#Introduction">1 Introduction</a>
  <ul class="toc-numbered-mark">
    <li><a id="toc-Legalese-1" href="#Legalese">1.1 Legalese</a></li>
    <li><a id="toc-Obtaining-this-document-1" href="#Obtaining-this-document">1.2 Obtaining this document</a></li>
    <li><a id="toc-Citing-this-document-1" href="#Citing-this-document">1.3 Citing this document</a></li>
    <li><a id="toc-Notation-1" href="#Notation">1.4 Notation</a></li>
    <li><a id="toc-Feedback-1" href="#Feedback">1.5 Feedback</a></li>
  </ul></li>
  <li><a id="toc-R-Basics-1" href="#R-Basics">2 R Basics</a>
  <ul class="toc-numbered-mark">
    <li><a id="toc-What-is-R_003f-1" href="#What-is-R_003f">2.1 What is R?</a></li>
    <li><a id="toc-What-machines-does-R-run-on_003f-1" href="#What-machines-does-R-run-on_003f">2.2 What machines does R run on?</a></li>
    <li><a id="toc-What-is-the-current-version-of-R_003f-1" href="#What-is-the-current-version-of-R_003f">2.3 What is the current version of R?</a></li>
    <li><a id="toc-How-can-R-be-obtained_003f-1" href="#How-can-R-be-obtained_003f">2.4 How can R be obtained?</a></li>
    <li><a id="toc-How-can-R-be-installed_003f-1" href="#How-can-R-be-installed_003f">2.5 How can R be installed?</a>
    <ul class="toc-numbered-mark">
      <li><a id="toc-How-can-R-be-installed-_0028Unix_002dlike_0029-1" href="#How-can-R-be-installed-_0028Unix_002dlike_0029">2.5.1 How can R be installed (Unix-like)</a></li>
      <li><a id="toc-How-can-R-be-installed-_0028Windows_0029-1" href="#How-can-R-be-installed-_0028Windows_0029">2.5.2 How can R be installed (Windows)</a></li>
      <li><a id="toc-How-can-R-be-installed-_0028Mac_0029-1" href="#How-can-R-be-installed-_0028Mac_0029">2.5.3 How can R be installed (Mac)</a></li>
    </ul></li>
    <li><a id="toc-Are-there-Unix_002dlike-binaries-for-R_003f-1" href="#Are-there-Unix_002dlike-binaries-for-R_003f">2.6 Are there Unix-like binaries for R?</a></li>
    <li><a id="toc-What-documentation-exists-for-R_003f-1" href="#What-documentation-exists-for-R_003f">2.7 What documentation exists for R?</a></li>
    <li><a id="toc-Citing-R-1" href="#Citing-R">2.8 Citing R</a></li>
    <li><a id="toc-What-mailing-lists-exist-for-R_003f-1" href="#What-mailing-lists-exist-for-R_003f">2.9 What mailing lists exist for R?</a></li>
    <li><a id="toc-What-is-CRAN_003f-1" href="#What-is-CRAN_003f">2.10 What is <abbr class="acronym">CRAN</abbr>?</a></li>
    <li><a id="toc-Can-I-use-R-for-commercial-purposes_003f-1" href="#Can-I-use-R-for-commercial-purposes_003f">2.11 Can I use R for commercial purposes?</a></li>
    <li><a id="toc-Why-is-R-named-R_003f-1" href="#Why-is-R-named-R_003f">2.12 Why is R named R?</a></li>
    <li><a id="toc-What-is-the-R-Foundation_003f-1" href="#What-is-the-R-Foundation_003f">2.13 What is the R Foundation?</a></li>
    <li><a id="toc-What-is-R_002dForge_003f-1" href="#What-is-R_002dForge_003f">2.14 What is R-Forge?</a></li>
  </ul></li>
  <li><a id="toc-R-and-S-1" href="#R-and-S">3 R and S</a>
  <ul class="toc-numbered-mark">
    <li><a id="toc-What-is-S_003f-1" href="#What-is-S_003f">3.1 What is S?</a></li>
    <li><a id="toc-What-is-S_002dPlus_003f" href="#What-is-S_002dPLUS_003f">3.2 What is <small class="sc">S-PLUS</small>?</a></li>
    <li><a id="toc-What-are-the-differences-between-R-and-S_003f-1" href="#What-are-the-differences-between-R-and-S_003f">3.3 What are the differences between R and S?</a>
    <ul class="toc-numbered-mark">
      <li><a id="toc-Lexical-scoping-1" href="#Lexical-scoping">3.3.1 Lexical scoping</a></li>
      <li><a id="toc-Models-1" href="#Models">3.3.2 Models</a></li>
      <li><a id="toc-Others-1" href="#Others">3.3.3 Others</a></li>
    </ul></li>
    <li><a id="toc-Is-there-anything-R-can-do-that-S_002dPlus-cannot_003f" href="#Is-there-anything-R-can-do-that-S_002dPLUS-cannot_003f">3.4 Is there anything R can do that <small class="sc">S-PLUS</small> cannot?</a></li>
    <li><a id="toc-What-is-R_002dplus_003f-1" href="#What-is-R_002dplus_003f">3.5 What is R-plus?</a></li>
  </ul></li>
  <li><a id="toc-R-Web-Interfaces-1" href="#R-Web-Interfaces">4 R Web Interfaces</a></li>
  <li><a id="toc-R-Add_002dOn-Packages-1" href="#R-Add_002dOn-Packages">5 R Add-On Packages</a>
  <ul class="toc-numbered-mark">
    <li><a id="toc-Which-add_002don-packages-exist-for-R_003f-1" href="#Which-add_002don-packages-exist-for-R_003f">5.1 Which add-on packages exist for R?</a>
    <ul class="toc-numbered-mark">
      <li><a id="toc-Add_002don-packages-in-R-1" href="#Add_002don-packages-in-R">5.1.1 Add-on packages in R</a></li>
      <li><a id="toc-Add_002don-packages-from-CRAN-1" href="#Add_002don-packages-from-CRAN">5.1.2 Add-on packages from <abbr class="acronym">CRAN</abbr></a></li>
      <li><a id="toc-Add_002don-packages-from-Bioconductor-1" href="#Add_002don-packages-from-Bioconductor">5.1.3 Add-on packages from Bioconductor</a></li>
      <li><a id="toc-Other-add_002don-packages-1" href="#Other-add_002don-packages">5.1.4 Other add-on packages</a></li>
    </ul></li>
    <li><a id="toc-How-can-add_002don-packages-be-installed_003f-1" href="#How-can-add_002don-packages-be-installed_003f">5.2 How can add-on packages be installed?</a></li>
    <li><a id="toc-How-can-add_002don-packages-be-used_003f-1" href="#How-can-add_002don-packages-be-used_003f">5.3 How can add-on packages be used?</a></li>
    <li><a id="toc-How-can-add_002don-packages-be-removed_003f-1" href="#How-can-add_002don-packages-be-removed_003f">5.4 How can add-on packages be removed?</a></li>
    <li><a id="toc-How-can-I-create-an-R-package_003f-1" href="#How-can-I-create-an-R-package_003f">5.5 How can I create an R package?</a></li>
    <li><a id="toc-How-can-I-contribute-to-R_003f-1" href="#How-can-I-contribute-to-R_003f">5.6 How can I contribute to R?</a></li>
  </ul></li>
  <li><a id="toc-R-and-Emacs-1" href="#R-and-Emacs">6 R and Emacs</a>
  <ul class="toc-numbered-mark">
    <li><a id="toc-Is-there-Emacs-support-for-R_003f-1" href="#Is-there-Emacs-support-for-R_003f">6.1 Is there Emacs support for R?</a></li>
    <li><a id="toc-Should-I-run-R-from-within-Emacs_003f-1" href="#Should-I-run-R-from-within-Emacs_003f">6.2 Should I run R from within Emacs?</a></li>
    <li><a id="toc-Debugging-R-from-within-Emacs-1" href="#Debugging-R-from-within-Emacs">6.3 Debugging R from within Emacs</a></li>
  </ul></li>
  <li><a id="toc-R-Miscellanea-1" href="#R-Miscellanea">7 R Miscellanea</a>
  <ul class="toc-numbered-mark">
    <li><a id="toc-How-can-I-set-components-of-a-list-to-NULL_003f-1" href="#How-can-I-set-components-of-a-list-to-NULL_003f">7.1 How can I set components of a list to NULL?</a></li>
    <li><a id="toc-How-can-I-save-my-workspace_003f-1" href="#How-can-I-save-my-workspace_003f">7.2 How can I save my workspace?</a></li>
    <li><a id="toc-How-can-I-clean-up-my-workspace_003f-1" href="#How-can-I-clean-up-my-workspace_003f">7.3 How can I clean up my workspace?</a></li>
    <li><a id="toc-How-can-I-get-eval_0028_0029-and-D_0028_0029-to-work_003f-1" href="#How-can-I-get-eval_0028_0029-and-D_0028_0029-to-work_003f">7.4 How can I get <code class="code">eval()</code> and <code class="code">D()</code> to work?</a></li>
    <li><a id="toc-Why-do-my-matrices-lose-dimensions_003f-1" href="#Why-do-my-matrices-lose-dimensions_003f">7.5 Why do my matrices lose dimensions?</a></li>
    <li><a id="toc-How-does-autoloading-work_003f-1" href="#How-does-autoloading-work_003f">7.6 How does autoloading work?</a></li>
    <li><a id="toc-How-should-I-set-options_003f-1" href="#How-should-I-set-options_003f">7.7 How should I set options?</a></li>
    <li><a id="toc-How-do-file-names-work-in-Windows_003f-1" href="#How-do-file-names-work-in-Windows_003f">7.8 How do file names work in Windows?</a></li>
    <li><a id="toc-Why-does-plotting-give-a-color-allocation-error_003f-1" href="#Why-does-plotting-give-a-color-allocation-error_003f">7.9 Why does plotting give a color allocation error?</a></li>
    <li><a id="toc-How-do-I-convert-factors-to-numeric_003f-1" href="#How-do-I-convert-factors-to-numeric_003f">7.10 How do I convert factors to numeric?</a></li>
    <li><a id="toc-Are-Trellis-displays-implemented-in-R_003f-1" href="#Are-Trellis-displays-implemented-in-R_003f">7.11 Are Trellis displays implemented in R?</a></li>
    <li><a id="toc-What-are-the-enclosing-and-parent-environments_003f-1" href="#What-are-the-enclosing-and-parent-environments_003f">7.12 What are the enclosing and parent environments?</a></li>
    <li><a id="toc-How-can-I-substitute-into-a-plot-label_003f-1" href="#How-can-I-substitute-into-a-plot-label_003f">7.13 How can I substitute into a plot label?</a></li>
    <li><a id="toc-What-are-valid-names_003f-1" href="#What-are-valid-names_003f">7.14 What are valid names?</a></li>
    <li><a id="toc-Are-GAMs-implemented-in-R_003f-1" href="#Are-GAMs-implemented-in-R_003f">7.15 Are GAMs<!-- /@w --> implemented in R?</a></li>
    <li><a id="toc-Why-is-the-output-not-printed-when-I-source_0028_0029-a-file_003f-1" href="#Why-is-the-output-not-printed-when-I-source_0028_0029-a-file_003f">7.16 Why is the output not printed when I source() a file?</a></li>
    <li><a id="toc-Why-does-outer_0028_0029-behave-strangely-with-my-function_003f-1" href="#Why-does-outer_0028_0029-behave-strangely-with-my-function_003f">7.17 Why does outer() behave strangely with my function?</a></li>
    <li><a id="toc-Why-does-the-output-from-anova_0028_0029-depend-on-the-order-of-factors-in-the-model_003f-1" href="#Why-does-the-output-from-anova_0028_0029-depend-on-the-order-of-factors-in-the-model_003f">7.18 Why does the output from <code class="code">anova()</code> depend on the order of factors in the model?</a></li>
    <li><a id="toc-How-do-I-produce-PNG-graphics-in-batch-mode_003f-1" href="#How-do-I-produce-PNG-graphics-in-batch-mode_003f">7.19 How do I produce PNG graphics in batch mode?</a></li>
    <li><a id="toc-How-can-I-get-command-line-editing-to-work_003f-1" href="#How-can-I-get-command-line-editing-to-work_003f">7.20 How can I get command line editing to work?</a></li>
    <li><a id="toc-How-can-I-turn-a-string-into-a-variable_003f-1" href="#How-can-I-turn-a-string-into-a-variable_003f">7.21 How can I turn a string into a variable?</a></li>
    <li><a id="toc-Why-do-lattice_002ftrellis-graphics-not-work_003f-1" href="#Why-do-lattice_002ftrellis-graphics-not-work_003f">7.22 Why do lattice/trellis graphics not work?</a></li>
    <li><a id="toc-How-can-I-sort-the-rows-of-a-data-frame_003f-1" href="#How-can-I-sort-the-rows-of-a-data-frame_003f">7.23 How can I sort the rows of a data frame?</a></li>
    <li><a id="toc-Why-does-the-help_002estart_0028_0029-search-engine-not-work_003f-1" href="#Why-does-the-help_002estart_0028_0029-search-engine-not-work_003f">7.24 Why does the help.start() search engine not work?</a></li>
    <li><a id="toc-Why-did-my-_002eRprofile-stop-working-when-I-updated-R_003f-1" href="#Why-did-my-_002eRprofile-stop-working-when-I-updated-R_003f">7.25 Why did my .Rprofile stop working when I updated R?</a></li>
    <li><a id="toc-Where-have-all-the-methods-gone_003f-1" href="#Where-have-all-the-methods-gone_003f">7.26 Where have all the methods gone?</a></li>
    <li><a id="toc-How-can-I-create-rotated-axis-labels_003f-1" href="#How-can-I-create-rotated-axis-labels_003f">7.27 How can I create rotated axis labels?</a></li>
    <li><a id="toc-Why-is-read_002etable_0028_0029-so-inefficient_003f-1" href="#Why-is-read_002etable_0028_0029-so-inefficient_003f">7.28 Why is read.table() so inefficient?</a></li>
    <li><a id="toc-What-is-the-difference-between-package-and-library_003f-1" href="#What-is-the-difference-between-package-and-library_003f">7.29 What is the difference between package and library?</a></li>
    <li><a id="toc-I-installed-a-package-but-the-functions-are-not-there-1" href="#I-installed-a-package-but-the-functions-are-not-there">7.30 I installed a package but the functions are not there</a></li>
    <li><a id="toc-Why-doesn_0027t-R-think-these-numbers-are-equal_003f-1" href="#Why-doesn_0027t-R-think-these-numbers-are-equal_003f">7.31 Why doesn&rsquo;t R think these numbers are equal?</a></li>
    <li><a id="toc-How-can-I-capture-or-ignore-errors-in-a-long-simulation_003f-1" href="#How-can-I-capture-or-ignore-errors-in-a-long-simulation_003f">7.32 How can I capture or ignore errors in a long simulation?</a></li>
    <li><a id="toc-Why-are-powers-of-negative-numbers-wrong_003f-1" href="#Why-are-powers-of-negative-numbers-wrong_003f">7.33 Why are powers of negative numbers wrong?</a></li>
    <li><a id="toc-How-can-I-save-the-result-of-each-iteration-in-a-loop-into-a-separate-file_003f-1" href="#How-can-I-save-the-result-of-each-iteration-in-a-loop-into-a-separate-file_003f">7.34 How can I save the result of each iteration in a loop into a separate file?</a></li>
    <li><a id="toc-Why-are-p_002dvalues-not-displayed-when-using-lmer_0028_0029_003f-1" href="#Why-are-p_002dvalues-not-displayed-when-using-lmer_0028_0029_003f">7.35 Why are <em class="math">p</em>-values not displayed when using <code class="code">lmer()</code>?</a></li>
    <li><a id="toc-Why-are-there-unwanted-borders_002c-lines-or-grid_002dlike-artifacts-when-viewing-a-plot-saved-to-a-PS-or-PDF-file_003f" href="#Why-are-there-unwanted-borders">7.36 Why are there unwanted borders, lines or grid-like artifacts when viewing a plot saved to a PS or PDF file?</a></li>
    <li><a id="toc-Why-does-backslash-behave-strangely-inside-strings_003f-1" href="#Why-does-backslash-behave-strangely-inside-strings_003f">7.37 Why does backslash behave strangely inside strings?</a></li>
    <li><a id="toc-How-can-I-put-error-bars-or-confidence-bands-on-my-plot_003f-1" href="#How-can-I-put-error-bars-or-confidence-bands-on-my-plot_003f">7.38 How can I put error bars or confidence bands on my plot?</a></li>
    <li><a id="toc-How-do-I-create-a-plot-with-two-y_002daxes_003f-1" href="#How-do-I-create-a-plot-with-two-y_002daxes_003f">7.39 How do I create a plot with two y-axes?</a></li>
    <li><a id="toc-How-do-I-access-the-source-code-for-a-function_003f-1" href="#How-do-I-access-the-source-code-for-a-function_003f">7.40 How do I access the source code for a function?</a></li>
    <li><a id="toc-Why-does-summary_0028_0029-report-strange-results-for-the-R_005e2-estimate-when-I-fit-a-linear-model-with-no-intercept_003f-1" href="#Why-does-summary_0028_0029-report-strange-results-for-the-R_005e2-estimate-when-I-fit-a-linear-model-with-no-intercept_003f">7.41 Why does summary() report strange results for the R^2 estimate when I fit a linear model with no intercept?</a></li>
    <li><a id="toc-Why-is-R-apparently-not-releasing-memory_003f-1" href="#Why-is-R-apparently-not-releasing-memory_003f">7.42 Why is R apparently not releasing memory?</a></li>
    <li><a id="toc-How-can-I-enable-secure-https-downloads-in-R_003f-1" href="#How-can-I-enable-secure-https-downloads-in-R_003f">7.43 How can I enable secure https downloads in R?</a></li>
    <li><a id="toc-How-can-I-get-CRAN-package-binaries-for-outdated-versions-of-R_003f-1" href="#How-can-I-get-CRAN-package-binaries-for-outdated-versions-of-R_003f">7.44 How can I get CRAN package binaries for outdated versions of R?</a></li>
  </ul></li>
  <li><a id="toc-R-Programming-1" href="#R-Programming">8 R Programming</a>
  <ul class="toc-numbered-mark">
    <li><a id="toc-How-should-I-write-summary-methods_003f-1" href="#How-should-I-write-summary-methods_003f">8.1 How should I write summary methods?</a></li>
    <li><a id="toc-How-can-I-debug-dynamically-loaded-code_003f-1" href="#How-can-I-debug-dynamically-loaded-code_003f">8.2 How can I debug dynamically loaded code?</a></li>
    <li><a id="toc-How-can-I-inspect-R-objects-when-debugging_003f-1" href="#How-can-I-inspect-R-objects-when-debugging_003f">8.3 How can I inspect R objects when debugging?</a></li>
    <li><a id="toc-How-can-I-change-compilation-flags_003f-1" href="#How-can-I-change-compilation-flags_003f">8.4 How can I change compilation flags?</a></li>
    <li><a id="toc-How-can-I-debug-S4-methods_003f-1" href="#How-can-I-debug-S4-methods_003f">8.5 How can I debug S4 methods?</a></li>
  </ul></li>
  <li><a id="toc-R-Bugs-1" href="#R-Bugs">9 R Bugs</a>
  <ul class="toc-numbered-mark">
    <li><a id="toc-What-is-a-bug_003f-1" href="#What-is-a-bug_003f">9.1 What is a bug?</a></li>
    <li><a id="toc-How-to-report-a-bug-1" href="#How-to-report-a-bug">9.2 How to report a bug</a></li>
  </ul></li>
  <li><a id="toc-Acknowledgments-1" href="#Acknowledgments">10 Acknowledgments</a></li>
</ul>
</div>
</div>
<hr>
<div class="chapter-level-extent" id="Introduction">
<div class="nav-panel">
<p>
Next: <a href="#R-Basics" accesskey="n" rel="next">R Basics</a>, Previous: <a href="#Top" accesskey="p" rel="prev">R FAQ</a>, Up: <a href="#Top" accesskey="u" rel="up">R FAQ</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
</div>
<h2 class="chapter" id="Introduction-1"><span>1 Introduction<a class="copiable-link" href="#Introduction-1"> &para;</a></span></h2>


<ul class="mini-toc">
<li><a href="#Legalese" accesskey="1">Legalese</a></li>
<li><a href="#Obtaining-this-document" accesskey="2">Obtaining this document</a></li>
<li><a href="#Citing-this-document" accesskey="3">Citing this document</a></li>
<li><a href="#Notation" accesskey="4">Notation</a></li>
<li><a href="#Feedback" accesskey="5">Feedback</a></li>
</ul>
<hr>
<div class="section-level-extent" id="Legalese">
<div class="nav-panel">
<p>
Next: <a href="#Obtaining-this-document" accesskey="n" rel="next">Obtaining this document</a>, Previous: <a href="#Introduction" accesskey="p" rel="prev">Introduction</a>, Up: <a href="#Introduction" accesskey="u" rel="up">Introduction</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
</div>
<h3 class="section" id="Legalese-1"><span>1.1 Legalese<a class="copiable-link" href="#Legalese-1"> &para;</a></span></h3>

<p>Copyright &copy; 1998&ndash;2020 Kurt Hornik <br>
Copyright &copy; 2021&ndash;2024 R Core Team
</p>
<p>This document is free software; you can redistribute it and/or modify it
under the terms of the <abbr class="acronym">GNU</abbr> General Public License as published
by the Free Software Foundation; either version 2, or (at your option)
any later version.
</p>
<p>This document is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
<abbr class="acronym">GNU</abbr> General Public License for more details.
</p>
<p>Copies of the <abbr class="acronym">GNU</abbr> General Public License versions are
available at
</p>
<div class="display">
<pre class="display-preformatted"><a class="url" href="https://www.R-project.org/Licenses/">https://www.R-project.org/Licenses/</a>
</pre></div>


<hr>
</div>
<div class="section-level-extent" id="Obtaining-this-document">
<div class="nav-panel">
<p>
Next: <a href="#Citing-this-document" accesskey="n" rel="next">Citing this document</a>, Previous: <a href="#Legalese" accesskey="p" rel="prev">Legalese</a>, Up: <a href="#Introduction" accesskey="u" rel="up">Introduction</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
</div>
<h3 class="section" id="Obtaining-this-document-1"><span>1.2 Obtaining this document<a class="copiable-link" href="#Obtaining-this-document-1"> &para;</a></span></h3>

<p>The latest version of this document is always available from
</p>
<div class="display">
<pre class="display-preformatted"><a class="url" href="https://CRAN.R-project.org/doc/manuals/">https://CRAN.R-project.org/doc/manuals/</a>
</pre></div>

<p>From there, you can obtain versions converted to
<a class="url" href="https://CRAN.R-project.org/doc/manuals/R-FAQ.html"><abbr class="acronym">HTML</abbr></a> and
<a class="url" href="https://CRAN.R-project.org/doc/manuals/R-FAQ.pdf">PDF</a>.
</p>
<hr>
</div>
<div class="section-level-extent" id="Citing-this-document">
<div class="nav-panel">
<p>
Next: <a href="#Notation" accesskey="n" rel="next">Notation</a>, Previous: <a href="#Obtaining-this-document" accesskey="p" rel="prev">Obtaining this document</a>, Up: <a href="#Introduction" accesskey="u" rel="up">Introduction</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
</div>
<h3 class="section" id="Citing-this-document-1"><span>1.3 Citing this document<a class="copiable-link" href="#Citing-this-document-1"> &para;</a></span></h3>

<p>In publications, please refer to this <abbr class="acronym">FAQ</abbr> as Hornik and R Core Team
(2023), &ldquo;The R <abbr class="acronym">FAQ</abbr>&rdquo;, and give the above,
<em class="emph">official</em> <abbr class="acronym">URL</abbr>:
</p>
<div class="example">
<div class="group"><pre class="example-preformatted">@Misc{,
  author        = {Kurt Hornik and the R Core Team},
  title         = {{R} {FAQ}},
  year          = {2023},
  url           = {https://CRAN.R-project.org/doc/manuals/R-FAQ.html}
}
</pre></div></div>


<hr>
</div>
<div class="section-level-extent" id="Notation">
<div class="nav-panel">
<p>
Next: <a href="#Feedback" accesskey="n" rel="next">Feedback</a>, Previous: <a href="#Citing-this-document" accesskey="p" rel="prev">Citing this document</a>, Up: <a href="#Introduction" accesskey="u" rel="up">Introduction</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
</div>
<h3 class="section" id="Notation-1"><span>1.4 Notation<a class="copiable-link" href="#Notation-1"> &para;</a></span></h3>

<p>Everything should be pretty standard.  &lsquo;<samp class="samp">R&gt;</samp>&rsquo; is used for the R
prompt, and a &lsquo;<samp class="samp">$</samp>&rsquo; for the shell prompt (where applicable).
</p>
<hr>
</div>
<div class="section-level-extent" id="Feedback">
<div class="nav-panel">
<p>
Previous: <a href="#Notation" accesskey="p" rel="prev">Notation</a>, Up: <a href="#Introduction" accesskey="u" rel="up">Introduction</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
</div>
<h3 class="section" id="Feedback-1"><span>1.5 Feedback<a class="copiable-link" href="#Feedback-1"> &para;</a></span></h3>

<p>Feedback via email to <a class="email" href="mailto:[email protected]">[email protected]</a> is most welcome.
</p>
<p>Features specific to the Windows and macOS ports of R are
described in the
<a class="url" href="https://CRAN.R-project.org/bin/windows/base/rw-FAQ.html">&ldquo;R for
Windows <abbr class="acronym">FAQ</abbr>&rdquo;</a> and the
<a class="url" href="https://CRAN.R-project.org/bin/macosx/RMacOSX-FAQ.html">&ldquo;R for Mac
OS X <abbr class="acronym">FAQ</abbr>&rdquo;</a>.  If you have information on Mac or Windows
systems that you think should be added to this document, please let us
know.
</p>

<hr>
</div>
</div>
<div class="chapter-level-extent" id="R-Basics">
<div class="nav-panel">
<p>
Next: <a href="#R-and-S" accesskey="n" rel="next">R and S</a>, Previous: <a href="#Introduction" accesskey="p" rel="prev">Introduction</a>, Up: <a href="#Top" accesskey="u" rel="up">R FAQ</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
</div>
<h2 class="chapter" id="R-Basics-1"><span>2 R Basics<a class="copiable-link" href="#R-Basics-1"> &para;</a></span></h2>


<ul class="mini-toc">
<li><a href="#What-is-R_003f" accesskey="1">What is R?</a></li>
<li><a href="#What-machines-does-R-run-on_003f" accesskey="2">What machines does R run on?</a></li>
<li><a href="#What-is-the-current-version-of-R_003f" accesskey="3">What is the current version of R?</a></li>
<li><a href="#How-can-R-be-obtained_003f" accesskey="4">How can R be obtained?</a></li>
<li><a href="#How-can-R-be-installed_003f" accesskey="5">How can R be installed?</a></li>
<li><a href="#Are-there-Unix_002dlike-binaries-for-R_003f" accesskey="6">Are there Unix-like binaries for R?</a></li>
<li><a href="#What-documentation-exists-for-R_003f" accesskey="7">What documentation exists for R?</a></li>
<li><a href="#Citing-R" accesskey="8">Citing R</a></li>
<li><a href="#What-mailing-lists-exist-for-R_003f" accesskey="9">What mailing lists exist for R?</a></li>
<li><a href="#What-is-CRAN_003f">What is <abbr class="acronym">CRAN</abbr>?</a></li>
<li><a href="#Can-I-use-R-for-commercial-purposes_003f">Can I use R for commercial purposes?</a></li>
<li><a href="#Why-is-R-named-R_003f">Why is R named R?</a></li>
<li><a href="#What-is-the-R-Foundation_003f">What is the R Foundation?</a></li>
<li><a href="#What-is-R_002dForge_003f">What is R-Forge?</a></li>
</ul>
<hr>
<div class="section-level-extent" id="What-is-R_003f">
<div class="nav-panel">
<p>
Next: <a href="#What-machines-does-R-run-on_003f" accesskey="n" rel="next">What machines does R run on?</a>, Previous: <a href="#R-Basics" accesskey="p" rel="prev">R Basics</a>, Up: <a href="#R-Basics" accesskey="u" rel="up">R Basics</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
</div>
<h3 class="section" id="What-is-R_003f-1"><span>2.1 What is R?<a class="copiable-link" href="#What-is-R_003f-1"> &para;</a></span></h3>

<p>R is a system for statistical computation and graphics.  It consists of
a language plus a run-time environment with graphics, a debugger, access
to certain system functions, and the ability to run programs stored in
script files.
</p>
<p>The design of R has been heavily influenced by two existing languages:
Becker, Chambers &amp; Wilks&rsquo; S (see <a class="pxref" href="#What-is-S_003f">What is S?</a>) and Sussman&rsquo;s
<a class="url" href="http://community.schemewiki.org/?scheme-faq">Scheme</a>.
Whereas the resulting language is very similar in appearance to S, the
underlying implementation and semantics are derived from Scheme.
See <a class="xref" href="#What-are-the-differences-between-R-and-S_003f">What are the differences between R and S?</a>, for further details.
</p>
<p>The core of R is an interpreted computer language which allows branching
and looping as well as modular programming using functions.  Most of the
user-visible functions in R are written in R.  It is possible for the
user to interface to procedures written in the C, C++, or FORTRAN
languages for efficiency.  The R distribution contains functionality for
a large number of statistical procedures.  Among these are: linear and
generalized linear models, nonlinear regression models, time series
analysis, classical parametric and nonparametric tests, clustering and
smoothing.  There is also a large set of functions which provide a
flexible graphical environment for creating various kinds of data
presentations.  Additional modules (&ldquo;add-on packages&rdquo;) are available
for a variety of specific purposes (see <a class="pxref" href="#R-Add_002dOn-Packages">R Add-On Packages</a>).
</p>
<p>R was initially written by <a class="email" href="mailto:[email protected]">Ross Ihaka</a>
and <a class="email" href="mailto:[email protected]">Robert Gentleman</a> at the
Department of Statistics of the University of Auckland in Auckland, New
Zealand.  In addition, a large group of individuals has contributed to R
by sending code and bug reports.
</p>
<p>Since mid-1997 there has been a core group (the &ldquo;R Core Team&rdquo;) who can
modify the R source code archive, currently consisting of
</p><div class="display">
<pre class="display-preformatted">John Chambers,
Peter Dalgaard,
Robert Gentleman,
Kurt Hornik,
Ross Ihaka,
Tomas Kalibera,
Michael Lawrence,
Friedrich Leisch,
Uwe Ligges,
Thomas Lumley,
Martin Maechler,
Sebastian Meyer,
Paul Murrell,
Martyn Plummer,
Brian Ripley,
Deepayan Sarkar,
Duncan Temple Lang,
Luke Tierney, and 
Simon Urbanek,
</pre></div>
<p>plus 
Heiner Schwarte up to October 1999, 
Guido Masarotto up to June 2003, 
Stefano Iacus up to July 2014, 
Seth Falcon up to August 2015, 
Duncan Murdoch up to September 2017, 
Martin Morgan up to June 2021, and 
Douglas Bates up to March 2024.
</p>
<p>R has a home page at <a class="url" href="https://www.R-project.org/">https://www.R-project.org/</a>.  It is
<a class="url" href="https://www.gnu.org/philosophy/free-sw.html">free software</a>
distributed under a <abbr class="acronym">GNU</abbr>-style
<a class="url" href="https://www.gnu.org/copyleft/copyleft.html">copyleft</a>, and an
official part of the <a class="url" href="https://www.gnu.org/"><abbr class="acronym">GNU</abbr></a> project
(&ldquo;<abbr class="acronym">GNU</abbr> S&rdquo;).
</p>
<hr>
</div>
<div class="section-level-extent" id="What-machines-does-R-run-on_003f">
<div class="nav-panel">
<p>
Next: <a href="#What-is-the-current-version-of-R_003f" accesskey="n" rel="next">What is the current version of R?</a>, Previous: <a href="#What-is-R_003f" accesskey="p" rel="prev">What is R?</a>, Up: <a href="#R-Basics" accesskey="u" rel="up">R Basics</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
</div>
<h3 class="section" id="What-machines-does-R-run-on_003f-1"><span>2.2 What machines does R run on?<a class="copiable-link" href="#What-machines-does-R-run-on_003f-1"> &para;</a></span></h3>

<p>R is being developed for the Unix-like, Windows and Mac families of
operating systems.  Support for Mac OS Classic ended with R 1.7.1.
</p>
<p>The current version of R will configure and build under a number of
common Unix-like (e.g., <a class="uref" href="https://en.wikipedia.org/wiki/Unix-like">https://en.wikipedia.org/wiki/Unix-like</a>)
platforms including <var class="var">cpu</var>-linux-gnu for the i386,
amd64/x86_64, alpha, arm, arm64, hppa,
mips/mipsel, powerpc, s390x and sparc
<abbr class="acronym">CPU</abbr>s (e.g.,
<a class="url" href="https://buildd.debian.org/build.php?&amp;pkg=r-base">https://buildd.debian.org/build.php?&amp;pkg=r-base</a>), 
386-hurd-gnu,
<var class="var">cpu</var>-kfreebsd-gnu for i386 and amd64,
i386-pc-solaris,
rs6000-ibm-aix,
sparc-sun-solaris, 
x86_64-apple-darwin,
aarch64-apple-darwin, 
x86_64-unknown-freebsd and 
x86_64-unknown-openbsd.
</p>

<p>If you know about other platforms, please drop us a note.
</p>
<hr>
</div>
<div class="section-level-extent" id="What-is-the-current-version-of-R_003f">
<div class="nav-panel">
<p>
Next: <a href="#How-can-R-be-obtained_003f" accesskey="n" rel="next">How can R be obtained?</a>, Previous: <a href="#What-machines-does-R-run-on_003f" accesskey="p" rel="prev">What machines does R run on?</a>, Up: <a href="#R-Basics" accesskey="u" rel="up">R Basics</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
</div>
<h3 class="section" id="What-is-the-current-version-of-R_003f-1"><span>2.3 What is the current version of R?<a class="copiable-link" href="#What-is-the-current-version-of-R_003f-1"> &para;</a></span></h3>
 
<p>R uses a &lsquo;major.minor.patchlevel&rsquo; numbering scheme.  Based on this,
there are the current release version of R (&lsquo;r-release&rsquo;) as well as two
development versions of R, a patched version of the current release
(&lsquo;r-patched&rsquo;) and one working towards the next minor or eventually major
(&lsquo;r-devel&rsquo;) releases of R, respectively.  New features are typically
introduced in r-devel, while r-patched is for bug fixes mostly.
</p>
<p>See <a class="url" href="https://CRAN.R-project.org/sources.html">https://CRAN.R-project.org/sources.html</a> for the current
versions of r-release, r-patched and r-devel.
</p>
<hr>
</div>
<div class="section-level-extent" id="How-can-R-be-obtained_003f">
<div class="nav-panel">
<p>
Next: <a href="#How-can-R-be-installed_003f" accesskey="n" rel="next">How can R be installed?</a>, Previous: <a href="#What-is-the-current-version-of-R_003f" accesskey="p" rel="prev">What is the current version of R?</a>, Up: <a href="#R-Basics" accesskey="u" rel="up">R Basics</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
</div>
<h3 class="section" id="How-can-R-be-obtained_003f-1"><span>2.4 How can R be obtained?<a class="copiable-link" href="#How-can-R-be-obtained_003f-1"> &para;</a></span></h3>

<p>Sources, binaries and documentation for R can be obtained via <abbr class="acronym">CRAN</abbr>,
the &ldquo;Comprehensive R Archive Network&rdquo; (see <a class="ref" href="#What-is-CRAN_003f">What is <abbr class="acronym">CRAN</abbr>?</a>).
</p>
<p>Sources are also available via <a class="url" href="https://svn.R-project.org/R/">https://svn.R-project.org/R/</a>, the
R Subversion repository, but currently not via anonymous rsync (nor
CVS).
</p>
<p>Tarballs with daily snapshots of the r-devel and r-patched development
versions of R can be found at
<a class="url" href="https://stat.ethz.ch/R/daily/">https://stat.ethz.ch/R/daily/</a>.
</p>





<hr>
</div>
<div class="section-level-extent" id="How-can-R-be-installed_003f">
<div class="nav-panel">
<p>
Next: <a href="#Are-there-Unix_002dlike-binaries-for-R_003f" accesskey="n" rel="next">Are there Unix-like binaries for R?</a>, Previous: <a href="#How-can-R-be-obtained_003f" accesskey="p" rel="prev">How can R be obtained?</a>, Up: <a href="#R-Basics" accesskey="u" rel="up">R Basics</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
</div>
<h3 class="section" id="How-can-R-be-installed_003f-1"><span>2.5 How can R be installed?<a class="copiable-link" href="#How-can-R-be-installed_003f-1"> &para;</a></span></h3>


<ul class="mini-toc">
<li><a href="#How-can-R-be-installed-_0028Unix_002dlike_0029" accesskey="1">How can R be installed (Unix-like)</a></li>
<li><a href="#How-can-R-be-installed-_0028Windows_0029" accesskey="2">How can R be installed (Windows)</a></li>
<li><a href="#How-can-R-be-installed-_0028Mac_0029" accesskey="3">How can R be installed (Mac)</a></li>
</ul>
<hr>
<div class="subsection-level-extent" id="How-can-R-be-installed-_0028Unix_002dlike_0029">
<div class="nav-panel">
<p>
Next: <a href="#How-can-R-be-installed-_0028Windows_0029" accesskey="n" rel="next">How can R be installed (Windows)</a>, Previous: <a href="#How-can-R-be-installed_003f" accesskey="p" rel="prev">How can R be installed?</a>, Up: <a href="#How-can-R-be-installed_003f" accesskey="u" rel="up">How can R be installed?</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
</div>
<h4 class="subsection" id="How-can-R-be-installed-_0028Unix_002dlike_0029-1"><span>2.5.1 How can R be installed (Unix-like)<a class="copiable-link" href="#How-can-R-be-installed-_0028Unix_002dlike_0029-1"> &para;</a></span></h4>

<p>If R is already installed, it can be started by typing <kbd class="kbd">R</kbd> at the
shell prompt (of course, provided that the executable is in your path).
</p>
<p>If binaries are available for your platform (see <a class="ref" href="#Are-there-Unix_002dlike-binaries-for-R_003f">Are there Unix-like binaries for R?</a>), you can use these, following the
instructions that come with them.
</p>
<p>Otherwise, you can compile and install R yourself, which can be done
very easily under a number of common Unix-like platforms (see <a class="ref" href="#What-machines-does-R-run-on_003f">What machines does R run on?</a>).  The file <samp class="file">INSTALL</samp> that comes with the
R distribution contains a brief introduction, and the &ldquo;R Installation
and Administration&rdquo; guide (see <a class="pxref" href="#What-documentation-exists-for-R_003f">What documentation exists for R?</a>)
has full details.
</p>
<p>Note that you need a FORTRAN 90 compiler as well as a C compiler to
build R.
</p>
<p>In the simplest case, untar the R source code, change to the directory
thus created, and issue the following commands (at the shell prompt):
</p>
<div class="example">
<pre class="example-preformatted">$ ./configure
$ make
</pre></div>

<p>If these commands execute successfully, the R binary and a shell script
front-end called <samp class="file">R</samp> are created and copied to the <samp class="file">bin</samp>
directory.  You can copy the script to a place where users can invoke
it, for example to <samp class="file">/usr/local/bin</samp>.  In addition,
<abbr class="acronym">HTML</abbr> versions of the R manuals (e.g., <samp class="file">R-exts.html</samp>, the
&ldquo;Writing R Extensions&rdquo; manual) are built in the <samp class="file">doc/manual</samp>
subdirectory.
</p>
<p>Use <kbd class="kbd">make pdf</kbd> to build PDF (Portable Document Format)
versions of the R manuals, including
<samp class="file">fullrefman.pdf</samp> (an R object reference index).  Manuals written in the
<abbr class="acronym">GNU</abbr> Texinfo system can also be converted to info files
suitable for reading online with Emacs or stand-alone <abbr class="acronym">GNU</abbr>
Info; use <kbd class="kbd">make info</kbd> to create these versions (note that this
requires Makeinfo version 4.5).
</p>
<p>Finally, use <kbd class="kbd">make check</kbd> to find out whether your R system works
correctly.
</p>
<p>You can also perform a &ldquo;system-wide&rdquo; installation using <kbd class="kbd">make
install</kbd>.  By default, this will install to the following directories:
</p>
<dl class="table">
<dt><samp class="file">${prefix}/bin</samp></dt>
<dd><p>the front-end shell script
</p></dd>
<dt><samp class="file">${prefix}/man/man1</samp></dt>
<dd><p>the man page
</p></dd>
<dt><samp class="file">${prefix}/lib/R</samp></dt>
<dd><p>all the rest (libraries, on-line help system, &hellip;).  This is the &ldquo;R
Home Directory&rdquo; (<code class="env">R_HOME</code>) of the installed system.
</p></dd>
</dl>

<p>In the above, <code class="code">prefix</code> is determined during configuration
(typically <samp class="file">/usr/local</samp>) and can be set by running
<code class="command">configure</code> with the option
</p>
<div class="example">
<pre class="example-preformatted">$ ./configure --prefix=/where/you/want/R/to/go
</pre></div>

<p>(E.g., the R executable will then be installed into
<samp class="file">/where/you/want/R/to/go/bin</samp>.)
</p>
<p>To install info and PDF versions of the manuals, use
<kbd class="kbd">make install-info</kbd> and <kbd class="kbd">make install-pdf</kbd>,
respectively.
</p>
<hr>
</div>
<div class="subsection-level-extent" id="How-can-R-be-installed-_0028Windows_0029">
<div class="nav-panel">
<p>
Next: <a href="#How-can-R-be-installed-_0028Mac_0029" accesskey="n" rel="next">How can R be installed (Mac)</a>, Previous: <a href="#How-can-R-be-installed-_0028Unix_002dlike_0029" accesskey="p" rel="prev">How can R be installed (Unix-like)</a>, Up: <a href="#How-can-R-be-installed_003f" accesskey="u" rel="up">How can R be installed?</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
</div>
<h4 class="subsection" id="How-can-R-be-installed-_0028Windows_0029-1"><span>2.5.2 How can R be installed (Windows)<a class="copiable-link" href="#How-can-R-be-installed-_0028Windows_0029-1"> &para;</a></span></h4>

<p>The <samp class="file">bin/windows</samp> directory of a <abbr class="acronym">CRAN</abbr> site contains binaries for
a base distribution and add-on packages from <abbr class="acronym">CRAN</abbr> to run on 64-bit
versions of Windows 7 and later on x86_64 chips (R 4.1.3 was the last
version of R to support 32-bit Windows).  The Windows version of R was
created by Robert Gentleman and Guido Masarotto; Brian
Ripley and Duncan Murdoch made substantial contributions and it is
now being maintained by other members of the R Core team.
</p>
<p>The same directory has links to snapshots of the r-patched and r-devel
versions of R.
</p>
<p>See the <a class="url" href="https://CRAN.R-project.org/bin/windows/base/rw-FAQ.html">&ldquo;R for Windows <abbr class="acronym">FAQ</abbr>&rdquo;</a> for more details.
</p>
<hr>
</div>
<div class="subsection-level-extent" id="How-can-R-be-installed-_0028Mac_0029">
<div class="nav-panel">
<p>
Previous: <a href="#How-can-R-be-installed-_0028Windows_0029" accesskey="p" rel="prev">How can R be installed (Windows)</a>, Up: <a href="#How-can-R-be-installed_003f" accesskey="u" rel="up">How can R be installed?</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
</div>
<h4 class="subsection" id="How-can-R-be-installed-_0028Mac_0029-1"><span>2.5.3 How can R be installed (Mac)<a class="copiable-link" href="#How-can-R-be-installed-_0028Mac_0029-1"> &para;</a></span></h4>

<p>The <samp class="file">bin/macosx</samp> directory of a <abbr class="acronym">CRAN</abbr> site contains a standard
Apple installer package to run on macOS 10.13 (&lsquo;High Sierra&rsquo;) or later,
and another which runs only on &lsquo;Apple Silicon&rsquo; Macs under macOS 11
(&lsquo;Big Sur&rsquo;) or later.  Once downloaded and executed, the installer will
install the current release of R and R.app, the macOS <abbr class="acronym">GUI</abbr>.
This port of R for macOS is maintained by
<a class="email" href="mailto:[email protected]">Simon Urbanek</a> (and previously by
Stefano Iacus).  The
<a class="url" href="https://CRAN.R-project.org/bin/macosx/RMacOSX-FAQ.html">&ldquo;R for
macOS <abbr class="acronym">FAQ</abbr>&rdquo;</a> has more details.
</p>
<p>Snapshots of the r-patched and r-devel versions of R are available as
Apple installer packages at <a class="uref" href="https://mac.R-project.org">https://mac.R-project.org</a>.
</p>
<hr>
</div>
</div>
<div class="section-level-extent" id="Are-there-Unix_002dlike-binaries-for-R_003f">
<div class="nav-panel">
<p>
Next: <a href="#What-documentation-exists-for-R_003f" accesskey="n" rel="next">What documentation exists for R?</a>, Previous: <a href="#How-can-R-be-installed_003f" accesskey="p" rel="prev">How can R be installed?</a>, Up: <a href="#R-Basics" accesskey="u" rel="up">R Basics</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
</div>
<h3 class="section" id="Are-there-Unix_002dlike-binaries-for-R_003f-1"><span>2.6 Are there Unix-like binaries for R?<a class="copiable-link" href="#Are-there-Unix_002dlike-binaries-for-R_003f-1"> &para;</a></span></h3>

<p>Binary distributions of R are available on many Unix-like OSes: only
some can be mentioned here so check your OS&rsquo;s search facilities to see
if one is available for yours.
</p>
<p>The <samp class="file">bin/linux</samp> directory of a <abbr class="acronym">CRAN</abbr> site contains R packages for
Debian and Ubuntu.
</p>
<p>Debian packages, maintained by Dirk Eddelbuettel, have long been part of
the Debian distribution, and can be accessed through APT, the Debian
package maintenance tool.  Use e.g. <code class="code">apt-get install r-base
r-recommended</code> to install the R environment and recommended packages.
If you also want to build R packages from source, also run <code class="code">apt-get
install r-base-dev</code> to obtain the additional tools required for this.
So-called &ldquo;backports&rdquo; of the current R packages for at least the
<em class="dfn">stable</em> distribution of Debian are provided by Johannes Ranke, and
available from <abbr class="acronym">CRAN</abbr>.  See
<a class="url" href="https://CRAN.R-project.org/bin/linux/debian/index.html">https://CRAN.R-project.org/bin/linux/debian/index.html</a> for details on R
Debian packages and installing the backports, which should also be
suitable for other Debian derivatives.  Native backports for Ubuntu are
provided by Michael Rutter, see
<a class="url" href="https://CRAN.R-project.org/bin/linux/ubuntu/index.html">https://CRAN.R-project.org/bin/linux/ubuntu/index.html</a> for
instructions.
</p>
<p>R binaries for Fedora, maintained by Tom &ldquo;Spot&rdquo; Callaway, are provided
as part of the Fedora distribution and can be accessed through
<code class="command">yum</code>, the <abbr class="abbr">RPM</abbr> installer/updater.  Note that the &ldquo;Software&rdquo;
application (gnome-software), which is the default <abbr class="acronym">GUI</abbr> for
software installation in Fedora 20, cannot be used to install R.  It is
therefore recommended to use the yum command line tool.
The Fedora R <abbr class="abbr">RPM</abbr> is a &ldquo;meta-package&rdquo; which installs all the user and
developer components of R (available separately as <code class="code">R-core</code> and
<code class="code">R-devel</code>), as well as <code class="code">R-java</code>, which ensures that R is
configured for use with Java.  The R <abbr class="abbr">RPM</abbr> also installs the standalone R
math library (<code class="code">libRmath</code> and <code class="code">libRmath-devel</code>), although this
is not necessary to use R.  When a new version of R is released, there
may be a delay of up to 2 weeks until the Fedora <abbr class="abbr">RPM</abbr> becomes publicly
available, as it must pass through the Fedora review process.
<abbr class="abbr">RPM</abbr>s for a selection of R packages are also provided by Fedora.  The
Extra Packages for Enterprise Linux (<abbr class="abbr">EPEL</abbr>) project
(<a class="url" href="https://docs.fedoraproject.org/en-US/epel/">https://docs.fedoraproject.org/en-US/epel/</a>) provides ports of the Fedora
<abbr class="abbr">RPM</abbr>s for RedHat Enterprise Linux and compatible distributions (e.g.,
Centos, Scientific Linux, Oracle Linux).
</p>
<p>See <a class="url" href="https://CRAN.R-project.org/bin/linux/suse/README.html">https://CRAN.R-project.org/bin/linux/suse/README.html</a> for
information about <abbr class="abbr">RPM</abbr>s for openSUSE.
</p>
<p>No other binary distributions are currently publicly available via
<abbr class="acronym">CRAN</abbr>.
</p>
<hr>
</div>
<div class="section-level-extent" id="What-documentation-exists-for-R_003f">
<div class="nav-panel">
<p>
Next: <a href="#Citing-R" accesskey="n" rel="next">Citing R</a>, Previous: <a href="#Are-there-Unix_002dlike-binaries-for-R_003f" accesskey="p" rel="prev">Are there Unix-like binaries for R?</a>, Up: <a href="#R-Basics" accesskey="u" rel="up">R Basics</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
</div>
<h3 class="section" id="What-documentation-exists-for-R_003f-1"><span>2.7 What documentation exists for R?<a class="copiable-link" href="#What-documentation-exists-for-R_003f-1"> &para;</a></span></h3>

<p>Online documentation for most of the functions and variables in R
exists, and can be printed on-screen by typing <kbd class="kbd">help(<var class="var">name</var>)</kbd>
(or <kbd class="kbd">?<var class="var">name</var></kbd>) at the R prompt, where <var class="var">name</var> is the name of
the topic help is sought for.  (In the case of unary and binary
operators and control-flow special forms, the name may need to be
quoted.)
</p>
<p>This documentation can also be made available as one reference manual
for on-line reading in <abbr class="acronym">HTML</abbr> and PDF formats, and as hardcopy via
LaTeX, see <a class="ref" href="#How-can-R-be-installed_003f">How can R be installed?</a>.  An up-to-date <abbr class="acronym">HTML</abbr>
version is always available for web browsing at
<a class="url" href="https://stat.ethz.ch/R-manual/">https://stat.ethz.ch/R-manual/</a>.
</p>

<p>The R distribution also comes with the following manuals.
</p>
<ul class="itemize mark-bullet">
<li>&ldquo;An Introduction to R&rdquo; (<samp class="file">R-intro</samp>)
includes information on data types, programming elements, statistical
modeling and graphics.  This document is based on the &ldquo;Notes on
<small class="sc">S-PLUS</small>&rdquo; by Bill Venables and David Smith.
</li><li>&ldquo;Writing R Extensions&rdquo; (<samp class="file">R-exts</samp>)
currently describes the process of creating R add-on packages, writing R
documentation, R&rsquo;s system and foreign language interfaces, and the R
<abbr class="acronym">API</abbr>.
</li><li>&ldquo;R Data Import/Export&rdquo; (<samp class="file">R-data</samp>)
is a guide to importing and exporting data to and from R.
</li><li>&ldquo;The R Language Definition&rdquo; (<samp class="file">R-lang</samp>),
a first version of the &ldquo;Kernighan &amp; Ritchie of R&rdquo;, explains
evaluation, parsing, object oriented programming, computing on the
language, and so forth.
</li><li>&ldquo;R Installation and Administration&rdquo; (<samp class="file">R-admin</samp>).
</li><li>&ldquo;R Internals&rdquo; (<samp class="file">R-ints</samp>)
is a guide to R&rsquo;s internal structures.
(Added in R 2.4.0.)
</li></ul>

<p>An annotated bibliography (BibTeX format) of R-related publications
can be found at
</p>
<div class="display">
<pre class="display-preformatted"><a class="url" href="https://www.R-project.org/doc/bib/R.bib">https://www.R-project.org/doc/bib/R.bib</a>
</pre></div>

<p>Books on R by R Core Team members include
</p>
<blockquote class="quotation">
<p>John M. Chambers (2008),
&ldquo;Software for Data Analysis: Programming with R&rdquo;.  
Springer, New York, ISBN 978-0-387-75935-7,
<a class="url" href="https://johnmchambers.su.domains/Rbook/">https://johnmchambers.su.domains/Rbook/</a>.
</p>
<p>Peter Dalgaard (2008),
&ldquo;Introductory Statistics with R&rdquo;,
2nd edition.
Springer, ISBN 978-0-387-79053-4,
<a class="url" href="http://publicifsv.sund.ku.dk/~pd/ISwR.html">http://publicifsv.sund.ku.dk/~pd/ISwR.html</a>.
</p>
<p>Robert Gentleman (2008),
&ldquo;R Programming for Bioinformatics&rdquo;.
Chapman &amp; Hall/CRC, Boca Raton, FL, ISBN 978-1-420-06367-7,
<a class="url" href="https://bioconductor.org/help/publications/books/r-programming-for-bioinformatics/">https://bioconductor.org/help/publications/books/r-programming-for-bioinformatics/</a>.
</p>
<p>Stefano M. Iacus (2008),
&ldquo;Simulation and Inference for Stochastic Differential Equations: With R
Examples&rdquo;.
Springer, New York, ISBN 978-0-387-75838-1.
</p>
<p>Deepayan Sarkar (2007),
&ldquo;Lattice: Multivariate Data Visualization with R&rdquo;.
Springer, New York, ISBN 978-0-387-75968-5.
</p>
<p>W. John Braun and Duncan J. Murdoch (2007),
&ldquo;A First Course in Statistical Programming with R&rdquo;.
 Cambridge University Press, Cambridge, ISBN 978-0521872652.
</p>
<p>P. Murrell (2005), &ldquo;R Graphics&rdquo;,
Chapman &amp; Hall/CRC, ISBN 1-584-88486-X,
<a class="url" href="https://www.stat.auckland.ac.nz/~paul/RGraphics/rgraphics.html">https://www.stat.auckland.ac.nz/~paul/RGraphics/rgraphics.html</a>.
</p>
<p>William N. Venables and Brian D. Ripley (2002),
&ldquo;Modern Applied Statistics with S&rdquo; (4th edition).
Springer, ISBN 0-387-95457-0,
<a class="url" href="https://www.stats.ox.ac.uk/pub/MASS4/">https://www.stats.ox.ac.uk/pub/MASS4/</a>.
</p>
<p>Jose C. Pinheiro and Douglas M. Bates (2000),
&ldquo;Mixed-Effects Models in S and S-Plus&rdquo;.
Springer, ISBN 0-387-98957-0.
</p></blockquote>

<p>Last, but not least, Ross&rsquo; and Robert&rsquo;s experience in designing and
implementing R is described in Ihaka &amp; Gentleman (1996), 
&ldquo;R: A Language for Data Analysis and Graphics&rdquo;, 
<em class="emph">Journal of Computational and Graphical Statistics</em>, <strong class="strong">5</strong>, 299&ndash;314
(doi:&nbsp;<a class="url" href="https://doi.org/10.1080/10618600.1996.10474713">10.1080/10618600.1996.10474713</a>).
</p>
<hr>
</div>
<div class="section-level-extent" id="Citing-R">
<div class="nav-panel">
<p>
Next: <a href="#What-mailing-lists-exist-for-R_003f" accesskey="n" rel="next">What mailing lists exist for R?</a>, Previous: <a href="#What-documentation-exists-for-R_003f" accesskey="p" rel="prev">What documentation exists for R?</a>, Up: <a href="#R-Basics" accesskey="u" rel="up">R Basics</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
</div>
<h3 class="section" id="Citing-R-1"><span>2.8 Citing R<a class="copiable-link" href="#Citing-R-1"> &para;</a></span></h3>

<p>To cite R in publications, use
</p>
<div class="example">
<div class="group"><pre class="example-preformatted">@Manual{,
  title        = {R: A Language and Environment for Statistical
                  Computing},
  author       = {{R Core Team}},
  organization = {R Foundation for Statistical Computing},
  address      = {Vienna, Austria},
  year         = <var class="var">YEAR</var>,
  url          = {https://www.R-project.org}
}
</pre></div></div>
<p>where <var class="var">YEAR</var> is the release year of the version of R used and can
determined as <code class="code">R.version$year</code>.
</p>
<p>Citation strings (or BibTeX entries) for R and R packages can also be
obtained by <code class="code">citation()</code>.
</p>
<hr>
</div>
<div class="section-level-extent" id="What-mailing-lists-exist-for-R_003f">
<div class="nav-panel">
<p>
Next: <a href="#What-is-CRAN_003f" accesskey="n" rel="next">What is <abbr class="acronym">CRAN</abbr>?</a>, Previous: <a href="#Citing-R" accesskey="p" rel="prev">Citing R</a>, Up: <a href="#R-Basics" accesskey="u" rel="up">R Basics</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
</div>
<h3 class="section" id="What-mailing-lists-exist-for-R_003f-1"><span>2.9 What mailing lists exist for R?<a class="copiable-link" href="#What-mailing-lists-exist-for-R_003f-1"> &para;</a></span></h3>

<p>Thanks to <a class="email" href="mailto:[email protected]">Martin Maechler</a>, there
are several mailing lists devoted to R, including the following:
</p>
<dl class="table">
<dt><code class="code">R-announce</code></dt>
<dd><p>A moderated list for major announcements about the development of R and
the availability of new code.
</p></dd>
<dt><code class="code">R-packages</code></dt>
<dd><p>A moderated list for announcements on the availability of new or
enhanced contributed packages.
</p></dd>
<dt><code class="code">R-help</code></dt>
<dd><p>The &lsquo;main&rsquo; R mailing list, for discussion about problems and solutions
encountered using R, including using R packages in the standard R distribution 
and on CRAN;  announcements (not covered by &lsquo;R-announce&rsquo; or &lsquo;R-packages&rsquo;); 
the availability of new functionality for R and documentation of R; 
and for posting nice examples and benchmarks. 
</p></dd>
<dt><code class="code">R-devel</code></dt>
<dd><p>This list is for questions and discussion about code development in R.
</p></dd>
<dt><code class="code">R-package-devel</code></dt>
<dd><p>A list which provides a forum for those developing R packages.
</p></dd>
</dl>

<p>Please read the <a class="url" href="https://www.R-project.org/posting-guide.html">posting guide</a> <em class="emph">before</em> sending anything to any mailing list.
</p>
<p>Note in particular that R-help is intended to be comprehensible to
people who want to use R to solve problems but who are not necessarily
interested in or knowledgeable about programming.  Questions likely to
prompt discussion unintelligible to non-programmers (e.g., questions
involving C or C++) should go to R-devel.
</p>
<p>Convenient access to information on these lists, subscription, and
archives is provided by the web interface at
<a class="url" href="https://stat.ethz.ch/mailman/listinfo/">https://stat.ethz.ch/mailman/listinfo/</a>.  One can also subscribe
(or unsubscribe) via email, e.g. to R-help by sending &lsquo;<samp class="samp">subscribe</samp>&rsquo;
(or &lsquo;<samp class="samp">unsubscribe</samp>&rsquo;) in the <em class="emph">body</em> of the message (not in the
subject!) to <a class="email" href="mailto:[email protected]">[email protected]</a>.
</p>
<p>Send email to <a class="email" href="mailto:[email protected]">[email protected]</a> to send a message to
everyone on the R-help mailing list.  Subscription and posting to the
other lists is done analogously, with &lsquo;<samp class="samp">R-help</samp>&rsquo; replaced by
&lsquo;<samp class="samp">R-announce</samp>&rsquo;, &lsquo;<samp class="samp">R-packages</samp>&rsquo;, and &lsquo;<samp class="samp">R-devel</samp>&rsquo;, respectively.
Note that the R-announce and R-packages lists are gatewayed into R-help.
Hence, you should subscribe to either of them only in case you are not
subscribed to R-help.
</p>
<p>It is recommended that you send mail to R-help rather than only to the R
Core developers (who are also subscribed to the list, of course).  This
may save them precious time they can use for constantly improving R, and
will typically also result in much quicker feedback for yourself.
</p>
<p>Of course, in the case of bug reports it would be very helpful to have
code which reliably reproduces the problem.  Also, make sure that you
include information on the system and version of R being used.  See
<a class="ref" href="#R-Bugs">R Bugs</a> for more details.
</p>
<p>See <a class="url" href="https://www.R-project.org/mail.html">https://www.R-project.org/mail.html</a> for more information on
the R mailing lists.
</p>


<hr>
</div>
<div class="section-level-extent" id="What-is-CRAN_003f">
<div class="nav-panel">
<p>
Next: <a href="#Can-I-use-R-for-commercial-purposes_003f" accesskey="n" rel="next">Can I use R for commercial purposes?</a>, Previous: <a href="#What-mailing-lists-exist-for-R_003f" accesskey="p" rel="prev">What mailing lists exist for R?</a>, Up: <a href="#R-Basics" accesskey="u" rel="up">R Basics</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
</div>
<h3 class="section" id="What-is-CRAN_003f-1"><span>2.10 What is <abbr class="acronym">CRAN</abbr>?<a class="copiable-link" href="#What-is-CRAN_003f-1"> &para;</a></span></h3>

<p>The &ldquo;Comprehensive R Archive Network&rdquo; (<abbr class="acronym">CRAN</abbr>) is a collection of
sites which carry identical material, consisting of the R
distribution(s), the contributed extensions, documentation for R, and
binaries.
</p>
<p>The <abbr class="acronym">CRAN</abbr> main site at WU (Wirtschaftsuniversit&auml;t Wien) in Austria
can be found at the <abbr class="acronym">URL</abbr>
</p>
<blockquote class="quotation">
<p><a class="url" href="https://CRAN.R-project.org/">https://CRAN.R-project.org/</a>
</p></blockquote>

<p>and is mirrored daily to many sites around the world.
See <a class="url" href="https://CRAN.R-project.org/mirrors.html">https://CRAN.R-project.org/mirrors.html</a> for a complete list of
mirrors.  Please use the <abbr class="acronym">CRAN</abbr> site closest to you to reduce network
load.
</p>
<p>From <abbr class="acronym">CRAN</abbr>, you can obtain the latest official release of R, daily
snapshots of R (copies of the current source trees), as gzipped and
bzipped tar files, a wealth of additional contributed code, as well as
prebuilt binaries for various operating systems (Linux, Mac OS Classic,
macOS, and MS Windows).  <abbr class="acronym">CRAN</abbr> also provides access to
documentation on R, existing mailing lists and the R Bug Tracking
system.
</p>
<p>Since March 2016, &ldquo;old&rdquo; material is made available from a central
<abbr class="acronym">CRAN</abbr> archive server (<a class="url" href="https://CRAN-archive.R-project.org/">https://CRAN-archive.R-project.org/</a>).
</p>
<p>Please always use the <abbr class="acronym">URL</abbr> of the master site when referring to
<abbr class="acronym">CRAN</abbr>.
</p>
<hr>
</div>
<div class="section-level-extent" id="Can-I-use-R-for-commercial-purposes_003f">
<div class="nav-panel">
<p>
Next: <a href="#Why-is-R-named-R_003f" accesskey="n" rel="next">Why is R named R?</a>, Previous: <a href="#What-is-CRAN_003f" accesskey="p" rel="prev">What is <abbr class="acronym">CRAN</abbr>?</a>, Up: <a href="#R-Basics" accesskey="u" rel="up">R Basics</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
</div>
<h3 class="section" id="Can-I-use-R-for-commercial-purposes_003f-1"><span>2.11 Can I use R for commercial purposes?<a class="copiable-link" href="#Can-I-use-R-for-commercial-purposes_003f-1"> &para;</a></span></h3>

<p>R is released under the
<a class="url" href="https://www.gnu.org/licenses/old-licenses/gpl-2.0.html"><abbr class="acronym">GNU</abbr> General Public License (<abbr class="acronym">GPL</abbr>), version 2 or
version 3</a>.  If you have any questions regarding the legality of using R
in any particular situation you should bring it up with your legal
counsel.  We are in no position to offer legal advice.
</p>
<p>It is the opinion of the R Core Team that one can use R for commercial
purposes (e.g., in business or in consulting).  The <abbr class="acronym">GPL</abbr>, like
all Open Source licenses, permits all and any use of the package.  It
only restricts distribution of R or of other programs containing code
from R.  This is made clear in clause 6 (&ldquo;No Discrimination Against
Fields of Endeavor&rdquo;) of the
<a class="url" href="https://opensource.org/osd">Open Source Definition</a>:
</p>
<blockquote class="quotation">
<p>The license must not restrict anyone from making use of the program in a
specific field of endeavor.  For example, it may not restrict the
program from being used in a business, or from being used for genetic
research.
</p></blockquote>

<p>It is also explicitly stated in clause 0 of the GPL, which says in part
</p>
<blockquote class="quotation">
<p>Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope.  The act of running
the Program is not restricted, and the output from the Program is
covered only if its contents constitute a work based on the Program.
</p></blockquote>

<p>Most add-on packages, including all recommended ones, also explicitly
allow commercial use in this way.  A few packages are restricted to
&ldquo;non-commercial use&rdquo;; you should contact the author to clarify whether
these may be used or seek the advice of your legal counsel.
</p>
<p>None of the discussion in this section constitutes legal advice.  The R
Core Team does not provide legal advice under any circumstances.
</p>
<hr>
</div>
<div class="section-level-extent" id="Why-is-R-named-R_003f">
<div class="nav-panel">
<p>
Next: <a href="#What-is-the-R-Foundation_003f" accesskey="n" rel="next">What is the R Foundation?</a>, Previous: <a href="#Can-I-use-R-for-commercial-purposes_003f" accesskey="p" rel="prev">Can I use R for commercial purposes?</a>, Up: <a href="#R-Basics" accesskey="u" rel="up">R Basics</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
</div>
<h3 class="section" id="Why-is-R-named-R_003f-1"><span>2.12 Why is R named R?<a class="copiable-link" href="#Why-is-R-named-R_003f-1"> &para;</a></span></h3>

<p>The name is partly based on the (first) names of the first two R authors
(Robert Gentleman and Ross Ihaka), and partly a play on the name of the
Bell Labs language &lsquo;S&rsquo; (see <a class="pxref" href="#What-is-S_003f">What is S?</a>).
</p>

<hr>
</div>
<div class="section-level-extent" id="What-is-the-R-Foundation_003f">
<div class="nav-panel">
<p>
Next: <a href="#What-is-R_002dForge_003f" accesskey="n" rel="next">What is R-Forge?</a>, Previous: <a href="#Why-is-R-named-R_003f" accesskey="p" rel="prev">Why is R named R?</a>, Up: <a href="#R-Basics" accesskey="u" rel="up">R Basics</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
</div>
<h3 class="section" id="What-is-the-R-Foundation_003f-1"><span>2.13 What is the R Foundation?<a class="copiable-link" href="#What-is-the-R-Foundation_003f-1"> &para;</a></span></h3>

<p>The R Foundation is a not for profit organization working in the public
interest.  It was founded by the members of the R Core Team in order to
provide support for the R project and other innovations in statistical
computing, provide a reference point for individuals, institutions or
commercial enterprises that want to support or interact with the R
development community, and to hold and administer the copyright of R
software and documentation.  See
<a class="url" href="https://www.R-project.org/foundation/">https://www.R-project.org/foundation/</a> for more information.
</p>
<hr>
</div>
<div class="section-level-extent" id="What-is-R_002dForge_003f">
<div class="nav-panel">
<p>
Previous: <a href="#What-is-the-R-Foundation_003f" accesskey="p" rel="prev">What is the R Foundation?</a>, Up: <a href="#R-Basics" accesskey="u" rel="up">R Basics</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
</div>
<h3 class="section" id="What-is-R_002dForge_003f-1"><span>2.14 What is R-Forge?<a class="copiable-link" href="#What-is-R_002dForge_003f-1"> &para;</a></span></h3>

<p>R-Forge (<a class="url" href="https://R-Forge.R-project.org/">https://R-Forge.R-project.org/</a>) offers a central platform
for the development of R packages, R-related software and further
projects.  It is based on <a class="url" href="https://en.wikipedia.org/wiki/GForge">GForge</a> offering
easy access to the best in SVN, daily built and checked packages,
mailing lists, bug tracking, message boards/forums, site hosting,
permanent file archival, full backups, and total web-based
administration.  For more information, see the R-Forge web page and
Stefan Theu&szlig;l and Achim Zeileis (2009), &ldquo;Collaborative software
development using R-Forge&rdquo;, <a class="url" href="https://journal.R-project.org/"><em class="emph">The R Journal</em></a>, <strong class="strong">1</strong>(1):9&ndash;14.
</p>

<hr>
</div>
</div>
<div class="chapter-level-extent" id="R-and-S">
<div class="nav-panel">
<p>
Next: <a href="#R-Web-Interfaces" accesskey="n" rel="next">R Web Interfaces</a>, Previous: <a href="#R-Basics" accesskey="p" rel="prev">R Basics</a>, Up: <a href="#Top" accesskey="u" rel="up">R FAQ</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
</div>
<h2 class="chapter" id="R-and-S-1"><span>3 R and S<a class="copiable-link" href="#R-and-S-1"> &para;</a></span></h2>


<ul class="mini-toc">
<li><a href="#What-is-S_003f" accesskey="1">What is S?</a></li>
<li><a href="#What-is-S_002dPLUS_003f" accesskey="2">What is <small class="sc">S-PLUS</small>?</a></li>
<li><a href="#What-are-the-differences-between-R-and-S_003f" accesskey="3">What are the differences between R and S?</a></li>
<li><a href="#Is-there-anything-R-can-do-that-S_002dPLUS-cannot_003f" accesskey="4">Is there anything R can do that <small class="sc">S-PLUS</small> cannot?</a></li>
<li><a href="#What-is-R_002dplus_003f" accesskey="5">What is R-plus?</a></li>
</ul>
<hr>
<div class="section-level-extent" id="What-is-S_003f">
<div class="nav-panel">
<p>
Next: <a href="#What-is-S_002dPLUS_003f" accesskey="n" rel="next">What is <small class="sc">S-PLUS</small>?</a>, Previous: <a href="#R-and-S" accesskey="p" rel="prev">R and S</a>, Up: <a href="#R-and-S" accesskey="u" rel="up">R and S</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
</div>
<h3 class="section" id="What-is-S_003f-1"><span>3.1 What is S?<a class="copiable-link" href="#What-is-S_003f-1"> &para;</a></span></h3>

<p>S is a very high level language and an environment for data analysis and
graphics.  In 1998, the Association for Computing Machinery
(<abbr class="abbr">ACM</abbr>) presented its Software System Award to John M. Chambers,
the principal designer of S, for
</p>
<blockquote class="quotation">
<p>the S system, which has forever altered the way people analyze,
visualize, and manipulate data &hellip;
</p>
<p>S is an elegant, widely accepted, and enduring software system, with
conceptual integrity, thanks to the insight, taste, and effort of John
Chambers.
</p></blockquote>

<p>The evolution of the S language is characterized by four books by John
Chambers and coauthors, which are also the primary references for S.
</p>
<ul class="itemize mark-bullet">
<li>Richard A. Becker and John M. Chambers (1984),
&ldquo;S.  An Interactive Environment for Data Analysis and Graphics,&rdquo;
Monterey: Wadsworth and Brooks/Cole.

<p>This is also referred to as the &ldquo;<em class="emph">Brown Book</em>&rdquo;, and of historical
interest only.
</p>
</li><li>Richard A. Becker, John M. Chambers and Allan R. Wilks (1988),
&ldquo;The New S Language,&rdquo;
London: Chapman &amp; Hall.

<p>This book is often called the &ldquo;<em class="emph">Blue Book</em>&rdquo;, and introduced what
is now known as S version 2.
</p>
</li><li>John M. Chambers and Trevor J. Hastie (1992),
&ldquo;Statistical Models in S,&rdquo;
 London: Chapman &amp; Hall.

<p>This is also called the &ldquo;<em class="emph">White Book</em>&rdquo;, and introduced S version
3, which added structures to facilitate statistical modeling in S.
</p>
</li><li>John M. Chambers (1998), 
&ldquo;Programming with Data,&rdquo;
New York: Springer,
ISBN 0-387-98503-4
(<a class="url" href="https://johnmchambers.su.domains/Sbook/">https://johnmchambers.su.domains/Sbook/</a>).

<p>This &ldquo;<em class="emph">Green Book</em>&rdquo; describes version 4 of S, a major revision of
S designed by John Chambers to improve its usefulness at every stage
of the programming process.
</p></li></ul>

<p>See <a class="url" href="https://johnmchambers.su.domains/papers/96.7.ps">https://johnmchambers.su.domains/papers/96.7.ps</a>
for further information on the &ldquo;Evolution of the S Language&rdquo;.
</p>


<hr>
</div>
<div class="section-level-extent" id="What-is-S_002dPLUS_003f">
<div class="nav-panel">
<p>
Next: <a href="#What-are-the-differences-between-R-and-S_003f" accesskey="n" rel="next">What are the differences between R and S?</a>, Previous: <a href="#What-is-S_003f" accesskey="p" rel="prev">What is S?</a>, Up: <a href="#R-and-S" accesskey="u" rel="up">R and S</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
</div>
<h3 class="section" id="What-is-S_002dPlus_003f"><span>3.2 What is <small class="sc">S-PLUS</small>?<a class="copiable-link" href="#What-is-S_002dPlus_003f"> &para;</a></span></h3>

<p><small class="sc">S-PLUS</small> is a value-added version of S sold by
<a class="url" href="https://www.tibco.com/">TIBCO Software Inc</a> as &lsquo;TIBCO Spotfire S+&rsquo;.
See <a class="url" href="https://en.wikipedia.org/wiki/S-PLUS">https://en.wikipedia.org/wiki/S-PLUS</a> for more information.
</p>
<hr>
</div>
<div class="section-level-extent" id="What-are-the-differences-between-R-and-S_003f">
<div class="nav-panel">
<p>
Next: <a href="#Is-there-anything-R-can-do-that-S_002dPLUS-cannot_003f" accesskey="n" rel="next">Is there anything R can do that <small class="sc">S-PLUS</small> cannot?</a>, Previous: <a href="#What-is-S_002dPLUS_003f" accesskey="p" rel="prev">What is <small class="sc">S-PLUS</small>?</a>, Up: <a href="#R-and-S" accesskey="u" rel="up">R and S</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
</div>
<h3 class="section" id="What-are-the-differences-between-R-and-S_003f-1"><span>3.3 What are the differences between R and S?<a class="copiable-link" href="#What-are-the-differences-between-R-and-S_003f-1"> &para;</a></span></h3>

<p>We can regard S as a language with three current implementations or
&ldquo;engines&rdquo;, the &ldquo;old S engine&rdquo; (S version 3; <small class="sc">S-PLUS</small> 3.x and 4.x),
the &ldquo;new S engine&rdquo; (S version 4; <small class="sc">S-PLUS</small> 5.x and above), and R.
Given this understanding, asking for &ldquo;the differences between R and S&rdquo;
really amounts to asking for the specifics of the R implementation of
the S language, i.e., the difference between the R and S <em class="emph">engines</em>.
</p>
<p>For the remainder of this section, &ldquo;S&rdquo; refers to the S engines and not
the S language.
</p>

<ul class="mini-toc">
<li><a href="#Lexical-scoping" accesskey="1">Lexical scoping</a></li>
<li><a href="#Models" accesskey="2">Models</a></li>
<li><a href="#Others" accesskey="3">Others</a></li>
</ul>
<hr>
<div class="subsection-level-extent" id="Lexical-scoping">
<div class="nav-panel">
<p>
Next: <a href="#Models" accesskey="n" rel="next">Models</a>, Previous: <a href="#What-are-the-differences-between-R-and-S_003f" accesskey="p" rel="prev">What are the differences between R and S?</a>, Up: <a href="#What-are-the-differences-between-R-and-S_003f" accesskey="u" rel="up">What are the differences between R and S?</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
</div>
<h4 class="subsection" id="Lexical-scoping-1"><span>3.3.1 Lexical scoping<a class="copiable-link" href="#Lexical-scoping-1"> &para;</a></span></h4>

<p>Contrary to other implementations of the S language, R has adopted an
evaluation model in which nested function definitions are lexically
scoped.  This is analogous to the evaluation model in Scheme.
</p>
<p>This difference becomes manifest when <em class="emph">free</em> variables occur in a
function.  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).  In S, the
values of free variables are determined by a set of global variables
(similar to C, there is only local and global scope).  In R, they are
determined by the environment in which the function was created.
</p>
<p>Consider the following function:
</p>
<div class="example">
<div class="group"><pre class="example-preformatted">cube &lt;- function(n) {
  sq &lt;- function() n * n
  n * sq()
}
</pre></div></div>

<p>Under S, <code class="code">sq()</code> does not &ldquo;know&rdquo; about the variable <code class="code">n</code>
unless it is defined globally:
</p>
<div class="example">
<div class="group"><pre class="example-preformatted">S&gt; cube(2)
Error in sq():  Object &quot;n&quot; not found
Dumped
S&gt; n &lt;- 3
S&gt; cube(2)
[1] 18
</pre></div></div>

<p>In R, the &ldquo;environment&rdquo; created when <code class="code">cube()</code> was invoked is
also looked in:
</p>
<div class="example">
<div class="group"><pre class="example-preformatted">R&gt; cube(2)
[1] 8
</pre></div></div>







<p>As a more &ldquo;interesting&rdquo; real-world problem, suppose you want to write
a function which returns the density function of the <em class="math">r</em>-th order
statistic from a sample of size <em class="math">n</em> from a (continuous)
distribution.  For simplicity, we shall use both the distribution and
density functions distribution as explicit arguments.  (Example compiled
from various postings by Luke Tierney.)
</p>
<p>The <small class="sc">S-PLUS</small> documentation for <code class="code">call()</code> basically suggests the
following:
</p>
<div class="example">
<div class="group"><pre class="example-preformatted">dorder &lt;- function(n, r, pfun, dfun) {
  f &lt;- function(x) NULL
  con &lt;- round(exp(lgamma(n + 1) - lgamma(r) - lgamma(n - r + 1)))
  PF &lt;- call(substitute(pfun), as.name(&quot;x&quot;))
  DF &lt;- call(substitute(dfun), as.name(&quot;x&quot;))
  f[[length(f)]] &lt;-
    call(&quot;*&quot;, con,
         call(&quot;*&quot;, call(&quot;^&quot;, PF, r - 1),
              call(&quot;*&quot;, call(&quot;^&quot;, call(&quot;-&quot;, 1, PF), n - r),
                   DF)))
  f
}
</pre></div></div>

<p>Rather tricky, isn&rsquo;t it?  The code uses the fact that in S,
functions are just lists of special mode with the function body as the
last argument, and hence does not work in R (one could make the idea
work, though).
</p>
<p>A version which makes heavy use of <code class="code">substitute()</code> and seems to work
under both S and R is
</p>
<div class="example">
<div class="group"><pre class="example-preformatted">dorder &lt;- function(n, r, pfun, dfun) {
  con &lt;- 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></div></div>

<p>(the <code class="code">eval()</code> is not needed in S).
</p>
<p>However, in R there is a much easier solution:
</p>
<div class="example">
<div class="group"><pre class="example-preformatted">dorder &lt;- function(n, r, pfun, dfun) {
  con &lt;- 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></div></div>

<p>This seems to be the &ldquo;natural&rdquo; implementation, and it works because
the free variables in the returned function can be looked up in the
defining environment (this is lexical scope).
</p>
<p>Note that what you really need is the function <em class="emph">closure</em>, i.e., the
body along with all variable bindings needed for evaluating it.  Since
in the above version, the free variables in the value function are not
modified, you can actually use it in S as well if you abstract out the
closure operation into a function <code class="code">MC()</code> (for &ldquo;make closure&rdquo;):
</p>
<div class="example">
<div class="group"><pre class="example-preformatted">dorder &lt;- function(n, r, pfun, dfun) {
  con &lt;- 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></div></div>

<p>Given the appropriate definitions of the closure operator, this works in
both R and S, and is much &ldquo;cleaner&rdquo; than a substitute/eval solution
(or one which overrules the default scoping rules by using explicit
access to evaluation frames, as is of course possible in both R and S).
</p>
<p>For R, <code class="code">MC()</code> simply is
</p>
<div class="example">
<pre class="example-preformatted">MC &lt;- function(f, env) f
</pre></div>

<p>(lexical scope!), a version for S is
</p>
<div class="example">
<div class="group"><pre class="example-preformatted">MC &lt;- function(f, env = NULL) {
  env &lt;- as.list(env)
  if (mode(f) != &quot;function&quot;)
    stop(paste(&quot;not a function:&quot;, f))
  if (length(env) &gt; 0 &amp;&amp; any(names(env) == &quot;&quot;))
    stop(paste(&quot;not all arguments are named:&quot;, env))
  fargs &lt;- if(length(f) &gt; 1) f[1:(length(f) - 1)] else NULL
  fargs &lt;- c(fargs, env)
  if (any(duplicated(names(fargs))))
    stop(paste(&quot;duplicated arguments:&quot;, paste(names(fargs)),
         collapse = &quot;, &quot;))
  fbody &lt;- f[length(f)]
  cf &lt;- c(fargs, fbody)
  mode(cf) &lt;- &quot;function&quot;
  return(cf)
}
</pre></div></div>

<p>Similarly, most optimization (or zero-finding) routines need some
arguments to be optimized over and have other parameters that depend on
the data but are fixed with respect to optimization.  With R scoping
rules, this is a trivial problem; simply make up the function with the
required definitions in the same environment and scoping takes care of
it.  With S, one solution is to add an extra parameter to the function
and to the optimizer to pass in these extras, which however can only
work if the optimizer supports this.
</p>
<p>Nested lexically scoped functions allow using function closures and
maintaining local state.  A simple example (taken from Abelson and
Sussman) is obtained by typing <kbd class="kbd">demo(&quot;scoping&quot;)</kbd> at the R prompt.
Further information is provided in the standard R reference &ldquo;R: A
Language for Data Analysis and Graphics&rdquo; (see <a class="pxref" href="#What-documentation-exists-for-R_003f">What documentation exists for R?</a>) and in Robert Gentleman and Ross Ihaka (2000), &ldquo;Lexical
Scope and Statistical Computing&rdquo;,
<em class="emph">Journal of
Computational and Graphical Statistics</em>, <strong class="strong">9</strong>, 491&ndash;508
(doi:&nbsp;<a class="url" href="https://doi.org/10.1080/10618600.2000.10474895">10.1080/10618600.2000.10474895</a>).
</p>
<p>Nested lexically scoped functions also imply a further major difference.
Whereas S stores all objects as separate files in a directory somewhere
(usually <samp class="file">.Data</samp> under the current directory), R does not.  All
objects in R are stored internally.  When R is started up it grabs a
piece of memory and uses it to store the objects.  R performs its own
memory management of this piece of memory, growing and shrinking its
size as needed.  Having everything in memory is necessary because it is
not really possible to externally maintain all relevant &ldquo;environments&rdquo;
of symbol/value pairs.  This difference also seems to make R
<em class="emph">faster</em> than S.
</p>
<p>The down side is that if R crashes you will lose all the work for the
current session.  Saving and restoring the memory &ldquo;images&rdquo; (the
functions and data stored in R&rsquo;s internal memory at any time) can be a
bit slow, especially if they are big.  In S this does not happen,
because everything is saved in disk files and if you crash nothing is
likely to happen to them.  (In fact, one might conjecture that the S
developers felt that the price of changing their approach to persistent
storage just to accommodate lexical scope was far too expensive.)
Hence, when doing important work, you might consider saving often (see
<a class="ref" href="#How-can-I-save-my-workspace_003f">How can I save my workspace?</a>) to safeguard against possible
crashes.  Other possibilities are logging your sessions, or have your R
commands stored in text files which can be read in using
<code class="code">source()</code>.
</p>
<blockquote class="quotation">
<p><b class="b">Note:</b> If you run R from within Emacs (see <a class="ref" href="#R-and-Emacs">R and Emacs</a>), you can save the
contents of the interaction buffer to a file and conveniently manipulate
it using <code class="code">ess-transcript-mode</code>, as well as save source copies of
all functions and data used.
</p></blockquote>

<hr>
</div>
<div class="subsection-level-extent" id="Models">
<div class="nav-panel">
<p>
Next: <a href="#Others" accesskey="n" rel="next">Others</a>, Previous: <a href="#Lexical-scoping" accesskey="p" rel="prev">Lexical scoping</a>, Up: <a href="#What-are-the-differences-between-R-and-S_003f" accesskey="u" rel="up">What are the differences between R and S?</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
</div>
<h4 class="subsection" id="Models-1"><span>3.3.2 Models<a class="copiable-link" href="#Models-1"> &para;</a></span></h4>

<p>There are some differences in the modeling code, such as
</p>
<ul class="itemize mark-bullet">
<li>Whereas in S, you would use <code class="code">lm(y ~ x^3)</code> to regress <code class="code">y</code> on
<code class="code">x^3</code>, in R, you have to insulate powers of numeric vectors (using
<code class="code">I()</code>), i.e., you have to use <code class="code">lm(y ~ I(x^3))</code>.
</li><li>The <abbr class="abbr">GLM</abbr> family objects are implemented differently in R and S.  The same
functionality is available but the components have different names.
</li><li>Option <code class="code">na.action</code> is set to <code class="code">&quot;na.omit&quot;</code> by default in R,
but not set in S.
</li><li>Terms objects are stored differently.  In S a terms object is an
expression with attributes, in R it is a formula with attributes.  The
attributes have the same names but are mostly stored differently.
</li><li>Finally, in R <code class="code">y ~ x + 0</code> is an alternative to <code class="code">y ~ x - 1</code> for
specifying a model with no intercept.  Models with no parameters at all
can be specified by <code class="code">y ~ 0</code>.
</li></ul>

<hr>
</div>
<div class="subsection-level-extent" id="Others">
<div class="nav-panel">
<p>
Previous: <a href="#Models" accesskey="p" rel="prev">Models</a>, Up: <a href="#What-are-the-differences-between-R-and-S_003f" accesskey="u" rel="up">What are the differences between R and S?</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
</div>
<h4 class="subsection" id="Others-1"><span>3.3.3 Others<a class="copiable-link" href="#Others-1"> &para;</a></span></h4>

<p>Apart from lexical scoping and its implications, R follows the S
language definition in the Blue and White Books as much as possible, and
hence really is an &ldquo;implementation&rdquo; of S.  There are some intentional
differences where the behavior of S is considered &ldquo;not clean&rdquo;.  In
general, the rationale is that R should help you detect programming
errors, while at the same time being as compatible as possible with S.
</p>
<p>Some known differences are the following.
</p>
<ul class="itemize mark-bullet">
<li>In R, if <code class="code">x</code> is a list, then <code class="code">x[i] &lt;- NULL</code> and <code class="code">x[[i]]
&lt;- NULL</code> remove the specified elements from <code class="code">x</code>.  The first of
these is incompatible with S, where it is a no-op.  (Note that you can
set elements to <code class="code">NULL</code> using <code class="code">x[i] &lt;- list(NULL)</code>.)


</li><li>In S, the functions named <code class="code">.First</code> and <code class="code">.Last</code> in the
<samp class="file">.Data</samp> directory can be used for customizing, as they are executed
at the very beginning and end of a session, respectively.

<p>In R, the startup mechanism is as follows.  Unless <samp class="option">--no-environ</samp>
was given on the command line, R searches for site and user files to
process for setting environment variables.  Then, R searches for a
site-wide startup profile unless the command line option
<samp class="option">--no-site-file</samp> was given.  This code is loaded in package
<strong class="strong">base</strong>.  Then, unless <samp class="option">--no-init-file</samp> was given, R
searches for a user profile file, and sources it into the user
workspace.  It then loads a saved image of the user workspace from
<samp class="file">.RData</samp> in case there is one (unless <samp class="option">--no-restore-data</samp> or
<samp class="option">--no-restore</samp> were specified).  Next, a function <code class="code">.First()</code>
is run if found on the search path.  Finally, function <code class="code">.First.sys</code>
in the <strong class="strong">base</strong> package is run.  When terminating an R session, by
default a function <code class="code">.Last</code> is run if found on the search path,
followed by <code class="code">.Last.sys</code>.  If needed, the functions <code class="code">.First()</code>
and <code class="code">.Last()</code> should be defined in the appropriate startup
profiles.  See the help pages for <code class="code">.First</code> and <code class="code">.Last</code> for
more details.
</p>
</li><li>In R, <code class="code">T</code> and <code class="code">F</code> are just variables being set to <code class="code">TRUE</code>
and <code class="code">FALSE</code>, respectively, but are not reserved words as in S and
hence can be overwritten by the user.  (This helps e.g. when you have
factors with levels <code class="code">&quot;T&quot;</code> or <code class="code">&quot;F&quot;</code>.)  Hence, when writing code
you should always use <code class="code">TRUE</code> and <code class="code">FALSE</code>.

</li><li>In R, <code class="code">dyn.load()</code> can only load <em class="emph">shared objects</em>, as created
for example by <kbd class="kbd">R CMD SHLIB</kbd>.

</li><li>In R, <code class="code">attach()</code> currently only works for lists and data frames,
but not for directories.  (In fact, <code class="code">attach()</code> also works for R
data files created with <code class="code">save()</code>, which is analogous to attaching
directories in S.)  Also, you cannot attach at position 1.

</li><li>Categories do not exist in R, and never will as they are deprecated now
in S.  Use factors instead.

</li><li>In R, <code class="code">For()</code> loops are not necessary and hence not supported.

</li><li>In R, <code class="code">assign()</code> uses the argument <samp class="option">envir=</samp> rather than
<samp class="option">where=</samp> as in S.

</li><li>The random number generators are different, and the seeds have different
length.

</li><li>R passes integer objects to C as <code class="code">int *</code> rather than <code class="code">long *</code>
as in S.

</li><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><li>By default, <code class="code">ls()</code> returns the names of the objects in the current
(under R) and global (under S) environment, respectively.  For example,
given

<div class="example">
<pre class="example-preformatted">x &lt;- 1; fun &lt;- function() {y &lt;- 1; ls()}
</pre></div>

<p>then <code class="code">fun()</code> returns <code class="code">&quot;y&quot;</code> in R and <code class="code">&quot;x&quot;</code> (together with
the rest of the global environment) in S.
</p>
</li><li>R allows for zero-extent matrices (and arrays, i.e., some elements of
the <code class="code">dim</code> attribute vector can be 0).  This has been determined a
useful feature as it helps reducing the need for special-case tests for
empty subsets.  For example, if <code class="code">x</code> is a matrix, <code class="code">x[, FALSE]</code>
is not <code class="code">NULL</code> but a &ldquo;matrix&rdquo; with 0 columns.  Hence, such objects
need to be tested for by checking whether their <code class="code">length()</code> is zero
(which works in both R and S), and not using <code class="code">is.null()</code>.

</li><li>Named vectors are considered vectors in R but not in S (e.g.,
<code class="code">is.vector(c(a = 1:3))</code> returns <code class="code">FALSE</code> in S and <code class="code">TRUE</code>
in R).

</li><li>Data frames are not considered as matrices in R (i.e., if <code class="code">DF</code> is a
data frame, then <code class="code">is.matrix(DF)</code> returns <code class="code">FALSE</code> in R and
<code class="code">TRUE</code> in S).

</li><li>R by default uses treatment contrasts in the unordered case, whereas S
uses the Helmert ones.  This is a deliberate difference reflecting the
opinion that treatment contrasts are more natural.

</li><li>In R, the argument of a replacement function which corresponds to the
right hand side must be named &lsquo;<samp class="samp">value</samp>&rsquo;.  E.g., <code class="code">f(a) &lt;- b</code> is
evaluated as <code class="code">a &lt;- &quot;f&lt;-&quot;(a, value = b)</code>.  S always takes the last
argument, irrespective of its name.

</li><li>In S, <code class="code">substitute()</code> searches for names for substitution in the
given expression in three places: the actual and the default arguments
of the matching call, and the local frame (in that order).  R looks in
the local frame only, with the special rule to use a &ldquo;promise&rdquo; if a
variable is not evaluated.  Since the local frame is initialized with
the actual arguments or the default expressions, this is usually
equivalent to S, until assignment takes place.

</li><li>In S, the index variable in a <code class="code">for()</code> loop is local to the inside
of the loop.  In R it is local to the environment where the <code class="code">for()</code>
statement is executed.

</li><li>In S, <code class="code">tapply(simplify=TRUE)</code> returns a vector where R returns a
one-dimensional array (which can have named dimnames).

</li><li>In S(-<small class="sc">PLUS</small>) the C locale is used, whereas in R the current
operating system locale is used for determining which characters are
alphanumeric and how they are sorted.  This affects the set of valid
names for R objects (for example accented chars may be allowed in R) and
ordering in sorts and comparisons (such as whether <code class="code">&quot;aA&quot; &lt; &quot;Bb&quot;</code> is
true or false).  From version 1.2.0 the locale can be (re-)set in R by
the <code class="code">Sys.setlocale()</code> function.

</li><li>In S, <code class="code">missing(<var class="var">arg</var>)</code> remains <code class="code">TRUE</code> if <var class="var">arg</var> is
subsequently modified; in R it doesn&rsquo;t.

</li><li>From R version 1.3.0, <code class="code">data.frame</code> strips <code class="code">I()</code> when creating
(column) names.

</li><li>In R, the string <code class="code">&quot;NA&quot;</code> is not treated as a missing value in a
character variable.  Use <code class="code">as.character(NA)</code> to create a missing
character value.

</li><li>R disallows repeated formal arguments in function calls.

</li><li>In S, <code class="code">dump()</code>, <code class="code">dput()</code> and <code class="code">deparse()</code> are essentially
different interfaces to the same code.  In R from version 2.0.0, this is
only true if the same <code class="code">control</code> argument is used, but by default it
is not.  By default <code class="code">dump()</code> tries to write code that will evaluate
to reproduce the object, whereas <code class="code">dput()</code> and <code class="code">deparse()</code>
default to options for producing deparsed code that is readable.

</li><li>In R, indexing a vector, matrix, array or data frame with <code class="code">[</code> using
a character vector index looks only for exact matches (whereas <code class="code">[[</code>
and <code class="code">$</code> allow partial matches).  In S, <code class="code">[</code> allows partial
matches.

</li><li>S has a two-argument version of <code class="code">atan</code> and no <code class="code">atan2</code>.  A call 
in S such as <code class="code">atan(x1, x2)</code> is equivalent to R&rsquo;s <code class="code">atan2(x1, 
x2)</code>.  However, beware of named arguments since S&rsquo;s <code class="code">atan(x = a, y
= b)</code> is equivalent to R&rsquo;s <code class="code">atan2(y = a, x = b)</code> with the meanings
of <code class="code">x</code> and <code class="code">y</code> interchanged.  (R used to have undocumented
support for a two-argument <code class="code">atan</code> with positional arguments, but
this has been withdrawn to avoid further confusion.)

</li><li>Numeric constants with no fractional and exponent (i.e., only integer)
part are taken as integer in <small class="sc">S-PLUS</small> 6.x or later, but as double in R.

</li></ul>

<p>There are also differences which are not intentional, and result from
missing or incorrect code in R.  The developers would appreciate hearing
about any deficiencies you may find (in a written report fully
documenting the difference as you see it).  Of course, it would be
useful if you were to implement the change yourself and make sure it
works.
</p>
<hr>
</div>
</div>
<div class="section-level-extent" id="Is-there-anything-R-can-do-that-S_002dPLUS-cannot_003f">
<div class="nav-panel">
<p>
Next: <a href="#What-is-R_002dplus_003f" accesskey="n" rel="next">What is R-plus?</a>, Previous: <a href="#What-are-the-differences-between-R-and-S_003f" accesskey="p" rel="prev">What are the differences between R and S?</a>, Up: <a href="#R-and-S" accesskey="u" rel="up">R and S</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
</div>
<h3 class="section" id="Is-there-anything-R-can-do-that-S_002dPlus-cannot_003f"><span>3.4 Is there anything R can do that <small class="sc">S-PLUS</small> cannot?<a class="copiable-link" href="#Is-there-anything-R-can-do-that-S_002dPlus-cannot_003f"> &para;</a></span></h3>

<p>Since almost anything you can do in R has source code that you could
port to <small class="sc">S-PLUS</small> with little effort there will never be much you can do
in R that you couldn&rsquo;t do in <small class="sc">S-PLUS</small> if you wanted to.  (Note that
using lexical scoping may simplify matters considerably, though.)
</p>
<p>R offers several graphics features that <small class="sc">S-PLUS</small> does not, such as finer
handling of line types, more convenient color handling (via palettes),
gamma correction for color, and, most importantly, mathematical
annotation in plot texts, via input expressions reminiscent of TeX
constructs.  See the help page for <code class="code">plotmath</code>, which features an
impressive on-line example.  More details can be found in 
Paul Murrell and Ross Ihaka (2000),
&ldquo;An Approach to Providing Mathematical Annotation in Plots&rdquo;, 
<em class="emph">Journal of Computational and Graphical Statistics</em>, <strong class="strong">9</strong>, 582&ndash;599
(doi:&nbsp;<a class="url" href="https://doi.org/10.1080/10618600.2000.10474900">10.1080/10618600.2000.10474900</a>).
</p>
<hr>
</div>
<div class="section-level-extent" id="What-is-R_002dplus_003f">
<div class="nav-panel">
<p>
Previous: <a href="#Is-there-anything-R-can-do-that-S_002dPLUS-cannot_003f" accesskey="p" rel="prev">Is there anything R can do that <small class="sc">S-PLUS</small> cannot?</a>, Up: <a href="#R-and-S" accesskey="u" rel="up">R and S</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
</div>
<h3 class="section" id="What-is-R_002dplus_003f-1"><span>3.5 What is R-plus?<a class="copiable-link" href="#What-is-R_002dplus_003f-1"> &para;</a></span></h3>

<p>For a very long time, there was no such thing.
</p>

<p>Revolution Analytics has released REvolution R, now available as
Microsoft R (see
<a class="url" href="https://blog.revolutionanalytics.com/2016/01/microsoft-r-open.html">https://blog.revolutionanalytics.com/2016/01/microsoft-r-open.html</a>
for more information).
</p>

<p>See also
<a class="url" href="https://en.wikipedia.org/wiki/R_programming_language#Commercialized_versions_of_R">https://en.wikipedia.org/wiki/R_programming_language#Commercialized_versions_of_R</a>
for pointers to commercialized versions of R.
</p>
<hr>
</div>
</div>
<div class="chapter-level-extent" id="R-Web-Interfaces">
<div class="nav-panel">
<p>
Next: <a href="#R-Add_002dOn-Packages" accesskey="n" rel="next">R Add-On Packages</a>, Previous: <a href="#R-and-S" accesskey="p" rel="prev">R and S</a>, Up: <a href="#Top" accesskey="u" rel="up">R FAQ</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
</div>
<h2 class="chapter" id="R-Web-Interfaces-1"><span>4 R Web Interfaces<a class="copiable-link" href="#R-Web-Interfaces-1"> &para;</a></span></h2>

<p>Please refer to the <abbr class="acronym">CRAN</abbr> task view on &ldquo;Web Technologies and
Services&rdquo; (<a class="url" href="https://CRAN.R-project.org/view=WebTechnologies">https://CRAN.R-project.org/view=WebTechnologies</a>),
specifically section &ldquo;Web and Server Frameworks&rdquo;, for up-to-date
information on R web interface packages.
</p>
<p>Early references on R web interfaces include
Jeff Banfield (1999),
&ldquo;Rweb: Web-based Statistical Analysis&rdquo;
(doi:&nbsp;<a class="url" href="https://doi.org/10.18637/jss.v004.i01">10.18637/jss.v004.i01</a>),
David Firth (2003),
&ldquo;CGIwithR: Facilities for processing web forms using R&rdquo;
(doi:&nbsp;<a class="url" href="https://doi.org/10.18637/jss.v008.i10">10.18637/jss.v008.i10</a>),
and
Angelo Mineo and Alfredo Pontillo (2006),
&ldquo;Using R via PHP for Teaching Purposes: R-php&rdquo;
(doi:&nbsp;<a class="url" href="https://doi.org/10.18637/jss.v017.i04">10.18637/jss.v017.i04</a>).
</p>
<hr>
</div>
<div class="chapter-level-extent" id="R-Add_002dOn-Packages">
<div class="nav-panel">
<p>
Next: <a href="#R-and-Emacs" accesskey="n" rel="next">R and Emacs</a>, Previous: <a href="#R-Web-Interfaces" accesskey="p" rel="prev">R Web Interfaces</a>, Up: <a href="#Top" accesskey="u" rel="up">R FAQ</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
</div>
<h2 class="chapter" id="R-Add_002dOn-Packages-1"><span>5 R Add-On Packages<a class="copiable-link" href="#R-Add_002dOn-Packages-1"> &para;</a></span></h2>


<ul class="mini-toc">
<li><a href="#Which-add_002don-packages-exist-for-R_003f" accesskey="1">Which add-on packages exist for R?</a></li>
<li><a href="#How-can-add_002don-packages-be-installed_003f" accesskey="2">How can add-on packages be installed?</a></li>
<li><a href="#How-can-add_002don-packages-be-used_003f" accesskey="3">How can add-on packages be used?</a></li>
<li><a href="#How-can-add_002don-packages-be-removed_003f" accesskey="4">How can add-on packages be removed?</a></li>
<li><a href="#How-can-I-create-an-R-package_003f" accesskey="5">How can I create an R package?</a></li>
<li><a href="#How-can-I-contribute-to-R_003f" accesskey="6">How can I contribute to R?</a></li>
</ul>
<hr>
<div class="section-level-extent" id="Which-add_002don-packages-exist-for-R_003f">
<div class="nav-panel">
<p>
Next: <a href="#How-can-add_002don-packages-be-installed_003f" accesskey="n" rel="next">How can add-on packages be installed?</a>, Previous: <a href="#R-Add_002dOn-Packages" accesskey="p" rel="prev">R Add-On Packages</a>, Up: <a href="#R-Add_002dOn-Packages" accesskey="u" rel="up">R Add-On Packages</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
</div>
<h3 class="section" id="Which-add_002don-packages-exist-for-R_003f-1"><span>5.1 Which add-on packages exist for R?<a class="copiable-link" href="#Which-add_002don-packages-exist-for-R_003f-1"> &para;</a></span></h3>


<ul class="mini-toc">
<li><a href="#Add_002don-packages-in-R" accesskey="1">Add-on packages in R</a></li>
<li><a href="#Add_002don-packages-from-CRAN" accesskey="2">Add-on packages from <abbr class="acronym">CRAN</abbr></a></li>
<li><a href="#Add_002don-packages-from-Bioconductor" accesskey="3">Add-on packages from Bioconductor</a></li>
<li><a href="#Other-add_002don-packages" accesskey="4">Other add-on packages</a></li>
</ul>
<hr>
<div class="subsection-level-extent" id="Add_002don-packages-in-R">
<div class="nav-panel">
<p>
Next: <a href="#Add_002don-packages-from-CRAN" accesskey="n" rel="next">Add-on packages from <abbr class="acronym">CRAN</abbr></a>, Previous: <a href="#Which-add_002don-packages-exist-for-R_003f" accesskey="p" rel="prev">Which add-on packages exist for R?</a>, Up: <a href="#Which-add_002don-packages-exist-for-R_003f" accesskey="u" rel="up">Which add-on packages exist for R?</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
</div>
<h4 class="subsection" id="Add_002don-packages-in-R-1"><span>5.1.1 Add-on packages in R<a class="copiable-link" href="#Add_002don-packages-in-R-1"> &para;</a></span></h4>

<p>The R distribution comes with the following packages:
</p>
<dl class="table">
<dt><strong class="strong">base</strong></dt>
<dd><p>Base R functions (and datasets before R 2.0.0).
</p></dd>
<dt><strong class="strong">compiler</strong></dt>
<dd><p>R byte code compiler (added in R 2.13.0).
</p></dd>
<dt><strong class="strong">datasets</strong></dt>
<dd><p>Base R datasets (added in R 2.0.0).
</p></dd>
<dt><strong class="strong">grDevices</strong></dt>
<dd><p>Graphics devices for base and grid graphics (added in R 2.0.0).
</p></dd>
<dt><strong class="strong">graphics</strong></dt>
<dd><p>R functions for base graphics.
</p></dd>
<dt><strong class="strong">grid</strong></dt>
<dd><p>A rewrite of the graphics layout capabilities, plus some support for
interaction.
</p></dd>
<dt><strong class="strong">methods</strong></dt>
<dd><p>Formally defined methods and classes for R objects, plus other
programming tools, as described in the Green Book.
</p></dd>
<dt><strong class="strong">parallel</strong></dt>
<dd><p>Support for parallel computation, including by forking and by sockets, 
and random-number generation (added in R 2.14.0).
</p></dd>
<dt><strong class="strong">splines</strong></dt>
<dd><p>Regression spline functions and classes.
</p></dd>
<dt><strong class="strong">stats</strong></dt>
<dd><p>R statistical functions.
</p></dd>
<dt><strong class="strong">stats4</strong></dt>
<dd><p>Statistical functions using S4 classes.
</p></dd>
<dt><strong class="strong">tcltk</strong></dt>
<dd><p>Interface and language bindings to Tcl/Tk <abbr class="acronym">GUI</abbr> elements.
</p></dd>
<dt><strong class="strong">tools</strong></dt>
<dd><p>Tools for package development and administration.
</p></dd>
<dt><strong class="strong">utils</strong></dt>
<dd><p>R utility functions.
</p></dd>
</dl>

<hr>
</div>
<div class="subsection-level-extent" id="Add_002don-packages-from-CRAN">
<div class="nav-panel">
<p>
Next: <a href="#Add_002don-packages-from-Bioconductor" accesskey="n" rel="next">Add-on packages from Bioconductor</a>, Previous: <a href="#Add_002don-packages-in-R" accesskey="p" rel="prev">Add-on packages in R</a>, Up: <a href="#Which-add_002don-packages-exist-for-R_003f" accesskey="u" rel="up">Which add-on packages exist for R?</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
</div>
<h4 class="subsection" id="Add_002don-packages-from-CRAN-1"><span>5.1.2 Add-on packages from <abbr class="acronym">CRAN</abbr><a class="copiable-link" href="#Add_002don-packages-from-CRAN-1"> &para;</a></span></h4>

<p>The <abbr class="acronym">CRAN</abbr> <samp class="file">src/contrib</samp> area contains a wealth of add-on
packages, including the following <em class="emph">recommended</em> packages which are
to be included in all binary distributions of R.
</p>
<dl class="table">
<dt><strong class="strong">KernSmooth</strong></dt>
<dd><p>Functions for kernel smoothing (and density estimation) corresponding to
the book &ldquo;Kernel Smoothing&rdquo; by M. P. Wand and M. C. Jones, 1995.
</p></dd>
<dt><strong class="strong">MASS</strong></dt>
<dd><p>Functions and datasets from the main package of Venables and Ripley,
&ldquo;Modern Applied Statistics with S&rdquo;.
</p></dd>
<dt><strong class="strong">Matrix</strong></dt>
<dd><p>Support for spares and dense matrices
</p></dd>
<dt><strong class="strong">boot</strong></dt>
<dd><p>Functions and datasets for bootstrapping from the book &ldquo;Bootstrap
Methods and Their Applications&rdquo; by A. C. Davison and D. V. Hinkley,
1997, Cambridge University Press.
</p></dd>
<dt><strong class="strong">class</strong></dt>
<dd><p>Functions for classification (<em class="math">k</em>-nearest neighbor and <abbr class="abbr">LVQ</abbr>).
</p></dd>
<dt><strong class="strong">cluster</strong></dt>
<dd><p>Functions for cluster analysis.
</p></dd>
<dt><strong class="strong">codetools</strong></dt>
<dd><p>Code analysis tools.
</p></dd>
<dt><strong class="strong">foreign</strong></dt>
<dd><p>Functions for reading and writing data stored by statistical software
like Minitab, S, SAS, SPSS, Stata, Systat, etc.
</p></dd>
<dt><strong class="strong">lattice</strong></dt>
<dd><p>Lattice graphics, an implementation of Trellis Graphics functions.
</p></dd>
<dt><strong class="strong">mgcv</strong></dt>
<dd><p>Routines for GAMs<!-- /@w --> and other generalized ridge regression problems with
multiple smoothing parameter selection by GCV or <abbr class="abbr">UBRE</abbr>.
</p></dd>
<dt><strong class="strong">nlme</strong></dt>
<dd><p>Fit and compare Gaussian linear and nonlinear mixed-effects models.
</p></dd>
<dt><strong class="strong">nnet</strong></dt>
<dd><p>Software for single hidden layer perceptrons (&ldquo;feed-forward neural
networks&rdquo;), and for multinomial log-linear models.
</p></dd>
<dt><strong class="strong">rpart</strong></dt>
<dd><p>Recursive PARTitioning and regression trees.
</p></dd>
<dt><strong class="strong">spatial</strong></dt>
<dd><p>Functions for kriging and point pattern analysis from &ldquo;Modern Applied
Statistics with S&rdquo; by W. Venables and B. Ripley.
</p></dd>
<dt><strong class="strong">survival</strong></dt>
<dd><p>Functions for survival analysis, including penalized likelihood.
</p></dd>
</dl>
<p>See the <a class="url" href="https://CRAN.R-project.org/web/packages/"><abbr class="acronym">CRAN</abbr>
contributed packages page</a> for more information.
</p>
<p>Many of these packages are categorized into
<a class="url" href="https://CRAN.R-project.org/web/views/"><abbr class="acronym">CRAN</abbr> Task Views</a>, allowing
to browse packages by topic and providing tools to automatically install
all packages for special areas of interest.
</p>



<hr>
</div>
<div class="subsection-level-extent" id="Add_002don-packages-from-Bioconductor">
<div class="nav-panel">
<p>
Next: <a href="#Other-add_002don-packages" accesskey="n" rel="next">Other add-on packages</a>, Previous: <a href="#Add_002don-packages-from-CRAN" accesskey="p" rel="prev">Add-on packages from <abbr class="acronym">CRAN</abbr></a>, Up: <a href="#Which-add_002don-packages-exist-for-R_003f" accesskey="u" rel="up">Which add-on packages exist for R?</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
</div>
<h4 class="subsection" id="Add_002don-packages-from-Bioconductor-1"><span>5.1.3 Add-on packages from Bioconductor<a class="copiable-link" href="#Add_002don-packages-from-Bioconductor-1"> &para;</a></span></h4>

<p><a class="url" href="https://www.bioconductor.org/">Bioconductor</a> is an open source and
open development software project for the analysis and comprehension of
genomic data.  Most Bioconductor components are distributed as R add-on
packages.  Initially most of the
<a class="url" href="https://bioconductor.org/packages/release/BiocViews.html#___Software">Bioconductor software packages</a>
focused primarily on DNA microarray data analysis.  As the 
project has matured, the functional scope of the software packages
broadened to include the analysis of all types of genomic data, such as
SAGE, sequence, or SNP data.  In addition, there are metadata
(annotation, CDF and probe) and experiment data packages.  See
<a class="url" href="https://bioconductor.org/install/">https://bioconductor.org/install/</a> for available packages and a
complete taxonomy via BioC Views.
</p>
<hr>
</div>
<div class="subsection-level-extent" id="Other-add_002don-packages">
<div class="nav-panel">
<p>
Previous: <a href="#Add_002don-packages-from-Bioconductor" accesskey="p" rel="prev">Add-on packages from Bioconductor</a>, Up: <a href="#Which-add_002don-packages-exist-for-R_003f" accesskey="u" rel="up">Which add-on packages exist for R?</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
</div>
<h4 class="subsection" id="Other-add_002don-packages-1"><span>5.1.4 Other add-on packages<a class="copiable-link" href="#Other-add_002don-packages-1"> &para;</a></span></h4>

<p>Many more packages are available from places other than the default
repositories discussed above (<abbr class="acronym">CRAN</abbr> and Bioconductor).  In particular,
R-Forge provides a <abbr class="acronym">CRAN</abbr> style repository at
<a class="url" href="https://R-Forge.R-project.org/">https://R-Forge.R-project.org/</a>.
</p>
<p>More code has been posted to the R-help mailing list, and can be
obtained from the mailing list archive.
</p>
<hr>
</div>
</div>
<div class="section-level-extent" id="How-can-add_002don-packages-be-installed_003f">
<div class="nav-panel">
<p>
Next: <a href="#How-can-add_002don-packages-be-used_003f" accesskey="n" rel="next">How can add-on packages be used?</a>, Previous: <a href="#Which-add_002don-packages-exist-for-R_003f" accesskey="p" rel="prev">Which add-on packages exist for R?</a>, Up: <a href="#R-Add_002dOn-Packages" accesskey="u" rel="up">R Add-On Packages</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
</div>
<h3 class="section" id="How-can-add_002don-packages-be-installed_003f-1"><span>5.2 How can add-on packages be installed?<a class="copiable-link" href="#How-can-add_002don-packages-be-installed_003f-1"> &para;</a></span></h3>

<p>(Unix-like only.)  The add-on packages on <abbr class="acronym">CRAN</abbr> come as gzipped tar
files named <code class="code"><var class="var">pkg</var>_<var class="var">version</var>.tar.gz</code>.  Let <var class="var">path</var> be
the path to such a package file.  Provided that <code class="command">tar</code> and
<code class="command">gzip</code> are available on your system, type
</p>
<div class="example">
<pre class="example-preformatted">$ R CMD INSTALL <var class="var">path</var>/<var class="var">pkg</var>_<var class="var">version</var>.tar.gz
</pre></div>

<p>at the shell prompt to install to the library tree rooted at the first
directory in your library search path (see the help page for
<code class="code">.libPaths()</code> for details on how the search path is determined).
</p>
<p>To install to another tree (e.g., your private one), use
</p>
<div class="example">
<pre class="example-preformatted">$ R CMD INSTALL -l <var class="var">lib</var> <var class="var">path</var>/<var class="var">pkg</var>_<var class="var">version</var>.tar.gz
</pre></div>

<p>where <var class="var">lib</var> gives the path to the library tree to install to.
</p>
<p>Even more conveniently, you can install and automatically update
packages from within R if you have access to repositories such as
<abbr class="acronym">CRAN</abbr>.  See the help page for <code class="code">available.packages()</code> for more
information.
</p>





<hr>
</div>
<div class="section-level-extent" id="How-can-add_002don-packages-be-used_003f">
<div class="nav-panel">
<p>
Next: <a href="#How-can-add_002don-packages-be-removed_003f" accesskey="n" rel="next">How can add-on packages be removed?</a>, Previous: <a href="#How-can-add_002don-packages-be-installed_003f" accesskey="p" rel="prev">How can add-on packages be installed?</a>, Up: <a href="#R-Add_002dOn-Packages" accesskey="u" rel="up">R Add-On Packages</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
</div>
<h3 class="section" id="How-can-add_002don-packages-be-used_003f-1"><span>5.3 How can add-on packages be used?<a class="copiable-link" href="#How-can-add_002don-packages-be-used_003f-1"> &para;</a></span></h3>

<p>To find out which additional packages are available on your system, type
</p>
<div class="example">
<pre class="example-preformatted">library()
</pre></div>

<p>at the R prompt.  
</p>
<p>This produces something like
</p>
<blockquote class="quotation">
<table summary="" class="cartouche" border="1"><tr><td>
<div class="example smallexample">
<pre class="example-preformatted">Packages in ‘/home/me/lib/R’:

mystuff       My own R functions, nicely packaged but not documented

Packages in ‘/usr/local/lib/R/library’:

KernSmooth    Functions for kernel smoothing for Wand &amp; Jones (1995)
MASS          Support Functions and Datasets for Venables and Ripley's MASS
Matrix        Sparse and Dense Matrix Classes and Methods
base          The R Base package
boot          Bootstrap R (S-Plus) Functions (Canty)
boot          Bootstrap Functions (Originally by Angelo Canty for S)
class         Functions for Classification
cluster       &quot;Finding Groups in Data&quot;: Cluster Analysis Extended
              Rousseeuw et al.
codetools     Code Analysis Tools for R
datasets      The R Datasets Package
foreign       Read Data Stored by Minitab, S, SAS, SPSS, Stata, Systat,
              dBase, ...
grDevices     The R Graphics Devices and Support for Colours and Fonts
graphics      The R Graphics Package
grid          The Grid Graphics Package
lattice       Lattice Graphics
methods       Formal Methods and Classes
mgcv          GAMs with GCV/AIC/REML smoothness estimation and GAMMs
              by PQL
nlme          Linear and Nonlinear Mixed Effects Models
nnet          Feed-forward Neural Networks and Multinomial Log-Linear
              Models
rpart         Recursive Partitioning
spatial       Functions for Kriging and Point Pattern Analysis
splines       Regression Spline Functions and Classes
stats         The R Stats Package
stats4        Statistical functions using S4 Classes
survival      Survival analysis, including penalised likelihood
tcltk         Tcl/Tk Interface
tools         Tools for Package Development
utils         The R Utils Package
</pre></div>
</td></tr></table>
</blockquote>

<p>You can &ldquo;load&rdquo; the installed package <var class="var">pkg</var> by
</p>
<div class="example">
<pre class="example-preformatted">library(<var class="var">pkg</var>)
</pre></div>

<p>You can then find out which functions it provides by typing one of
</p>
<div class="example">
<pre class="example-preformatted">library(help = <var class="var">pkg</var>)
help(package = <var class="var">pkg</var>)
</pre></div>

<p>You can unload the loaded package <var class="var">pkg</var> by
</p>
<div class="example">
<pre class="example-preformatted">detach(&quot;package:<var class="var">pkg</var>&quot;, unload = TRUE)
</pre></div>

<p>(where <code class="code">unload = TRUE</code> is needed only for packages with a
namespace, see <code class="code">?unload</code>).
</p>
<hr>
</div>
<div class="section-level-extent" id="How-can-add_002don-packages-be-removed_003f">
<div class="nav-panel">
<p>
Next: <a href="#How-can-I-create-an-R-package_003f" accesskey="n" rel="next">How can I create an R package?</a>, Previous: <a href="#How-can-add_002don-packages-be-used_003f" accesskey="p" rel="prev">How can add-on packages be used?</a>, Up: <a href="#R-Add_002dOn-Packages" accesskey="u" rel="up">R Add-On Packages</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
</div>
<h3 class="section" id="How-can-add_002don-packages-be-removed_003f-1"><span>5.4 How can add-on packages be removed?<a class="copiable-link" href="#How-can-add_002don-packages-be-removed_003f-1"> &para;</a></span></h3>

<p>Use
</p>
<div class="example">
<pre class="example-preformatted">$ R CMD REMOVE <var class="var">pkg_1</var> ... <var class="var">pkg_n</var>
</pre></div>

<p>to remove the packages <var class="var">pkg_1</var>, &hellip;, <var class="var">pkg_n</var> from the
library tree rooted at the first directory given in <code class="env">R_LIBS</code> if this
is set and non-null, and from the default library otherwise.
</p>

<p>To remove from library <var class="var">lib</var>, do
</p>
<div class="example">
<pre class="example-preformatted">$ R CMD REMOVE -l <var class="var">lib</var> <var class="var">pkg_1</var> ... <var class="var">pkg_n</var>
</pre></div>

<hr>
</div>
<div class="section-level-extent" id="How-can-I-create-an-R-package_003f">
<div class="nav-panel">
<p>
Next: <a href="#How-can-I-contribute-to-R_003f" accesskey="n" rel="next">How can I contribute to R?</a>, Previous: <a href="#How-can-add_002don-packages-be-removed_003f" accesskey="p" rel="prev">How can add-on packages be removed?</a>, Up: <a href="#R-Add_002dOn-Packages" accesskey="u" rel="up">R Add-On Packages</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
</div>
<h3 class="section" id="How-can-I-create-an-R-package_003f-1"><span>5.5 How can I create an R package?<a class="copiable-link" href="#How-can-I-create-an-R-package_003f-1"> &para;</a></span></h3>

<p>A package consists of a subdirectory containing a file
<samp class="file">DESCRIPTION</samp> and the subdirectories <samp class="file">R</samp>, <samp class="file">data</samp>,
<samp class="file">demo</samp>, <samp class="file">exec</samp>, <samp class="file">inst</samp>, <samp class="file">man</samp>, <samp class="file">po</samp>,
<samp class="file">src</samp>, and <samp class="file">tests</samp> (some of which can be missing).  The
package subdirectory may also contain files <samp class="file">INDEX</samp>,
<samp class="file">NAMESPACE</samp>, <samp class="file">configure</samp>, <samp class="file">cleanup</samp>, <samp class="file">LICENSE</samp>,
<samp class="file">LICENCE</samp>, <samp class="file">COPYING</samp> and <samp class="file">NEWS</samp>.
</p>
<p>See <a data-manual="R-exts" href="https://cran.r-project.org/doc/manuals/R-exts.html#Creating-R-packages">Creating R packages</a> in <cite class="cite">Writing R Extensions</cite>,
for details.
</p>
<p>R version 1.3.0 has added the function <code class="code">package.skeleton()</code> which
will set up directories, save data and code, and create skeleton help
files for a set of R functions and datasets.
</p>
<p>See <a class="xref" href="#What-is-CRAN_003f">What is <abbr class="acronym">CRAN</abbr>?</a>, for information on uploading a package to <abbr class="acronym">CRAN</abbr>.
</p>
<hr>
</div>
<div class="section-level-extent" id="How-can-I-contribute-to-R_003f">
<div class="nav-panel">
<p>
Previous: <a href="#How-can-I-create-an-R-package_003f" accesskey="p" rel="prev">How can I create an R package?</a>, Up: <a href="#R-Add_002dOn-Packages" accesskey="u" rel="up">R Add-On Packages</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
</div>
<h3 class="section" id="How-can-I-contribute-to-R_003f-1"><span>5.6 How can I contribute to R?<a class="copiable-link" href="#How-can-I-contribute-to-R_003f-1"> &para;</a></span></h3>

<p>R is in active development and there is always a risk of bugs creeping
in.  Also, the developers do not have access to all possible machines
capable of running R.  So, simply using it and communicating problems is
certainly of great value.
</p>
<p>The <a class="url" href="https://developer.R-project.org/">R Developer Page</a> acts as an
intermediate repository for more or less finalized ideas and plans for
the R statistical system.  It contains (pointers to) TODO lists, RFCs,
various other writeups, ideas lists, and SVN miscellanea.
</p>
<hr>
</div>
</div>
<div class="chapter-level-extent" id="R-and-Emacs">
<div class="nav-panel">
<p>
Next: <a href="#R-Miscellanea" accesskey="n" rel="next">R Miscellanea</a>, Previous: <a href="#R-Add_002dOn-Packages" accesskey="p" rel="prev">R Add-On Packages</a>, Up: <a href="#Top" accesskey="u" rel="up">R FAQ</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
</div>
<h2 class="chapter" id="R-and-Emacs-1"><span>6 R and Emacs<a class="copiable-link" href="#R-and-Emacs-1"> &para;</a></span></h2>


<ul class="mini-toc">
<li><a href="#Is-there-Emacs-support-for-R_003f" accesskey="1">Is there Emacs support for R?</a></li>
<li><a href="#Should-I-run-R-from-within-Emacs_003f" accesskey="2">Should I run R from within Emacs?</a></li>
<li><a href="#Debugging-R-from-within-Emacs" accesskey="3">Debugging R from within Emacs</a></li>
</ul>
<hr>
<div class="section-level-extent" id="Is-there-Emacs-support-for-R_003f">
<div class="nav-panel">
<p>
Next: <a href="#Should-I-run-R-from-within-Emacs_003f" accesskey="n" rel="next">Should I run R from within Emacs?</a>, Previous: <a href="#R-and-Emacs" accesskey="p" rel="prev">R and Emacs</a>, Up: <a href="#R-and-Emacs" accesskey="u" rel="up">R and Emacs</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
</div>
<h3 class="section" id="Is-there-Emacs-support-for-R_003f-1"><span>6.1 Is there Emacs support for R?<a class="copiable-link" href="#Is-there-Emacs-support-for-R_003f-1"> &para;</a></span></h3>

<p>There is an Emacs package called <abbr class="acronym">ESS</abbr> (&ldquo;Emacs Speaks
Statistics&rdquo;) which provides a standard interface between statistical
programs and statistical processes.  It is intended to provide
assistance for interactive statistical programming and data analysis.
Languages supported include: S dialects (R, S 3/4, and <small class="sc">S-PLUS</small>
3.x/4.x/5.x/6.x/7.x), LispStat dialects (XLispStat, ViSta),
SAS, Stata, and BUGS.
</p>
<p><abbr class="acronym">ESS</abbr> grew out of the need for bug fixes and extensions to
S-mode 4.8 (which was a <abbr class="acronym">GNU</abbr> Emacs interface to S/<small class="sc">S-PLUS</small>
version 3 only).  The current set of developers desired support for
XEmacs, R, S4, and MS Windows.  In addition, with new modes being
developed for R, Stata, and SAS, it was felt that a unifying interface
and framework for the user interface would benefit both the user and the
developer, by helping both groups conform to standard Emacs usage.  The
end result is an increase in efficiency for statistical programming and
data analysis, over the usual tools.
</p>
<p>R support contains code for editing R source code (syntactic indentation
and highlighting of source code, partial evaluations of code, loading
and error-checking of code, and source code revision maintenance) and
documentation (syntactic indentation and highlighting of source code,
sending examples to running <abbr class="acronym">ESS</abbr> process, and previewing),
interacting with an inferior R process from within Emacs (command-line
editing, searchable command history, command-line completion of R object
and file names, 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 saved transcripts, and re-evaluating commands from transcript
files).
</p>
<p>The latest stable version of <abbr class="acronym">ESS</abbr> is available via <abbr class="acronym">CRAN</abbr> or
the <a class="url" href="https://ESS.R-project.org/">ESS web page</a>.
</p>
<p><abbr class="acronym">ESS</abbr> comes with detailed installation instructions.
</p>
<p>For help with <abbr class="acronym">ESS</abbr>, send email to
<a class="email" href="mailto:[email protected]">[email protected]</a>.
</p>
<p>Please send bug reports and suggestions on <abbr class="acronym">ESS</abbr> to
<a class="email" href="mailto:[email protected]">[email protected]</a>.  The easiest way to do this from is
within Emacs by typing <kbd class="kbd">M-x ess-submit-bug-report</kbd> or using the
[ESS] or [iESS] pulldown menus.
</p>
<hr>
</div>
<div class="section-level-extent" id="Should-I-run-R-from-within-Emacs_003f">
<div class="nav-panel">
<p>
Next: <a href="#Debugging-R-from-within-Emacs" accesskey="n" rel="next">Debugging R from within Emacs</a>, Previous: <a href="#Is-there-Emacs-support-for-R_003f" accesskey="p" rel="prev">Is there Emacs support for R?</a>, Up: <a href="#R-and-Emacs" accesskey="u" rel="up">R and Emacs</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
</div>
<h3 class="section" id="Should-I-run-R-from-within-Emacs_003f-1"><span>6.2 Should I run R from within Emacs?<a class="copiable-link" href="#Should-I-run-R-from-within-Emacs_003f-1"> &para;</a></span></h3>

<p>Yes, instead of just running it in a console, <em class="emph">definitely</em>.  As an
alternative to other <abbr class="abbr">IDE</abbr>s such as RStudio, <em class="emph">possibly</em>, notably if you
are interested to use Emacs for other computer interaction.
You&rsquo;d be using <abbr class="acronym">ESS</abbr>, Emacs Speaks Statistics, see previous FAQ.
</p>
<p>Inferior R mode provides a readline/history
mechanism, object name completion, and syntax-based highlighting of the
interaction buffer using Font Lock mode, as well as a very convenient
interface to the R help system.
</p>
<p>Of course, it also integrates nicely with the mechanisms for editing R
source using Emacs.  One can write code in one Emacs buffer and send
whole or parts of it for execution to R; this is helpful for both data
analysis and programming.  One can also seamlessly integrate with a
revision control system, in order to maintain a log of changes in your
programs and data, as well as to allow for the retrieval of past
versions of the code.
</p>
<p>In addition, it allows you to keep a record of your session, which can
also be used for error recovery through the use of the transcript mode.
</p>
<p>To specify command line arguments for the inferior R process, use
<kbd class="kbd">C-u M-x R</kbd> for starting R.
</p>

<hr>
</div>
<div class="section-level-extent" id="Debugging-R-from-within-Emacs">
<div class="nav-panel">
<p>
Previous: <a href="#Should-I-run-R-from-within-Emacs_003f" accesskey="p" rel="prev">Should I run R from within Emacs?</a>, Up: <a href="#R-and-Emacs" accesskey="u" rel="up">R and Emacs</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
</div>
<h3 class="section" id="Debugging-R-from-within-Emacs-1"><span>6.3 Debugging R from within Emacs<a class="copiable-link" href="#Debugging-R-from-within-Emacs-1"> &para;</a></span></h3>

<p>To debug R &ldquo;from within Emacs&rdquo;, there are several possibilities.  To
use the Emacs <abbr class="abbr">GUD</abbr> (Grand Unified Debugger) library with the recommended
debugger GDB, type <kbd class="kbd">M-x gdb</kbd> and give the path to the R
<em class="emph">binary</em> as argument.  At the <code class="command">gdb</code> prompt, set
<code class="env">R_HOME</code> and other environment variables as needed (using e.g.
<kbd class="kbd">set env R_HOME /path/to/R/</kbd>, but see also below), and start the
binary with the desired arguments (e.g., <kbd class="kbd">run --quiet</kbd>).
</p>
<p>If you have <abbr class="acronym">ESS</abbr>, you can do <kbd class="kbd">C-u M-x R <kbd class="key">RET</kbd> - d
<kbd class="key">SPC</kbd> g d b <kbd class="key">RET</kbd></kbd> to start an inferior R process with arguments
<samp class="option">-d gdb</samp>.
</p>
<p>A third option is to start an inferior R process via <abbr class="acronym">ESS</abbr>
(<kbd class="kbd">M-x R</kbd>) and then start <abbr class="abbr">GUD</abbr> (<kbd class="kbd">M-x gdb</kbd>) giving the R binary
(using its full path name) as the program to debug.  Use the program
<code class="command">ps</code> to find the process number of the currently running R
process then use the <code class="code">attach</code> command in GDB to attach it to that
process.  One advantage of this method is that you have separate
<code class="code">*R*</code> and <code class="code">*gud-gdb*</code> windows.  Within the <code class="code">*R*</code> window
you have all the <abbr class="acronym">ESS</abbr> facilities, such as object-name
completion, that we know and love.
</p>
<p>When using <abbr class="abbr">GUD</abbr> mode for debugging from within Emacs, you may find it
most convenient to use the directory with your code in it as the current
working directory and then make a symbolic link from that directory to
the R binary.  That way <samp class="file">.gdbinit</samp> can stay in the directory with
the code and be used to set up the environment and the search paths for
the source, e.g. as follows:
</p>
<div class="example">
<pre class="example-preformatted">set env R_HOME /opt/R
set env R_PAPERSIZE letter
set env R_PRINTCMD lpr
dir /opt/R/src/appl
dir /opt/R/src/main
dir /opt/R/src/nmath
dir /opt/R/src/unix
</pre></div>

<hr>
</div>
</div>
<div class="chapter-level-extent" id="R-Miscellanea">
<div class="nav-panel">
<p>
Next: <a href="#R-Programming" accesskey="n" rel="next">R Programming</a>, Previous: <a href="#R-and-Emacs" accesskey="p" rel="prev">R and Emacs</a>, Up: <a href="#Top" accesskey="u" rel="up">R FAQ</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
</div>
<h2 class="chapter" id="R-Miscellanea-1"><span>7 R Miscellanea<a class="copiable-link" href="#R-Miscellanea-1"> &para;</a></span></h2>








<ul class="mini-toc">
<li><a href="#How-can-I-set-components-of-a-list-to-NULL_003f" accesskey="1">How can I set components of a list to NULL?</a></li>
<li><a href="#How-can-I-save-my-workspace_003f" accesskey="2">How can I save my workspace?</a></li>
<li><a href="#How-can-I-clean-up-my-workspace_003f" accesskey="3">How can I clean up my workspace?</a></li>
<li><a href="#How-can-I-get-eval_0028_0029-and-D_0028_0029-to-work_003f" accesskey="4">How can I get <code class="code">eval()</code> and <code class="code">D()</code> to work?</a></li>
<li><a href="#Why-do-my-matrices-lose-dimensions_003f" accesskey="5">Why do my matrices lose dimensions?</a></li>
<li><a href="#How-does-autoloading-work_003f" accesskey="6">How does autoloading work?</a></li>
<li><a href="#How-should-I-set-options_003f" accesskey="7">How should I set options?</a></li>
<li><a href="#How-do-file-names-work-in-Windows_003f" accesskey="8">How do file names work in Windows?</a></li>
<li><a href="#Why-does-plotting-give-a-color-allocation-error_003f" accesskey="9">Why does plotting give a color allocation error?</a></li>
<li><a href="#How-do-I-convert-factors-to-numeric_003f">How do I convert factors to numeric?</a></li>
<li><a href="#Are-Trellis-displays-implemented-in-R_003f">Are Trellis displays implemented in R?</a></li>
<li><a href="#What-are-the-enclosing-and-parent-environments_003f">What are the enclosing and parent environments?</a></li>
<li><a href="#How-can-I-substitute-into-a-plot-label_003f">How can I substitute into a plot label?</a></li>
<li><a href="#What-are-valid-names_003f">What are valid names?</a></li>
<li><a href="#Are-GAMs-implemented-in-R_003f">Are GAMs<!-- /@w --> implemented in R?</a></li>
<li><a href="#Why-is-the-output-not-printed-when-I-source_0028_0029-a-file_003f">Why is the output not printed when I source() a file?</a></li>
<li><a href="#Why-does-outer_0028_0029-behave-strangely-with-my-function_003f">Why does outer() behave strangely with my function?</a></li>
<li><a href="#Why-does-the-output-from-anova_0028_0029-depend-on-the-order-of-factors-in-the-model_003f">Why does the output from <code class="code">anova()</code> depend on the order of factors in the model?</a></li>
<li><a href="#How-do-I-produce-PNG-graphics-in-batch-mode_003f">How do I produce PNG graphics in batch mode?</a></li>
<li><a href="#How-can-I-get-command-line-editing-to-work_003f">How can I get command line editing to work?</a></li>
<li><a href="#How-can-I-turn-a-string-into-a-variable_003f">How can I turn a string into a variable?</a></li>
<li><a href="#Why-do-lattice_002ftrellis-graphics-not-work_003f">Why do lattice/trellis graphics not work?</a></li>
<li><a href="#How-can-I-sort-the-rows-of-a-data-frame_003f">How can I sort the rows of a data frame?</a></li>
<li><a href="#Why-does-the-help_002estart_0028_0029-search-engine-not-work_003f">Why does the help.start() search engine not work?</a></li>
<li><a href="#Why-did-my-_002eRprofile-stop-working-when-I-updated-R_003f">Why did my .Rprofile stop working when I updated R?</a></li>
<li><a href="#Where-have-all-the-methods-gone_003f">Where have all the methods gone?</a></li>
<li><a href="#How-can-I-create-rotated-axis-labels_003f">How can I create rotated axis labels?</a></li>
<li><a href="#Why-is-read_002etable_0028_0029-so-inefficient_003f">Why is read.table() so inefficient?</a></li>
<li><a href="#What-is-the-difference-between-package-and-library_003f">What is the difference between package and library?</a></li>
<li><a href="#I-installed-a-package-but-the-functions-are-not-there">I installed a package but the functions are not there</a></li>
<li><a href="#Why-doesn_0027t-R-think-these-numbers-are-equal_003f">Why doesn&rsquo;t R think these numbers are equal?</a></li>
<li><a href="#How-can-I-capture-or-ignore-errors-in-a-long-simulation_003f">How can I capture or ignore errors in a long simulation?</a></li>
<li><a href="#Why-are-powers-of-negative-numbers-wrong_003f">Why are powers of negative numbers wrong?</a></li>
<li><a href="#How-can-I-save-the-result-of-each-iteration-in-a-loop-into-a-separate-file_003f">How can I save the result of each iteration in a loop into a separate file?</a></li>
<li><a href="#Why-are-p_002dvalues-not-displayed-when-using-lmer_0028_0029_003f">Why are <em class="math">p</em>-values not displayed when using <code class="code">lmer()</code>?</a></li>
<li><a href="#Why-are-there-unwanted-borders">Why are there unwanted borders, lines or grid-like artifacts when viewing a plot saved to a PS or PDF file?</a></li>
<li><a href="#Why-does-backslash-behave-strangely-inside-strings_003f">Why does backslash behave strangely inside strings?</a></li>
<li><a href="#How-can-I-put-error-bars-or-confidence-bands-on-my-plot_003f">How can I put error bars or confidence bands on my plot?</a></li>
<li><a href="#How-do-I-create-a-plot-with-two-y_002daxes_003f">How do I create a plot with two y-axes?</a></li>
<li><a href="#How-do-I-access-the-source-code-for-a-function_003f">How do I access the source code for a function?</a></li>
<li><a href="#Why-does-summary_0028_0029-report-strange-results-for-the-R_005e2-estimate-when-I-fit-a-linear-model-with-no-intercept_003f">Why does summary() report strange results for the R^2 estimate when I fit a linear model with no intercept?</a></li>
<li><a href="#Why-is-R-apparently-not-releasing-memory_003f">Why is R apparently not releasing memory?</a></li>
<li><a href="#How-can-I-enable-secure-https-downloads-in-R_003f">How can I enable secure https downloads in R?</a></li>
<li><a href="#How-can-I-get-CRAN-package-binaries-for-outdated-versions-of-R_003f">How can I get CRAN package binaries for outdated versions of R?</a></li>
</ul>
<hr>
<div class="section-level-extent" id="How-can-I-set-components-of-a-list-to-NULL_003f">
<div class="nav-panel">
<p>
Next: <a href="#How-can-I-save-my-workspace_003f" accesskey="n" rel="next">How can I save my workspace?</a>, Previous: <a href="#R-Miscellanea" accesskey="p" rel="prev">R Miscellanea</a>, Up: <a href="#R-Miscellanea" accesskey="u" rel="up">R Miscellanea</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
</div>
<h3 class="section" id="How-can-I-set-components-of-a-list-to-NULL_003f-1"><span>7.1 How can I set components of a list to NULL?<a class="copiable-link" href="#How-can-I-set-components-of-a-list-to-NULL_003f-1"> &para;</a></span></h3>

<p>You can use
</p>
<div class="example">
<pre class="example-preformatted">x[i] &lt;- list(NULL)
</pre></div>

<p>to set component <code class="code">i</code> of the list <code class="code">x</code> to <code class="code">NULL</code>, similarly
for named components.  Do not set <code class="code">x[i]</code> or <code class="code">x[[i]]</code> to
<code class="code">NULL</code>, because this will remove the corresponding component from
the list.
</p>
<p>For dropping the row names of a matrix <code class="code">x</code>, it may be easier to use
<code class="code">rownames(x) &lt;- NULL</code>, similarly for column names.
</p>
<hr>
</div>
<div class="section-level-extent" id="How-can-I-save-my-workspace_003f">
<div class="nav-panel">
<p>
Next: <a href="#How-can-I-clean-up-my-workspace_003f" accesskey="n" rel="next">How can I clean up my workspace?</a>, Previous: <a href="#How-can-I-set-components-of-a-list-to-NULL_003f" accesskey="p" rel="prev">How can I set components of a list to NULL?</a>, Up: <a href="#R-Miscellanea" accesskey="u" rel="up">R Miscellanea</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
</div>
<h3 class="section" id="How-can-I-save-my-workspace_003f-1"><span>7.2 How can I save my workspace?<a class="copiable-link" href="#How-can-I-save-my-workspace_003f-1"> &para;</a></span></h3>

<p><code class="code">save.image()</code> saves the objects in the user&rsquo;s <code class="code">.GlobalEnv</code> to
the file <samp class="file">.RData</samp> in the R startup directory.  (This is also what
happens after <kbd class="kbd">q(&quot;yes&quot;)</kbd>.)  Using <code class="code">save.image(<var class="var">file</var>)</code> one
can save the image under a different name.
</p>
<hr>
</div>
<div class="section-level-extent" id="How-can-I-clean-up-my-workspace_003f">
<div class="nav-panel">
<p>
Next: <a href="#How-can-I-get-eval_0028_0029-and-D_0028_0029-to-work_003f" accesskey="n" rel="next">How can I get <code class="code">eval()</code> and <code class="code">D()</code> to work?</a>, Previous: <a href="#How-can-I-save-my-workspace_003f" accesskey="p" rel="prev">How can I save my workspace?</a>, Up: <a href="#R-Miscellanea" accesskey="u" rel="up">R Miscellanea</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
</div>
<h3 class="section" id="How-can-I-clean-up-my-workspace_003f-1"><span>7.3 How can I clean up my workspace?<a class="copiable-link" href="#How-can-I-clean-up-my-workspace_003f-1"> &para;</a></span></h3>

<p>To remove all objects in the currently active environment (typically
<code class="code">.GlobalEnv</code>), you can do
</p>
<div class="example">
<pre class="example-preformatted">rm(list = ls(all.names = TRUE))
</pre></div>

<p>(Without <samp class="option">all = TRUE</samp>, only the objects with names not starting
with a &lsquo;<samp class="samp">.</samp>&rsquo; are removed.)
</p>
<hr>
</div>
<div class="section-level-extent" id="How-can-I-get-eval_0028_0029-and-D_0028_0029-to-work_003f">
<div class="nav-panel">
<p>
Next: <a href="#Why-do-my-matrices-lose-dimensions_003f" accesskey="n" rel="next">Why do my matrices lose dimensions?</a>, Previous: <a href="#How-can-I-clean-up-my-workspace_003f" accesskey="p" rel="prev">How can I clean up my workspace?</a>, Up: <a href="#R-Miscellanea" accesskey="u" rel="up">R Miscellanea</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
</div>
<h3 class="section" id="How-can-I-get-eval_0028_0029-and-D_0028_0029-to-work_003f-1"><span>7.4 How can I get <code class="code">eval()</code> and <code class="code">D()</code> to work?<a class="copiable-link" href="#How-can-I-get-eval_0028_0029-and-D_0028_0029-to-work_003f-1"> &para;</a></span></h3>

<p>Strange things will happen if you use <code class="code">eval(print(x), envir = e)</code>
or <code class="code">D(x^2, &quot;x&quot;)</code>.  The first one will either tell you that
&quot;<code class="code">x</code>&quot; is not found, or print the value of the wrong <code class="code">x</code>.
The other one will likely return zero if <code class="code">x</code> exists, and an error
otherwise.
</p>
<p>This is because in both cases, the first argument is evaluated in the
calling environment first.  The result (which should be an object of
mode <code class="code">&quot;expression&quot;</code> or <code class="code">&quot;call&quot;</code>) is then evaluated or
differentiated.  What you (most likely) really want is obtained by
&ldquo;quoting&rdquo; the first argument upon surrounding it with
<code class="code">expression()</code>.  For example,
</p>
<div class="example">
<pre class="example-preformatted">R&gt; D(expression(x^2), &quot;x&quot;)
2 * x
</pre></div>

<p>Although this behavior may initially seem to be rather strange, it is
perfectly logical.  The &ldquo;intuitive&rdquo; behavior could easily be
implemented, but problems would arise whenever the expression is
contained in a variable, passed as a parameter, or is the result of a
function call.  Consider for instance the semantics in cases like
</p>
<div class="example">
<pre class="example-preformatted">D2 &lt;- function(e, n) D(D(e, n), n)
</pre></div>

<p>or
</p>
<div class="example">
<pre class="example-preformatted">g &lt;- function(y) eval(substitute(y), sys.frame(sys.parent(n = 2)))
g(a * b)
</pre></div>

<p>See the help page for <code class="code">deriv()</code> for more examples.
</p>
<hr>
</div>
<div class="section-level-extent" id="Why-do-my-matrices-lose-dimensions_003f">
<div class="nav-panel">
<p>
Next: <a href="#How-does-autoloading-work_003f" accesskey="n" rel="next">How does autoloading work?</a>, Previous: <a href="#How-can-I-get-eval_0028_0029-and-D_0028_0029-to-work_003f" accesskey="p" rel="prev">How can I get <code class="code">eval()</code> and <code class="code">D()</code> to work?</a>, Up: <a href="#R-Miscellanea" accesskey="u" rel="up">R Miscellanea</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
</div>
<h3 class="section" id="Why-do-my-matrices-lose-dimensions_003f-1"><span>7.5 Why do my matrices lose dimensions?<a class="copiable-link" href="#Why-do-my-matrices-lose-dimensions_003f-1"> &para;</a></span></h3>

<p>When a matrix with a single row or column is created by a subscripting
operation, e.g., <code class="code">row &lt;- mat[2, ]</code>, it is by default turned into a
vector.  In a similar way if an array with dimension, say, 2&nbsp;x&nbsp;3&nbsp;x&nbsp;1&nbsp;x&nbsp;4<!-- /@w --> is created by subscripting it will be coerced into a 2&nbsp;x&nbsp;3&nbsp;x&nbsp;4<!-- /@w -->
array, losing the unnecessary dimension.  After much discussion this has
been determined to be a <em class="emph">feature</em>.
</p>
<p>To prevent this happening, add the option <samp class="option">drop = FALSE</samp> to the
subscripting.  For example,
</p>
<div class="example">
<pre class="example-preformatted">rowmatrix &lt;- mat[2, , drop = FALSE]  # <span class="r">creates a row matrix</span>
colmatrix &lt;- mat[, 2, drop = FALSE]  # <span class="r">creates a column matrix</span>
a &lt;- b[1, 1, 1, drop = FALSE]        # <span class="r">creates a 1 x 1 x 1 array</span>
</pre></div>

<p>The <samp class="option">drop = FALSE</samp> option should be used defensively when
programming.  For example, the statement
</p>
<div class="example">
<pre class="example-preformatted">somerows &lt;- mat[index, ]
</pre></div>

<p>will return a vector rather than a matrix if <code class="code">index</code> happens to
have length 1, causing errors later in the code.  It should probably be
rewritten as
</p>
<div class="example">
<pre class="example-preformatted">somerows &lt;- mat[index, , drop = FALSE]
</pre></div>

<hr>
</div>
<div class="section-level-extent" id="How-does-autoloading-work_003f">
<div class="nav-panel">
<p>
Next: <a href="#How-should-I-set-options_003f" accesskey="n" rel="next">How should I set options?</a>, Previous: <a href="#Why-do-my-matrices-lose-dimensions_003f" accesskey="p" rel="prev">Why do my matrices lose dimensions?</a>, Up: <a href="#R-Miscellanea" accesskey="u" rel="up">R Miscellanea</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
</div>
<h3 class="section" id="How-does-autoloading-work_003f-1"><span>7.6 How does autoloading work?<a class="copiable-link" href="#How-does-autoloading-work_003f-1"> &para;</a></span></h3>

<p>Autoloading is rarely used since packages became lazy-loaded.
</p>
<p>R has a special environment called <code class="code">.AutoloadEnv</code>.  Using
<kbd class="kbd">autoload(<var class="var">name</var>, <var class="var">pkg</var>)</kbd>, where <var class="var">name</var> and
<var class="var">pkg</var> are strings giving the names of an object and the package
containing it, stores some information in this environment.  When R
tries to evaluate <var class="var">name</var>, it loads the corresponding package
<var class="var">pkg</var> and reevaluates <var class="var">name</var> in the new package&rsquo;s
environment.
</p>
<p>Using this mechanism makes R behave as if the package was loaded, but
does not occupy memory (yet).
</p>
<p>See the help page for <code class="code">autoload()</code> for a very nice example.
</p>
<hr>
</div>
<div class="section-level-extent" id="How-should-I-set-options_003f">
<div class="nav-panel">
<p>
Next: <a href="#How-do-file-names-work-in-Windows_003f" accesskey="n" rel="next">How do file names work in Windows?</a>, Previous: <a href="#How-does-autoloading-work_003f" accesskey="p" rel="prev">How does autoloading work?</a>, Up: <a href="#R-Miscellanea" accesskey="u" rel="up">R Miscellanea</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
</div>
<h3 class="section" id="How-should-I-set-options_003f-1"><span>7.7 How should I set options?<a class="copiable-link" href="#How-should-I-set-options_003f-1"> &para;</a></span></h3>

<p>The function <code class="code">options()</code> allows setting and examining a variety of
global &ldquo;options&rdquo; which affect the way in which R computes and displays
its results.  The variable <code class="code">.Options</code> holds the current values of
these options, but should never directly be assigned to unless you want
to drive yourself crazy&mdash;simply pretend that it is a &ldquo;read-only&rdquo;
variable.
</p>
<p>For example, given
</p>
<div class="example">
<pre class="example-preformatted">test1 &lt;- function(x = pi, dig = 3) {
  oo &lt;- options(digits = dig); on.exit(options(oo));
  cat(.Options$digits, x, &quot;\n&quot;)
}
test2 &lt;- function(x = pi, dig = 3) {
  .Options$digits &lt;- dig
  cat(.Options$digits, x, &quot;\n&quot;)
}
</pre></div>

<p>we obtain:
</p>
<div class="example">
<pre class="example-preformatted">R&gt; test1()
3 3.14 
R&gt; test2()
3 3.141593
</pre></div>

<p>What is really used is the <em class="emph">global</em> value of <code class="code">.Options</code>, and
using <kbd class="kbd">options(OPT = VAL)</kbd> correctly updates it.  Local copies of
<code class="code">.Options</code>, either in <code class="code">.GlobalEnv</code> or in a function
environment (frame), are just silently disregarded.
</p>
<hr>
</div>
<div class="section-level-extent" id="How-do-file-names-work-in-Windows_003f">
<div class="nav-panel">
<p>
Next: <a href="#Why-does-plotting-give-a-color-allocation-error_003f" accesskey="n" rel="next">Why does plotting give a color allocation error?</a>, Previous: <a href="#How-should-I-set-options_003f" accesskey="p" rel="prev">How should I set options?</a>, Up: <a href="#R-Miscellanea" accesskey="u" rel="up">R Miscellanea</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
</div>
<h3 class="section" id="How-do-file-names-work-in-Windows_003f-1"><span>7.8 How do file names work in Windows?<a class="copiable-link" href="#How-do-file-names-work-in-Windows_003f-1"> &para;</a></span></h3>

<p>As R uses C-style string handling, &lsquo;<samp class="samp">\</samp>&rsquo; is treated as an escape
character, so that for example one can enter a newline as &lsquo;<samp class="samp">\n</samp>&rsquo;.
When you really need a &lsquo;<samp class="samp">\</samp>&rsquo;, you have to escape it with another
&lsquo;<samp class="samp">\</samp>&rsquo;.
</p>
<p>Thus, in filenames use something like <code class="code">&quot;c:\\data\\money.dat&quot;</code>.  You
can also replace &lsquo;<samp class="samp">\</samp>&rsquo; by &lsquo;<samp class="samp">/</samp>&rsquo; (<code class="code">&quot;c:/data/money.dat&quot;</code>).
</p>
<hr>
</div>
<div class="section-level-extent" id="Why-does-plotting-give-a-color-allocation-error_003f">
<div class="nav-panel">
<p>
Next: <a href="#How-do-I-convert-factors-to-numeric_003f" accesskey="n" rel="next">How do I convert factors to numeric?</a>, Previous: <a href="#How-do-file-names-work-in-Windows_003f" accesskey="p" rel="prev">How do file names work in Windows?</a>, Up: <a href="#R-Miscellanea" accesskey="u" rel="up">R Miscellanea</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
</div>
<h3 class="section" id="Why-does-plotting-give-a-color-allocation-error_003f-1"><span>7.9 Why does plotting give a color allocation error?<a class="copiable-link" href="#Why-does-plotting-give-a-color-allocation-error_003f-1"> &para;</a></span></h3>

<p>This is about a problem rarely seen with modern X11 installations.
</p>
<p>On an X11 device, plotting sometimes, e.g., when running
<code class="code">demo(&quot;image&quot;)</code>, results in &ldquo;Error: color allocation error&rdquo;.
This is an X problem, and only indirectly related to R.  It occurs when
applications started prior to R have used all the available colors.
(How many colors are available depends on the X configuration; sometimes
only 256 colors can be used.)
</p>

<p>You could also set the <code class="code">colortype</code> of <code class="code">X11()</code> to
<code class="code">&quot;pseudo.cube&quot;</code> rather than the default <code class="code">&quot;pseudo&quot;</code>.  See the
help page for <code class="code">X11()</code> for more information.
</p>



<hr>
</div>
<div class="section-level-extent" id="How-do-I-convert-factors-to-numeric_003f">
<div class="nav-panel">
<p>
Next: <a href="#Are-Trellis-displays-implemented-in-R_003f" accesskey="n" rel="next">Are Trellis displays implemented in R?</a>, Previous: <a href="#Why-does-plotting-give-a-color-allocation-error_003f" accesskey="p" rel="prev">Why does plotting give a color allocation error?</a>, Up: <a href="#R-Miscellanea" accesskey="u" rel="up">R Miscellanea</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
</div>
<h3 class="section" id="How-do-I-convert-factors-to-numeric_003f-1"><span>7.10 How do I convert factors to numeric?<a class="copiable-link" href="#How-do-I-convert-factors-to-numeric_003f-1"> &para;</a></span></h3>

<p>It may happen that when reading numeric data into R (usually, when
reading in a file), they come in as factors.  If <code class="code">f</code> is such a
factor object, you can use
</p>
<div class="example">
<pre class="example-preformatted">as.numeric(as.character(f))
</pre></div>

<p>to get the numbers back.  More efficient, but harder to remember, is
</p>
<div class="example">
<pre class="example-preformatted">as.numeric(levels(f))[as.integer(f)]
</pre></div>

<p>In any case, do not call <code class="code">as.numeric()</code> or their likes directly for
the task at hand (as <code class="code">as.numeric()</code> or <code class="code">unclass()</code> give the
internal codes).
</p>
<hr>
</div>
<div class="section-level-extent" id="Are-Trellis-displays-implemented-in-R_003f">
<div class="nav-panel">
<p>
Next: <a href="#What-are-the-enclosing-and-parent-environments_003f" accesskey="n" rel="next">What are the enclosing and parent environments?</a>, Previous: <a href="#How-do-I-convert-factors-to-numeric_003f" accesskey="p" rel="prev">How do I convert factors to numeric?</a>, Up: <a href="#R-Miscellanea" accesskey="u" rel="up">R Miscellanea</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
</div>
<h3 class="section" id="Are-Trellis-displays-implemented-in-R_003f-1"><span>7.11 Are Trellis displays implemented in R?<a class="copiable-link" href="#Are-Trellis-displays-implemented-in-R_003f-1"> &para;</a></span></h3>

<p>The recommended package <a class="url" href="https://CRAN.R-project.org/package=lattice"><strong class="strong">lattice</strong></a> (which is based on base
package <strong class="strong">grid</strong>) provides graphical functionality that is compatible
with most Trellis commands.
</p>
<p>You could also look at <code class="code">coplot()</code> and <code class="code">dotchart()</code> which might
do at least some of what you want.  Note also that the R version of
<code class="code">pairs()</code> is fairly general and provides most of the functionality
of <code class="code">splom()</code>, and that R&rsquo;s default plot method has an argument
<code class="code">asp</code> allowing to specify (and fix against device resizing) the
aspect ratio of the plot.
</p>
<p>(Because the word &ldquo;Trellis&rdquo; has been claimed as a trademark we do not
use it in R.  The name &ldquo;lattice&rdquo; has been chosen for the R
equivalent.)
</p>
<hr>
</div>
<div class="section-level-extent" id="What-are-the-enclosing-and-parent-environments_003f">
<div class="nav-panel">
<p>
Next: <a href="#How-can-I-substitute-into-a-plot-label_003f" accesskey="n" rel="next">How can I substitute into a plot label?</a>, Previous: <a href="#Are-Trellis-displays-implemented-in-R_003f" accesskey="p" rel="prev">Are Trellis displays implemented in R?</a>, Up: <a href="#R-Miscellanea" accesskey="u" rel="up">R Miscellanea</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
</div>
<h3 class="section" id="What-are-the-enclosing-and-parent-environments_003f-1"><span>7.12 What are the enclosing and parent environments?<a class="copiable-link" href="#What-are-the-enclosing-and-parent-environments_003f-1"> &para;</a></span></h3>

<p>Inside a function you may want to access variables in two additional
environments: the one that the function was defined in (&ldquo;enclosing&rdquo;),
and the one it was invoked in (&ldquo;parent&rdquo;).
</p>
<p>If you create a function at the command line or load it in a package its
enclosing environment is the global workspace.  If you define a function
<code class="code">f()</code> inside another function <code class="code">g()</code> its enclosing environment
is the environment inside <code class="code">g()</code>.  The enclosing environment for a
function is fixed when the function is created.  You can find out the
enclosing environment for a function <code class="code">f()</code> using
<code class="code">environment(f)</code>.
</p>
<p>The &ldquo;parent&rdquo; environment, on the other hand, is defined when you
invoke a function.  If you invoke <code class="code">lm()</code> at the command line its
parent environment is the global workspace, if you invoke it inside a
function <code class="code">f()</code> then its parent environment is the environment
inside <code class="code">f()</code>.  You can find out the parent environment for an
invocation of a function by using <code class="code">parent.frame()</code> or
<code class="code">sys.frame(sys.parent())</code>.
</p>
<p>So for most user-visible functions the enclosing environment will be the
global workspace, since that is where most functions are defined.  The
parent environment will be wherever the function happens to be called
from.  If a function <code class="code">f()</code> is defined inside another function
<code class="code">g()</code> it will probably be used inside <code class="code">g()</code> as well, so its
parent environment and enclosing environment will probably be the same.
</p>
<p>Parent environments are important because things like model formulas
need to be evaluated in the environment the function was called from,
since that&rsquo;s where all the variables will be available.  This relies on
the parent environment being potentially different with each invocation.
</p>
<p>Enclosing environments are important because a function can use
variables in the enclosing environment to share information with other
functions or with other invocations of itself (see the section on
lexical scoping).  This relies on the enclosing environment being the
same each time the function is invoked.  (In C this would be done with
static variables.)
</p>
<p>Scoping <em class="emph">is</em> hard.  Looking at examples helps.  It is particularly
instructive to look at examples that work differently in R and S and try
to see why they differ.  One way to describe the scoping differences
between R and S is to say that in S the enclosing environment is
<em class="emph">always</em> the global workspace, but in R the enclosing environment
is wherever the function was created.
</p>
<hr>
</div>
<div class="section-level-extent" id="How-can-I-substitute-into-a-plot-label_003f">
<div class="nav-panel">
<p>
Next: <a href="#What-are-valid-names_003f" accesskey="n" rel="next">What are valid names?</a>, Previous: <a href="#What-are-the-enclosing-and-parent-environments_003f" accesskey="p" rel="prev">What are the enclosing and parent environments?</a>, Up: <a href="#R-Miscellanea" accesskey="u" rel="up">R Miscellanea</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
</div>
<h3 class="section" id="How-can-I-substitute-into-a-plot-label_003f-1"><span>7.13 How can I substitute into a plot label?<a class="copiable-link" href="#How-can-I-substitute-into-a-plot-label_003f-1"> &para;</a></span></h3>

<p>Often, it is desired to use the value of an R object in a plot label,
e.g., a title.  This is easily accomplished using <code class="code">paste()</code> if the
label is a simple character string, but not always obvious in case the
label is an expression (for refined mathematical annotation).  In such a
case, either use <code class="code">parse()</code> on your pasted character string or use
<code class="code">substitute()</code> on an expression.  For example, if <code class="code">ahat</code> is an
estimator of your parameter <em class="math">a</em> of interest, use
</p>
<div class="example">
<pre class="example-preformatted">title(substitute(hat(a) == ahat, list(ahat = ahat)))
</pre></div>

<p>(note that it is &lsquo;<samp class="samp">==</samp>&rsquo; and not &lsquo;<samp class="samp">=</samp>&rsquo;).  Sometimes <code class="code">bquote()</code>
gives a more compact form, e.g.,
</p>
<div class="example">
<pre class="example-preformatted">title(bquote(hat(a) = .(ahat)))
</pre></div>

<p>where subexpressions enclosed in &lsquo;<samp class="samp">.()</samp>&rsquo; are replaced by their
values.
</p>
<p>There are more examples in the mailing list archives.
</p>
<hr>
</div>
<div class="section-level-extent" id="What-are-valid-names_003f">
<div class="nav-panel">
<p>
Next: <a href="#Are-GAMs-implemented-in-R_003f" accesskey="n" rel="next">Are GAMs<!-- /@w --> implemented in R?</a>, Previous: <a href="#How-can-I-substitute-into-a-plot-label_003f" accesskey="p" rel="prev">How can I substitute into a plot label?</a>, Up: <a href="#R-Miscellanea" accesskey="u" rel="up">R Miscellanea</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
</div>
<h3 class="section" id="What-are-valid-names_003f-1"><span>7.14 What are valid names?<a class="copiable-link" href="#What-are-valid-names_003f-1"> &para;</a></span></h3>

<p>When creating data frames using <code class="code">data.frame()</code> or
<code class="code">read.table()</code>, R by default ensures that the variable names are
syntactically valid.  (The argument <samp class="option">check.names</samp> to these
functions controls whether variable names are checked and adjusted by
<code class="code">make.names()</code> if needed.)
</p>
<p>To understand what names are &ldquo;valid&rdquo;, one needs to take into account
that the term &ldquo;name&rdquo; is used in several different (but related) ways
in the language:
</p>
<ol class="enumerate">
<li> A <em class="emph">syntactic name</em> is a string the parser interprets as this type
of expression.  It consists of letters, numbers, and the dot and
underscore characters, and starts with either a letter or a dot not
followed by a number.  Reserved words are not syntactic names.
</li><li> An <em class="emph">object name</em> is a string associated with an object that is
assigned in an expression either by having the object name on the left
of an assignment operation or as an argument to the <code class="code">assign()</code>
function.  It is usually a syntactic name as well, but can be any
non-empty string if it is quoted (and it is always quoted in the call to
<code class="code">assign()</code>).

</li><li> An <em class="emph">argument name</em> is what appears to the left of the equals sign
when supplying an argument in a function call (for example,
<code class="code">f(trim=.5)</code>).  Argument names are also usually syntactic names,
but again can be anything if they are quoted.

</li><li> An <em class="emph">element name</em> is a string that identifies a piece of an object
(a component of a list, for example.)  When it is used on the right of
the &lsquo;<samp class="samp">$</samp>&rsquo; operator, it must be a syntactic name, or quoted.
Otherwise, element names can be any strings.  (When an object is used as
a database, as in a call to <code class="code">eval()</code> or <code class="code">attach()</code>, the
element names become object names.)

</li><li> Finally, a <em class="emph">file name</em> is a string identifying a file in the
operating system for reading, writing, etc.  It really has nothing much
to do with names in the language, but it is traditional to call these
strings file &ldquo;names&rdquo;.
</li></ol>

<hr>
</div>
<div class="section-level-extent" id="Are-GAMs-implemented-in-R_003f">
<div class="nav-panel">
<p>
Next: <a href="#Why-is-the-output-not-printed-when-I-source_0028_0029-a-file_003f" accesskey="n" rel="next">Why is the output not printed when I source() a file?</a>, Previous: <a href="#What-are-valid-names_003f" accesskey="p" rel="prev">What are valid names?</a>, Up: <a href="#R-Miscellanea" accesskey="u" rel="up">R Miscellanea</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
</div>
<h3 class="section" id="Are-GAMs-implemented-in-R_003f-1"><span>7.15 Are GAMs<!-- /@w --> implemented in R?<a class="copiable-link" href="#Are-GAMs-implemented-in-R_003f-1"> &para;</a></span></h3>

<p>Package <a class="url" href="https://CRAN.R-project.org/package=gam"><strong class="strong">gam</strong></a> from <abbr class="acronym">CRAN</abbr> implements all the Generalized
Additive Models (GAM) functionality as described in the GAM chapter of
the White Book.  In particular, it implements backfitting with both
local regression and smoothing splines, and is extendable.  There is a
<code class="code">gam()</code> function for GAMs<!-- /@w --> in package <a class="url" href="https://CRAN.R-project.org/package=mgcv"><strong class="strong">mgcv</strong></a>, but it is not
an exact clone of what is described in the White Book (no <code class="code">lo()</code>
for example).  Package <a class="url" href="https://CRAN.R-project.org/package=gss"><strong class="strong">gss</strong></a> can fit spline-based GAMs<!-- /@w --> too.  And
if you can accept regression splines you can use <code class="code">glm()</code>.  For
Gaussian GAMs<!-- /@w --> you can use <code class="code">bruto()</code> from package <a class="url" href="https://CRAN.R-project.org/package=mda"><strong class="strong">mda</strong></a>.
</p>
<hr>
</div>
<div class="section-level-extent" id="Why-is-the-output-not-printed-when-I-source_0028_0029-a-file_003f">
<div class="nav-panel">
<p>
Next: <a href="#Why-does-outer_0028_0029-behave-strangely-with-my-function_003f" accesskey="n" rel="next">Why does outer() behave strangely with my function?</a>, Previous: <a href="#Are-GAMs-implemented-in-R_003f" accesskey="p" rel="prev">Are GAMs<!-- /@w --> implemented in R?</a>, Up: <a href="#R-Miscellanea" accesskey="u" rel="up">R Miscellanea</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
</div>
<h3 class="section" id="Why-is-the-output-not-printed-when-I-source_0028_0029-a-file_003f-1"><span>7.16 Why is the output not printed when I source() a file?<a class="copiable-link" href="#Why-is-the-output-not-printed-when-I-source_0028_0029-a-file_003f-1"> &para;</a></span></h3>

<p>Most R commands do not generate any output. The command
</p>
<div class="example">
<pre class="example-preformatted">1+1
</pre></div>

<p>computes the value 2 and returns it; the command
</p>
<div class="example">
<pre class="example-preformatted">summary(glm(y~x+z, family=binomial))
</pre></div>

<p>fits a logistic regression model, computes some summary information and
returns an object of class <code class="code">&quot;summary.glm&quot;</code> (see <a class="pxref" href="#How-should-I-write-summary-methods_003f">How should I write summary methods?</a>).
</p>
<p>If you type &lsquo;<samp class="samp">1+1</samp>&rsquo; or &lsquo;<samp class="samp">summary(glm(y~x+z, family=binomial))</samp>&rsquo; at
the command line the returned value is automatically printed (unless it
is <code class="code">invisible()</code>), but in other circumstances, such as in a
<code class="code">source()</code>d file or inside a function it isn&rsquo;t printed unless you
specifically print it.
</p>
<p>To print the value use
</p>
<div class="example">
<pre class="example-preformatted">print(1+1)
</pre></div>

<p>or
</p>
<div class="example">
<pre class="example-preformatted">print(summary(glm(y~x+z, family=binomial)))
</pre></div>

<p>instead, or use <code class="code">source(<var class="var">file</var>, echo=TRUE)</code>.
</p>
<hr>
</div>
<div class="section-level-extent" id="Why-does-outer_0028_0029-behave-strangely-with-my-function_003f">
<div class="nav-panel">
<p>
Next: <a href="#Why-does-the-output-from-anova_0028_0029-depend-on-the-order-of-factors-in-the-model_003f" accesskey="n" rel="next">Why does the output from <code class="code">anova()</code> depend on the order of factors in the model?</a>, Previous: <a href="#Why-is-the-output-not-printed-when-I-source_0028_0029-a-file_003f" accesskey="p" rel="prev">Why is the output not printed when I source() a file?</a>, Up: <a href="#R-Miscellanea" accesskey="u" rel="up">R Miscellanea</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
</div>
<h3 class="section" id="Why-does-outer_0028_0029-behave-strangely-with-my-function_003f-1"><span>7.17 Why does outer() behave strangely with my function?<a class="copiable-link" href="#Why-does-outer_0028_0029-behave-strangely-with-my-function_003f-1"> &para;</a></span></h3>

<p>As the help for <code class="code">outer()</code> indicates, it does not work on arbitrary
functions the way the <code class="code">apply()</code> family does.  It requires functions
that are vectorized to work elementwise on arrays.  As you can see by
looking at the code, <code class="code">outer(x, y, FUN)</code> creates two large vectors
containing every possible combination of elements of <code class="code">x</code> and
<code class="code">y</code> and then passes this to <code class="code">FUN</code> all at once.  Your function
probably cannot handle two large vectors as parameters.
</p>
<p>If you have a function that cannot handle two vectors but can handle two
scalars, then you can still use <code class="code">outer()</code> but you will need to wrap
your function up first, to simulate vectorized behavior.  Suppose your
function is
</p>
<div class="example">
<pre class="example-preformatted">foo &lt;- function(x, y, happy) {
  stopifnot(length(x) == 1, length(y) == 1) # scalars only!
  (x + y) * happy
}
</pre></div>

<p>If you define the general function
</p>
<div class="example">
<pre class="example-preformatted">wrapper &lt;- function(x, y, my.fun, ...) {
  sapply(seq_along(x), FUN = function(i) my.fun(x[i], y[i], ...))
}
</pre></div>

<p>then you can use <code class="code">outer()</code> by writing, e.g.,
</p>
<div class="example">
<pre class="example-preformatted">outer(1:4, 1:2, FUN = wrapper, my.fun = foo, happy = 10)
</pre></div>

<p>Scalar functions can also be vectorized using <code class="code">Vectorize()</code>.
</p>
<hr>
</div>
<div class="section-level-extent" id="Why-does-the-output-from-anova_0028_0029-depend-on-the-order-of-factors-in-the-model_003f">
<div class="nav-panel">
<p>
Next: <a href="#How-do-I-produce-PNG-graphics-in-batch-mode_003f" accesskey="n" rel="next">How do I produce PNG graphics in batch mode?</a>, Previous: <a href="#Why-does-outer_0028_0029-behave-strangely-with-my-function_003f" accesskey="p" rel="prev">Why does outer() behave strangely with my function?</a>, Up: <a href="#R-Miscellanea" accesskey="u" rel="up">R Miscellanea</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
</div>
<h3 class="section" id="Why-does-the-output-from-anova_0028_0029-depend-on-the-order-of-factors-in-the-model_003f-1"><span>7.18 Why does the output from <code class="code">anova()</code> depend on the order of factors in the model?<a class="copiable-link" href="#Why-does-the-output-from-anova_0028_0029-depend-on-the-order-of-factors-in-the-model_003f-1"> &para;</a></span></h3>

<p>In a model such as <code class="code">~A+B+A:B</code>, R will report the difference in sums
of squares between the models <code class="code">~1</code>, <code class="code">~A</code>, <code class="code">~A+B</code> and
<code class="code">~A+B+A:B</code>.  If the model were <code class="code">~B+A+A:B</code>, R would report
differences between <code class="code">~1</code>, <code class="code">~B</code>, <code class="code">~A+B</code>, and
<code class="code">~A+B+A:B</code> . In the first case the sum of squares for <code class="code">A</code> is
comparing <code class="code">~1</code> and <code class="code">~A</code>, in the second case it is comparing
<code class="code">~B</code> and <code class="code">~B+A</code>.  In a non-orthogonal design (i.e., most
unbalanced designs) these comparisons are (conceptually and numerically)
different.
</p>
<p>Some packages report instead the sums of squares based on comparing the
full model to the models with each factor removed one at a time (the
famous &lsquo;Type III sums of squares&rsquo; from SAS, for example).  These do not
depend on the order of factors in the model.  The question of which set
of sums of squares is the Right Thing provokes low-level holy wars on
R-help from time to time.
</p>
<p>There is no need to be agitated about the particular sums of squares
that R reports.  You can compute your favorite sums of squares quite
easily.  Any two models can be compared with <code class="code">anova(<var class="var">model1</var>,
<var class="var">model2</var>)</code>, and <code class="code">drop1(<var class="var">model1</var>)</code> will show the sums of
squares resulting from dropping single terms.
</p>
<hr>
</div>
<div class="section-level-extent" id="How-do-I-produce-PNG-graphics-in-batch-mode_003f">
<div class="nav-panel">
<p>
Next: <a href="#How-can-I-get-command-line-editing-to-work_003f" accesskey="n" rel="next">How can I get command line editing to work?</a>, Previous: <a href="#Why-does-the-output-from-anova_0028_0029-depend-on-the-order-of-factors-in-the-model_003f" accesskey="p" rel="prev">Why does the output from <code class="code">anova()</code> depend on the order of factors in the model?</a>, Up: <a href="#R-Miscellanea" accesskey="u" rel="up">R Miscellanea</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
</div>
<h3 class="section" id="How-do-I-produce-PNG-graphics-in-batch-mode_003f-1"><span>7.19 How do I produce PNG graphics in batch mode?<a class="copiable-link" href="#How-do-I-produce-PNG-graphics-in-batch-mode_003f-1"> &para;</a></span></h3>

<p>Under a Unix-like, if your installation supports the
<code class="code">type=&quot;cairo&quot;</code> option to the <code class="code">png()</code> device there should be no
problems, and the default settings should just work.  This option is not
available for versions of R prior to 2.7.0, or without support for
cairo.  From R 2.7.0 <code class="code">png()</code> by default uses the Quartz device
on macOS, and that too works in batch mode.
</p>
<p>Earlier versions of the <code class="code">png()</code> device used the X11 driver, which
is a problem in batch mode or for remote operation.  If you have
Ghostscript you can use <code class="code">bitmap()</code>, which produces a PostScript or
PDF file then converts it to any bitmap format supported by Ghostscript.
On some installations this produces ugly output, on others it is
perfectly satisfactory.  Many systems now come with Xvfb from
<a class="url" href="https://www.x.org/">X.Org</a> (possibly as an optional
install), which is an X11 server that does not require a screen.
</p>

<hr>
</div>
<div class="section-level-extent" id="How-can-I-get-command-line-editing-to-work_003f">
<div class="nav-panel">
<p>
Next: <a href="#How-can-I-turn-a-string-into-a-variable_003f" accesskey="n" rel="next">How can I turn a string into a variable?</a>, Previous: <a href="#How-do-I-produce-PNG-graphics-in-batch-mode_003f" accesskey="p" rel="prev">How do I produce PNG graphics in batch mode?</a>, Up: <a href="#R-Miscellanea" accesskey="u" rel="up">R Miscellanea</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
</div>
<h3 class="section" id="How-can-I-get-command-line-editing-to-work_003f-1"><span>7.20 How can I get command line editing to work?<a class="copiable-link" href="#How-can-I-get-command-line-editing-to-work_003f-1"> &para;</a></span></h3>

<p>The Unix-like command-line interface to R can only provide the inbuilt
command line editor which allows recall, editing and re-submission of
prior commands provided that the <abbr class="acronym">GNU</abbr> readline library is
available at the time R is configured for compilation.  Note that the
&lsquo;development&rsquo; version of readline including the appropriate headers is
needed: users of Linux binary distributions will need to install
packages such as <code class="code">libreadline-dev</code> (Debian) or
<code class="code">readline-devel</code> (Red Hat).
</p>
<hr>
</div>
<div class="section-level-extent" id="How-can-I-turn-a-string-into-a-variable_003f">
<div class="nav-panel">
<p>
Next: <a href="#Why-do-lattice_002ftrellis-graphics-not-work_003f" accesskey="n" rel="next">Why do lattice/trellis graphics not work?</a>, Previous: <a href="#How-can-I-get-command-line-editing-to-work_003f" accesskey="p" rel="prev">How can I get command line editing to work?</a>, Up: <a href="#R-Miscellanea" accesskey="u" rel="up">R Miscellanea</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
</div>
<h3 class="section" id="How-can-I-turn-a-string-into-a-variable_003f-1"><span>7.21 How can I turn a string into a variable?<a class="copiable-link" href="#How-can-I-turn-a-string-into-a-variable_003f-1"> &para;</a></span></h3>

<p>If you have
</p>
<div class="example">
<pre class="example-preformatted">varname &lt;- c(&quot;a&quot;, &quot;b&quot;, &quot;d&quot;)
</pre></div>

<p>you can do
</p>
<div class="example">
<pre class="example-preformatted">get(varname[1]) + 2
</pre></div>

<p>for
</p>
<div class="example">
<pre class="example-preformatted">a + 2
</pre></div>

<p>or
</p>
<div class="example">
<pre class="example-preformatted">assign(varname[1], 2 + 2)
</pre></div>

<p>for
</p>
<div class="example">
<pre class="example-preformatted">a &lt;- 2 + 2
</pre></div>

<p>or
</p>
<div class="example">
<pre class="example-preformatted">eval(substitute(lm(y ~ x + variable),
                list(variable = as.name(varname[1]))))
</pre></div>

<p>for
</p>
<div class="example">
<pre class="example-preformatted">lm(y ~ x + a)
</pre></div>

<p>At least in the first two cases it is often easier to just use a list,
and then you can easily index it by name
</p>
<div class="example">
<pre class="example-preformatted">vars &lt;- list(a = 1:10, b = rnorm(100), d = LETTERS)
vars[[&quot;a&quot;]]
</pre></div>

<p>without any of this messing about.
</p>
<hr>
</div>
<div class="section-level-extent" id="Why-do-lattice_002ftrellis-graphics-not-work_003f">
<div class="nav-panel">
<p>
Next: <a href="#How-can-I-sort-the-rows-of-a-data-frame_003f" accesskey="n" rel="next">How can I sort the rows of a data frame?</a>, Previous: <a href="#How-can-I-turn-a-string-into-a-variable_003f" accesskey="p" rel="prev">How can I turn a string into a variable?</a>, Up: <a href="#R-Miscellanea" accesskey="u" rel="up">R Miscellanea</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
</div>
<h3 class="section" id="Why-do-lattice_002ftrellis-graphics-not-work_003f-1"><span>7.22 Why do lattice/trellis graphics not work?<a class="copiable-link" href="#Why-do-lattice_002ftrellis-graphics-not-work_003f-1"> &para;</a></span></h3>

<p>The most likely reason is that you forgot to tell R to display the
graph.  Lattice functions such as <code class="code">xyplot()</code> create a graph object,
but do not display it (the same is true of <a class="url" href="https://CRAN.R-project.org/package=ggplot2"><strong class="strong">ggplot2</strong></a> graphics,
and Trellis graphics in <small class="sc">S-PLUS</small>).  The <code class="code">print()</code> method for the
graph object produces the actual display.  When you use these functions
interactively at the command line, the result is automatically printed,
but in <code class="code">source()</code> or inside your own functions you will need an
explicit <code class="code">print()</code> statement.
</p>
<hr>
</div>
<div class="section-level-extent" id="How-can-I-sort-the-rows-of-a-data-frame_003f">
<div class="nav-panel">
<p>
Next: <a href="#Why-does-the-help_002estart_0028_0029-search-engine-not-work_003f" accesskey="n" rel="next">Why does the help.start() search engine not work?</a>, Previous: <a href="#Why-do-lattice_002ftrellis-graphics-not-work_003f" accesskey="p" rel="prev">Why do lattice/trellis graphics not work?</a>, Up: <a href="#R-Miscellanea" accesskey="u" rel="up">R Miscellanea</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
</div>
<h3 class="section" id="How-can-I-sort-the-rows-of-a-data-frame_003f-1"><span>7.23 How can I sort the rows of a data frame?<a class="copiable-link" href="#How-can-I-sort-the-rows-of-a-data-frame_003f-1"> &para;</a></span></h3>

<p>To sort the rows within a data frame, with respect to the values in one
or more of the columns, simply use <code class="code">order()</code> (e.g.,
<code class="code">DF[order(DF$a, DF[[&quot;b&quot;]]), ]</code> to sort the data frame <code class="code">DF</code> on
columns named <code class="code">a</code> and <code class="code">b</code>).
</p>
<hr>
</div>
<div class="section-level-extent" id="Why-does-the-help_002estart_0028_0029-search-engine-not-work_003f">
<div class="nav-panel">
<p>
Next: <a href="#Why-did-my-_002eRprofile-stop-working-when-I-updated-R_003f" accesskey="n" rel="next">Why did my .Rprofile stop working when I updated R?</a>, Previous: <a href="#How-can-I-sort-the-rows-of-a-data-frame_003f" accesskey="p" rel="prev">How can I sort the rows of a data frame?</a>, Up: <a href="#R-Miscellanea" accesskey="u" rel="up">R Miscellanea</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
</div>
<h3 class="section" id="Why-does-the-help_002estart_0028_0029-search-engine-not-work_003f-1"><span>7.24 Why does the help.start() search engine not work?<a class="copiable-link" href="#Why-does-the-help_002estart_0028_0029-search-engine-not-work_003f-1"> &para;</a></span></h3>

<p>Since R 2.10.0, the browser-based search engine in <code class="code">help.start()</code>
is an <abbr class="acronym">HTML</abbr> interface to <code class="code">help.search()</code>, and should always work.
Before that, the engine utilized a Java applet.  In order for this to
function properly, one needed a compatible version of Java installed on
the system and linked to the browser, and both Java <em class="emph">and</em>
JavaScript enabled in the browser.
</p>
<hr>
</div>
<div class="section-level-extent" id="Why-did-my-_002eRprofile-stop-working-when-I-updated-R_003f">
<div class="nav-panel">
<p>
Next: <a href="#Where-have-all-the-methods-gone_003f" accesskey="n" rel="next">Where have all the methods gone?</a>, Previous: <a href="#Why-does-the-help_002estart_0028_0029-search-engine-not-work_003f" accesskey="p" rel="prev">Why does the help.start() search engine not work?</a>, Up: <a href="#R-Miscellanea" accesskey="u" rel="up">R Miscellanea</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
</div>
<h3 class="section" id="Why-did-my-_002eRprofile-stop-working-when-I-updated-R_003f-1"><span>7.25 Why did my .Rprofile stop working when I updated R?<a class="copiable-link" href="#Why-did-my-_002eRprofile-stop-working-when-I-updated-R_003f-1"> &para;</a></span></h3>

<p>Did you read the <samp class="file">NEWS</samp> file?  For functions that are not in the
<strong class="strong">base</strong> package you need to specify the correct package namespace,
since the code will be run <em class="emph">before</em> the packages are loaded.  E.g.,
</p>
<div class="example">
<pre class="example-preformatted">ps.options(horizontal = FALSE)
help.start()
</pre></div>

<p>needs to be
</p>
<div class="example">
<pre class="example-preformatted">grDevices::ps.options(horizontal = FALSE)
utils::help.start()
</pre></div>

<p>(<code class="code">graphics::ps.options(horizontal = FALSE)</code> in R 1.9.x).
</p>
<hr>
</div>
<div class="section-level-extent" id="Where-have-all-the-methods-gone_003f">
<div class="nav-panel">
<p>
Next: <a href="#How-can-I-create-rotated-axis-labels_003f" accesskey="n" rel="next">How can I create rotated axis labels?</a>, Previous: <a href="#Why-did-my-_002eRprofile-stop-working-when-I-updated-R_003f" accesskey="p" rel="prev">Why did my .Rprofile stop working when I updated R?</a>, Up: <a href="#R-Miscellanea" accesskey="u" rel="up">R Miscellanea</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
</div>
<h3 class="section" id="Where-have-all-the-methods-gone_003f-1"><span>7.26 Where have all the methods gone?<a class="copiable-link" href="#Where-have-all-the-methods-gone_003f-1"> &para;</a></span></h3>

<p>Many functions, particularly S3 methods, are now hidden in namespaces.
This has the advantage that they cannot be called inadvertently with
arguments of the wrong class, but it makes them harder to view.
</p>
<p>To see the code for an S3 method (e.g., <code class="code">[.terms</code>) use
</p>
<div class="example">
<pre class="example-preformatted">getS3method(&quot;[&quot;, &quot;terms&quot;)
</pre></div>

<p>To see the code for an unexported function <code class="code">foo()</code> in the namespace
of package <code class="code">&quot;bar&quot;</code> use <code class="code">bar:::foo</code>.  Don&rsquo;t use these
constructions to call unexported functions in your own code&mdash;they are
probably unexported for a reason and may change without warning.
</p>
<hr>
</div>
<div class="section-level-extent" id="How-can-I-create-rotated-axis-labels_003f">
<div class="nav-panel">
<p>
Next: <a href="#Why-is-read_002etable_0028_0029-so-inefficient_003f" accesskey="n" rel="next">Why is read.table() so inefficient?</a>, Previous: <a href="#Where-have-all-the-methods-gone_003f" accesskey="p" rel="prev">Where have all the methods gone?</a>, Up: <a href="#R-Miscellanea" accesskey="u" rel="up">R Miscellanea</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
</div>
<h3 class="section" id="How-can-I-create-rotated-axis-labels_003f-1"><span>7.27 How can I create rotated axis labels?<a class="copiable-link" href="#How-can-I-create-rotated-axis-labels_003f-1"> &para;</a></span></h3>

<p>To rotate axis labels (using base graphics), you need to use
<code class="code">text()</code>, rather than <code class="code">mtext()</code>, as the latter does not
support <code class="code">par(&quot;srt&quot;)</code>.
</p>
<div class="example">
<pre class="example-preformatted">## <span class="r">Increase bottom margin to make room for rotated labels</span>
par(mar = c(7, 4, 4, 2) + 0.1)
## <span class="r">Create plot with no x axis and no x axis label</span>
plot(1 : 8, xaxt = &quot;n&quot;,  xlab = &quot;&quot;)
## <span class="r">Set up x axis with tick marks alone</span>
axis(1, labels = FALSE)
## <span class="r">Create some text labels</span>
labels &lt;- paste(&quot;Label&quot;, 1:8, sep = &quot; &quot;)
## <span class="r">Plot x axis labels at default tick marks</span>
text(1:8, par(&quot;usr&quot;)[3] - 0.25, srt = 45, adj = 1,
     labels = labels, xpd = TRUE)
## <span class="r">Plot x axis label at line 6 (of 7)</span>
mtext(1, text = &quot;X Axis Label&quot;, line = 6)
</pre></div>

<p>When plotting the x axis labels, we use <code class="code">srt = 45</code> for text
rotation angle, <code class="code">adj = 1</code> to place the right end of text at the
tick marks, and <code class="code">xpd = TRUE</code> to allow for text outside the plot
region.  You can adjust the value of the <code class="code">0.25</code> offset as required
to move the axis labels up or down relative to the x axis.  See
<code class="code">?par</code> for more information.
</p>
<p>Also see Figure 1 and associated code in 
Paul Murrell (2003),
&ldquo;Integrating grid Graphics Output with Base Graphics Output&rdquo;,
<em class="emph">R News</em>, <strong class="strong">3/2</strong>, 7&ndash;12.
</p>
<hr>
</div>
<div class="section-level-extent" id="Why-is-read_002etable_0028_0029-so-inefficient_003f">
<div class="nav-panel">
<p>
Next: <a href="#What-is-the-difference-between-package-and-library_003f" accesskey="n" rel="next">What is the difference between package and library?</a>, Previous: <a href="#How-can-I-create-rotated-axis-labels_003f" accesskey="p" rel="prev">How can I create rotated axis labels?</a>, Up: <a href="#R-Miscellanea" accesskey="u" rel="up">R Miscellanea</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
</div>
<h3 class="section" id="Why-is-read_002etable_0028_0029-so-inefficient_003f-1"><span>7.28 Why is read.table() so inefficient?<a class="copiable-link" href="#Why-is-read_002etable_0028_0029-so-inefficient_003f-1"> &para;</a></span></h3>

<p>By default, <code class="code">read.table()</code> needs to read in everything as character
data, and then try to figure out which variables to convert to numerics
or factors.  For a large data set, this takes considerable amounts of
time and memory.  Performance can substantially be improved by using the
<code class="code">colClasses</code> argument to specify the classes to be assumed for the
columns of the table.
</p>
<hr>
</div>
<div class="section-level-extent" id="What-is-the-difference-between-package-and-library_003f">
<div class="nav-panel">
<p>
Next: <a href="#I-installed-a-package-but-the-functions-are-not-there" accesskey="n" rel="next">I installed a package but the functions are not there</a>, Previous: <a href="#Why-is-read_002etable_0028_0029-so-inefficient_003f" accesskey="p" rel="prev">Why is read.table() so inefficient?</a>, Up: <a href="#R-Miscellanea" accesskey="u" rel="up">R Miscellanea</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
</div>
<h3 class="section" id="What-is-the-difference-between-package-and-library_003f-1"><span>7.29 What is the difference between package and library?<a class="copiable-link" href="#What-is-the-difference-between-package-and-library_003f-1"> &para;</a></span></h3>

<p>A <em class="dfn">package</em> is a standardized collection of material extending R,
e.g. providing code, data, or documentation.  A <em class="dfn">library</em> is a
place (directory) where R knows to find packages it can use (i.e., which
were <em class="dfn">installed</em>).  R is told to use a package (to &ldquo;load&rdquo; it and
add it to the search path) via calls to the function <code class="code">library</code>.
I.e., <code class="code">library()</code> is employed to load a package from libraries
containing packages.
</p>
<p>See <a class="xref" href="#R-Add_002dOn-Packages">R Add-On Packages</a>, for more details.  See also Uwe Ligges (2003),
&ldquo;R Help Desk: Package Management&rdquo;, <em class="emph">R News</em>, <strong class="strong">3/3</strong>,
37&ndash;39.
</p>
<hr>
</div>
<div class="section-level-extent" id="I-installed-a-package-but-the-functions-are-not-there">
<div class="nav-panel">
<p>
Next: <a href="#Why-doesn_0027t-R-think-these-numbers-are-equal_003f" accesskey="n" rel="next">Why doesn&rsquo;t R think these numbers are equal?</a>, Previous: <a href="#What-is-the-difference-between-package-and-library_003f" accesskey="p" rel="prev">What is the difference between package and library?</a>, Up: <a href="#R-Miscellanea" accesskey="u" rel="up">R Miscellanea</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
</div>
<h3 class="section" id="I-installed-a-package-but-the-functions-are-not-there-1"><span>7.30 I installed a package but the functions are not there<a class="copiable-link" href="#I-installed-a-package-but-the-functions-are-not-there-1"> &para;</a></span></h3>

<p>To actually <em class="emph">use</em> the package, it needs to be <em class="emph">loaded</em> using
<code class="code">library()</code>.
</p>
<p>See <a class="ref" href="#R-Add_002dOn-Packages">R Add-On Packages</a> and <a class="ref" href="#What-is-the-difference-between-package-and-library_003f">What is the difference between package and library?</a> for more information.
</p>
<hr>
</div>
<div class="section-level-extent" id="Why-doesn_0027t-R-think-these-numbers-are-equal_003f">
<div class="nav-panel">
<p>
Next: <a href="#How-can-I-capture-or-ignore-errors-in-a-long-simulation_003f" accesskey="n" rel="next">How can I capture or ignore errors in a long simulation?</a>, Previous: <a href="#I-installed-a-package-but-the-functions-are-not-there" accesskey="p" rel="prev">I installed a package but the functions are not there</a>, Up: <a href="#R-Miscellanea" accesskey="u" rel="up">R Miscellanea</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
</div>
<h3 class="section" id="Why-doesn_0027t-R-think-these-numbers-are-equal_003f-1"><span>7.31 Why doesn&rsquo;t R think these numbers are equal?<a class="copiable-link" href="#Why-doesn_0027t-R-think-these-numbers-are-equal_003f-1"> &para;</a></span></h3>

<p>The only numbers that can be represented exactly in R&rsquo;s numeric type are
integers and fractions whose denominator is a power of 2.  All other
numbers are internally rounded to (typically) 53 binary digits accuracy.
As a result, two floating point numbers will not reliably be equal
unless they have been computed by the same algorithm, and not always
even then.  For example
</p>
<div class="example">
<pre class="example-preformatted">R&gt; a &lt;- sqrt(2)
R&gt; a * a == 2
[1] FALSE
R&gt; a * a - 2
[1] 4.440892e-16
R&gt; print(a * a, digits = 18)
[1] 2.00000000000000044
</pre></div>

<p>The function <code class="code">all.equal()</code> compares two objects using a numeric
tolerance of <code class="code">.Machine$double.eps ^ 0.5</code>.  If you want much greater
accuracy than this you will need to consider error propagation
carefully.
</p>
<p>A discussion with many easily followed examples is in Appendix G
&ldquo;Computational Precision and Floating Point Arithmetic&rdquo;, pages
753&ndash;771 of <em class="emph">Statistical Analysis and Data Display: An Intermediate
Course with Examples in R</em>, Richard M. Heiberger and Burt Holland
(Springer 2015, second edition).
This appendix is a free download from
<a class="url" href="https://link.springer.com/content/pdf/bbm:978-1-4939-2122-5/1.pdf">https://link.springer.com/content/pdf/bbm:978-1-4939-2122-5/1.pdf</a>.
</p>
<p>For more information, see e.g. 
David Goldberg (1991), 
&ldquo;What Every Computer Scientist Should Know About Floating-Point Arithmetic&rdquo;,
<em class="emph">ACM Computing Surveys</em>, <strong class="strong">23/1</strong>, 5&ndash;48, 
also available via
<a class="url" href="https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html">https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html</a>.
</p>
<p>Here is another example, this time using addition:
</p>
<div class="example">
<pre class="example-preformatted">R&gt; .3 + .6 == .9
[1] FALSE
R&gt; .3 + .6 - .9
[1] -1.110223e-16
R&gt; print(matrix(c(.3,  .6,  .9, .3 + .6)), digits = 18)
                     [,1]
[1,] 0.299999999999999989
[2,] 0.599999999999999978
[3,] 0.900000000000000022
[4,] 0.899999999999999911
</pre></div>


<hr>
</div>
<div class="section-level-extent" id="How-can-I-capture-or-ignore-errors-in-a-long-simulation_003f">
<div class="nav-panel">
<p>
Next: <a href="#Why-are-powers-of-negative-numbers-wrong_003f" accesskey="n" rel="next">Why are powers of negative numbers wrong?</a>, Previous: <a href="#Why-doesn_0027t-R-think-these-numbers-are-equal_003f" accesskey="p" rel="prev">Why doesn&rsquo;t R think these numbers are equal?</a>, Up: <a href="#R-Miscellanea" accesskey="u" rel="up">R Miscellanea</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
</div>
<h3 class="section" id="How-can-I-capture-or-ignore-errors-in-a-long-simulation_003f-1"><span>7.32 How can I capture or ignore errors in a long simulation?<a class="copiable-link" href="#How-can-I-capture-or-ignore-errors-in-a-long-simulation_003f-1"> &para;</a></span></h3>

<p>Use <code class="code">try()</code>, which returns an object of class <code class="code">&quot;try-error&quot;</code>
instead of an error, or preferably <code class="code">tryCatch()</code>, where the return
value can be configured more flexibly.  For example
</p>
<div class="example">
<pre class="example-preformatted">beta[i,] &lt;- tryCatch(coef(lm(formula, data)),
                     error = function(e) rep(NaN, 4))
</pre></div>

<p>would return the coefficients if the <code class="code">lm()</code> call succeeded and
would return <code class="code">c(NaN, NaN, NaN, NaN)</code> if it failed (presumably there
are supposed to be 4 coefficients in this example).
</p>
<hr>
</div>
<div class="section-level-extent" id="Why-are-powers-of-negative-numbers-wrong_003f">
<div class="nav-panel">
<p>
Next: <a href="#How-can-I-save-the-result-of-each-iteration-in-a-loop-into-a-separate-file_003f" accesskey="n" rel="next">How can I save the result of each iteration in a loop into a separate file?</a>, Previous: <a href="#How-can-I-capture-or-ignore-errors-in-a-long-simulation_003f" accesskey="p" rel="prev">How can I capture or ignore errors in a long simulation?</a>, Up: <a href="#R-Miscellanea" accesskey="u" rel="up">R Miscellanea</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
</div>
<h3 class="section" id="Why-are-powers-of-negative-numbers-wrong_003f-1"><span>7.33 Why are powers of negative numbers wrong?<a class="copiable-link" href="#Why-are-powers-of-negative-numbers-wrong_003f-1"> &para;</a></span></h3>

<p>You are probably seeing something like
</p>
<div class="example">
<pre class="example-preformatted">R&gt; -2^2
[1] -4
</pre></div>

<p>and misunderstanding the precedence rules for expressions in R.
Write
</p>
<div class="example">
<pre class="example-preformatted">R&gt; (-2)^2
[1] 4
</pre></div>

<p>to get the square of <em class="math">-2</em>.
</p>
<p>The precedence rules are documented in <code class="code">?Syntax</code>, and to see how R
interprets  an expression you can look at the parse tree
</p>
<div class="example">
<pre class="example-preformatted">R&gt; as.list(quote(-2^2))
[[1]]
`-`

[[2]]
2^2
</pre></div>

<hr>
</div>
<div class="section-level-extent" id="How-can-I-save-the-result-of-each-iteration-in-a-loop-into-a-separate-file_003f">
<div class="nav-panel">
<p>
Next: <a href="#Why-are-p_002dvalues-not-displayed-when-using-lmer_0028_0029_003f" accesskey="n" rel="next">Why are <em class="math">p</em>-values not displayed when using <code class="code">lmer()</code>?</a>, Previous: <a href="#Why-are-powers-of-negative-numbers-wrong_003f" accesskey="p" rel="prev">Why are powers of negative numbers wrong?</a>, Up: <a href="#R-Miscellanea" accesskey="u" rel="up">R Miscellanea</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
</div>
<h3 class="section" id="How-can-I-save-the-result-of-each-iteration-in-a-loop-into-a-separate-file_003f-1"><span>7.34 How can I save the result of each iteration in a loop into a separate file?<a class="copiable-link" href="#How-can-I-save-the-result-of-each-iteration-in-a-loop-into-a-separate-file_003f-1"> &para;</a></span></h3>

<p>One way is to use <code class="code">paste()</code> (or <code class="code">sprintf()</code>) to concatenate a
stem filename and the iteration number while <code class="code">file.path()</code>
constructs the path.  For example, to save results into files
<samp class="file">result1.rda</samp>, &hellip;, <samp class="file">result100.rda</samp> in the subdirectory
<samp class="file">Results</samp> of the current working directory, one can use
</p>
<div class="example">
<pre class="example-preformatted">for(i in 1:100) {
  ## Calculations constructing &quot;some_object&quot; ...
  fp &lt;- file.path(&quot;Results&quot;, paste(&quot;result&quot;, i, &quot;.rda&quot;, sep = &quot;&quot;))
  save(list = &quot;some_object&quot;, file = fp)
}
</pre></div>

<hr>
</div>
<div class="section-level-extent" id="Why-are-p_002dvalues-not-displayed-when-using-lmer_0028_0029_003f">
<div class="nav-panel">
<p>
Next: <a href="#Why-are-there-unwanted-borders" accesskey="n" rel="next">Why are there unwanted borders, lines or grid-like artifacts when viewing a plot saved to a PS or PDF file?</a>, Previous: <a href="#How-can-I-save-the-result-of-each-iteration-in-a-loop-into-a-separate-file_003f" accesskey="p" rel="prev">How can I save the result of each iteration in a loop into a separate file?</a>, Up: <a href="#R-Miscellanea" accesskey="u" rel="up">R Miscellanea</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
</div>
<h3 class="section" id="Why-are-p_002dvalues-not-displayed-when-using-lmer_0028_0029_003f-1"><span>7.35 Why are <em class="math">p</em>-values not displayed when using <code class="code">lmer()</code>?<a class="copiable-link" href="#Why-are-p_002dvalues-not-displayed-when-using-lmer_0028_0029_003f-1"> &para;</a></span></h3>

<p>Doug Bates has kindly provided an extensive response in a post to the 
r-help list, which can be reviewed at
<a class="uref" href="https://stat.ethz.ch/pipermail/r-help/2006-May/094765.html">https://stat.ethz.ch/pipermail/r-help/2006-May/094765.html</a>.
</p>
<hr>
</div>
<div class="section-level-extent" id="Why-are-there-unwanted-borders">
<div class="nav-panel">
<p>
Next: <a href="#Why-does-backslash-behave-strangely-inside-strings_003f" accesskey="n" rel="next">Why does backslash behave strangely inside strings?</a>, Previous: <a href="#Why-are-p_002dvalues-not-displayed-when-using-lmer_0028_0029_003f" accesskey="p" rel="prev">Why are <em class="math">p</em>-values not displayed when using <code class="code">lmer()</code>?</a>, Up: <a href="#R-Miscellanea" accesskey="u" rel="up">R Miscellanea</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
</div>
<h3 class="section" id="Why-are-there-unwanted-borders_002c-lines-or-grid_002dlike-artifacts-when-viewing-a-plot-saved-to-a-PS-or-PDF-file_003f"><span>7.36 Why are there unwanted borders, lines or grid-like artifacts when viewing a plot saved to a PS or PDF file?<a class="copiable-link" href="#Why-are-there-unwanted-borders_002c-lines-or-grid_002dlike-artifacts-when-viewing-a-plot-saved-to-a-PS-or-PDF-file_003f"> &para;</a></span></h3>

<p>This can occur when using functions such as <code class="code">polygon()</code>,
<code class="code">filled.contour()</code>, <code class="code">image()</code> or other functions which may
call these internally.  In the case of <code class="code">polygon()</code>, you may observe
unwanted borders between the polygons even when setting the
<code class="code">border</code> argument to <code class="code">NA</code> or <code class="code">&quot;transparent&quot;</code>.
</p>
<p>The source of the problem is the PS/PDF viewer when the plot is
anti-aliased.  The details for the solution will be different depending
upon the viewer used, the operating system and may change over time.
For some common viewers, consider the following:
</p>
<dl class="ftable">
<dt><a id="index-Acrobat-Reader-_0028cross-platform_0029"></a><span>Acrobat Reader (cross platform)<a class="copiable-link" href="#index-Acrobat-Reader-_0028cross-platform_0029"> &para;</a></span></dt>
<dd><p>There are options in Preferences to enable/disable text smoothing, image
smoothing and line art smoothing.
Disable line art smoothing.
</p></dd>
<dt><a id="index-Preview-_0028macOS_0029"></a><span>Preview (macOS)<a class="copiable-link" href="#index-Preview-_0028macOS_0029"> &para;</a></span></dt>
<dd><p>There is an option in Preferences to enable/disable anti-aliasing of
text and line art.
Disable this option. 
</p></dd>
<dt><a id="index-GSview-_0028cross-platform_0029"></a><span>GSview (cross platform)<a class="copiable-link" href="#index-GSview-_0028cross-platform_0029"> &para;</a></span></dt>
<dd><p>There are settings for Text Alpha and Graphics Alpha.
Change Graphics Alpha from 4 bits to 1 bit to disable graphic
anti-aliasing.
</p></dd>
<dt><a id="index-gv-_0028Unix_002dlike-X_0029"></a><span>gv (Unix-like X)<a class="copiable-link" href="#index-gv-_0028Unix_002dlike-X_0029"> &para;</a></span></dt>
<dd><p>There is an option to enable/disable anti-aliasing.
Disable this option.
</p></dd>
<dt><a id="index-Evince-_0028Linux_002fGNOME_0029"></a><span>Evince (Linux/GNOME)<a class="copiable-link" href="#index-Evince-_0028Linux_002fGNOME_0029"> &para;</a></span></dt>
<dd><p>There is not an option to disable anti-aliasing in this viewer.
</p></dd>
<dt><a id="index-Okular-_0028Linux_002fKDE_0029"></a><span>Okular (Linux/KDE)<a class="copiable-link" href="#index-Okular-_0028Linux_002fKDE_0029"> &para;</a></span></dt>
<dd><p>There is not an option in the GUI to enable/disable anti-aliasing.
From a console command line, use:
</p><div class="example smallexample">
<pre class="example-preformatted">$ kwriteconfig --file okularpartrc --group ‘Dlg Performance’ \
               --key GraphicsAntialias Disabled
</pre></div>
<p>Then restart Okular.  Change the final word to &lsquo;<samp class="samp">Enabled</samp>&rsquo; to restore
the original setting.
</p></dd>
</dl>

<hr>
</div>
<div class="section-level-extent" id="Why-does-backslash-behave-strangely-inside-strings_003f">
<div class="nav-panel">
<p>
Next: <a href="#How-can-I-put-error-bars-or-confidence-bands-on-my-plot_003f" accesskey="n" rel="next">How can I put error bars or confidence bands on my plot?</a>, Previous: <a href="#Why-are-there-unwanted-borders" accesskey="p" rel="prev">Why are there unwanted borders, lines or grid-like artifacts when viewing a plot saved to a PS or PDF file?</a>, Up: <a href="#R-Miscellanea" accesskey="u" rel="up">R Miscellanea</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
</div>
<h3 class="section" id="Why-does-backslash-behave-strangely-inside-strings_003f-1"><span>7.37 Why does backslash behave strangely inside strings?<a class="copiable-link" href="#Why-does-backslash-behave-strangely-inside-strings_003f-1"> &para;</a></span></h3>

<p>This question most often comes up in relation to file names (see
<a class="ref" href="#How-do-file-names-work-in-Windows_003f">How do file names work in Windows?</a>)  but it also happens that
people complain that they cannot seem to put a single &lsquo;<samp class="samp">\</samp>&rsquo; character
into a text string unless it happens to be followed by certain other
characters.
</p>
<p>To understand this, you have to distinguish between character strings
and <em class="emph">representations</em> of character strings.  Mostly, the
representation in R is just the string with a single or double quote at
either end, but there are strings that cannot be represented that way,
e.g., strings that themselves contain the quote character.  So
</p>
<div class="example">
<pre class="example-preformatted">&gt; str &lt;- &quot;This \&quot;text\&quot; is quoted&quot;
&gt; str
[1] &quot;This \&quot;text\&quot; is quoted&quot;
&gt; cat(str, &quot;\n&quot;)
This &quot;text&quot; is quoted
</pre></div>

<p>The <em class="emph">escape sequences</em> &lsquo;<samp class="samp">\&quot;</samp>&rsquo; and &lsquo;<samp class="samp">\n</samp>&rsquo; represent a double
quote and the newline character respectively. Printing text strings,
using <code class="code">print()</code> or by typing the name at the prompt will use the
escape sequences too, but the <code class="code">cat()</code> function will display the
string as-is. Notice that &lsquo;<samp class="samp">&quot;\n&quot;</samp>&rsquo; is a one-character string, not
two; the backslash is not actually in the string, it is just generated
in the printed representation.
</p>
<div class="example">
<pre class="example-preformatted">&gt; nchar(&quot;\n&quot;)
[1] 1
&gt; substring(&quot;\n&quot;, 1, 1)
[1] &quot;\n&quot;
</pre></div>

<p>So how do you put a backslash in a string? For this, you have to
escape the escape character. I.e., you have to double the backslash.
as in
</p>
<div class="example">
<pre class="example-preformatted">&gt; cat(&quot;\\n&quot;, &quot;\n&quot;)
\n
</pre></div>

<p>Some functions, particularly those involving regular expression
matching, themselves use metacharacters, which may need to be escaped by
the backslash mechanism.  In those cases you may need a <em class="emph">quadruple</em>
backslash to represent a single literal one.
</p>
<p>In versions of R up to 2.4.1 an unknown escape sequence like &lsquo;<samp class="samp">\p</samp>&rsquo;
was quietly interpreted as just &lsquo;<samp class="samp">p</samp>&rsquo;.  Current versions of R emit a
warning.
</p>
<hr>
</div>
<div class="section-level-extent" id="How-can-I-put-error-bars-or-confidence-bands-on-my-plot_003f">
<div class="nav-panel">
<p>
Next: <a href="#How-do-I-create-a-plot-with-two-y_002daxes_003f" accesskey="n" rel="next">How do I create a plot with two y-axes?</a>, Previous: <a href="#Why-does-backslash-behave-strangely-inside-strings_003f" accesskey="p" rel="prev">Why does backslash behave strangely inside strings?</a>, Up: <a href="#R-Miscellanea" accesskey="u" rel="up">R Miscellanea</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
</div>
<h3 class="section" id="How-can-I-put-error-bars-or-confidence-bands-on-my-plot_003f-1"><span>7.38 How can I put error bars or confidence bands on my plot?<a class="copiable-link" href="#How-can-I-put-error-bars-or-confidence-bands-on-my-plot_003f-1"> &para;</a></span></h3>

<p>Some functions will display a particular kind of plot with error bars,
such as the <code class="code">bar.err()</code> function in the <a class="url" href="https://CRAN.R-project.org/package=agricolae"><strong class="strong">agricolae</strong></a>
package, the <code class="code">plotCI()</code> function in the <a class="url" href="https://CRAN.R-project.org/package=gplots"><strong class="strong">gplots</strong></a> package,
the <code class="code">plotCI()</code> and <code class="code">brkdn.plot()</code> functions in the
<a class="url" href="https://CRAN.R-project.org/package=plotrix"><strong class="strong">plotrix</strong></a> package and the <code class="code">error.bars()</code>,
<code class="code">error.crosses()</code> and <code class="code">error.bars.by()</code> functions in the
<a class="url" href="https://CRAN.R-project.org/package=psych"><strong class="strong">psych</strong></a> package.  Within these types of functions, some will
accept the measures of dispersion (e.g., <code class="code">plotCI</code>), some will
calculate the dispersion measures from the raw values (<code class="code">bar.err</code>,
<code class="code">brkdn.plot</code>), and some will do both (<code class="code">error.bars</code>).  Still
other functions will just display error bars, like the dispersion
function in the <a class="url" href="https://CRAN.R-project.org/package=plotrix"><strong class="strong">plotrix</strong></a> package.  Most of the above functions
use the <code class="code">arrows()</code> function in the base <strong class="strong">graphics</strong> package to
draw the error bars.
</p>
<p>The above functions all use the base graphics system.  The grid and
lattice graphics systems also have specific functions for displaying
error bars, e.g., the <code class="code">grid.arrow()</code> function in the <strong class="strong">grid</strong>
package, and the <code class="code">geom_errorbar()</code>, <code class="code">geom_errorbarh()</code>,
<code class="code">geom_pointrange()</code>, <code class="code">geom_linerange()</code>,
<code class="code">geom_crossbar()</code> and <code class="code">geom_ribbon()</code> functions in the
<a class="url" href="https://CRAN.R-project.org/package=ggplot2"><strong class="strong">ggplot2</strong></a> package.  In the lattice system, error bars can be
displayed with <code class="code">Dotplot()</code> or <code class="code">xYplot()</code> in the
<a class="url" href="https://CRAN.R-project.org/package=Hmisc"><strong class="strong">Hmisc</strong></a> package and <code class="code">segplot()</code> in the
<a class="url" href="https://CRAN.R-project.org/package=latticeExtra"><strong class="strong">latticeExtra</strong></a> package.
</p>
<hr>
</div>
<div class="section-level-extent" id="How-do-I-create-a-plot-with-two-y_002daxes_003f">
<div class="nav-panel">
<p>
Next: <a href="#How-do-I-access-the-source-code-for-a-function_003f" accesskey="n" rel="next">How do I access the source code for a function?</a>, Previous: <a href="#How-can-I-put-error-bars-or-confidence-bands-on-my-plot_003f" accesskey="p" rel="prev">How can I put error bars or confidence bands on my plot?</a>, Up: <a href="#R-Miscellanea" accesskey="u" rel="up">R Miscellanea</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
</div>
<h3 class="section" id="How-do-I-create-a-plot-with-two-y_002daxes_003f-1"><span>7.39 How do I create a plot with two y-axes?<a class="copiable-link" href="#How-do-I-create-a-plot-with-two-y_002daxes_003f-1"> &para;</a></span></h3>

<p>Creating a graph with two y-axes, i.e., with two sorts of data that are
scaled to the same vertical size and showing separate vertical axes on
the left and right sides of the plot that reflect the original scales of
the data, is possible in R but is not recommended.  The basic approach
for constructing such graphs is to use <code class="code">par(new=TRUE)</code> (see
<code class="code">?par</code>); functions <code class="code">twoord.plot()</code> (in the <a class="url" href="https://CRAN.R-project.org/package=plotrix"><strong class="strong">plotrix</strong></a>
package) and <code class="code">doubleYScale()</code> (in the <a class="url" href="https://CRAN.R-project.org/package=latticeExtra"><strong class="strong">latticeExtra</strong></a>
package) automate the process somewhat.
</p>
<hr>
</div>
<div class="section-level-extent" id="How-do-I-access-the-source-code-for-a-function_003f">
<div class="nav-panel">
<p>
Next: <a href="#Why-does-summary_0028_0029-report-strange-results-for-the-R_005e2-estimate-when-I-fit-a-linear-model-with-no-intercept_003f" accesskey="n" rel="next">Why does summary() report strange results for the R^2 estimate when I fit a linear model with no intercept?</a>, Previous: <a href="#How-do-I-create-a-plot-with-two-y_002daxes_003f" accesskey="p" rel="prev">How do I create a plot with two y-axes?</a>, Up: <a href="#R-Miscellanea" accesskey="u" rel="up">R Miscellanea</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
</div>
<h3 class="section" id="How-do-I-access-the-source-code-for-a-function_003f-1"><span>7.40 How do I access the source code for a function?<a class="copiable-link" href="#How-do-I-access-the-source-code-for-a-function_003f-1"> &para;</a></span></h3>

<p>In most cases, typing the name of the function will print its source 
code. However, code is sometimes hidden in a namespace, or compiled.  For 
a complete overview on how to access source code, see Uwe Ligges (2006),
&ldquo;Help Desk: Accessing the sources&rdquo;, <em class="emph">R News</em>, <strong class="strong">6/4</strong>,
43&ndash;45 (<a class="url" href="https://CRAN.R-project.org/doc/Rnews/Rnews_2006-4.pdf">https://CRAN.R-project.org/doc/Rnews/Rnews_2006-4.pdf</a>).
</p>
<hr>
</div>
<div class="section-level-extent" id="Why-does-summary_0028_0029-report-strange-results-for-the-R_005e2-estimate-when-I-fit-a-linear-model-with-no-intercept_003f">
<div class="nav-panel">
<p>
Next: <a href="#Why-is-R-apparently-not-releasing-memory_003f" accesskey="n" rel="next">Why is R apparently not releasing memory?</a>, Previous: <a href="#How-do-I-access-the-source-code-for-a-function_003f" accesskey="p" rel="prev">How do I access the source code for a function?</a>, Up: <a href="#R-Miscellanea" accesskey="u" rel="up">R Miscellanea</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
</div>
<h3 class="section" id="Why-does-summary_0028_0029-report-strange-results-for-the-R_005e2-estimate-when-I-fit-a-linear-model-with-no-intercept_003f-1"><span>7.41 Why does summary() report strange results for the R^2 estimate when I fit a linear model with no intercept?<a class="copiable-link" href="#Why-does-summary_0028_0029-report-strange-results-for-the-R_005e2-estimate-when-I-fit-a-linear-model-with-no-intercept_003f-1"> &para;</a></span></h3>

<p>As described in <code class="code">?summary.lm</code>, when the intercept is zero (e.g.,
from <code class="code">y ~ x - 1</code> or <code class="code">y ~ x + 0</code>), <code class="code">summary.lm()</code> uses the
formula
     R^2 = 1 - Sum(R[i]^2) / Sum((y[i])^2),
which is different from the usual
     R^2 = 1 - Sum(R[i]^2) / Sum((y[i] - mean(y))^2).
There are several reasons for this:
</p><ul class="itemize mark-bullet">
<li>Otherwise the <em class="math">R^2</em> could be negative (because the model with zero
intercept can fit <em class="emph">worse</em> than the constant-mean model it is
implicitly compared to).
</li><li>If you set the slope to zero in the model with a line through the
origin you get fitted values y*=0
</li><li>The model with constant, non-zero mean is not nested in the model
with a line through the origin.
</li></ul>

<p>All these come down to saying that if you know <em class="emph">a priori</em> that
<em class="math">E[Y]=0</em> when <em class="math">x=0</em> then the &lsquo;null&rsquo; model that you should
compare to the fitted line, the model where <em class="math">x</em> doesn&rsquo;t explain any
of the variance, is the model where <em class="math">E[Y]=0</em> everywhere.  (If you
don&rsquo;t know a priori that <em class="math">E[Y]=0</em> when <em class="math">x=0</em>, then you
probably shouldn&rsquo;t be fitting a line through the origin.)
</p>
<hr>
</div>
<div class="section-level-extent" id="Why-is-R-apparently-not-releasing-memory_003f">
<div class="nav-panel">
<p>
Next: <a href="#How-can-I-enable-secure-https-downloads-in-R_003f" accesskey="n" rel="next">How can I enable secure https downloads in R?</a>, Previous: <a href="#Why-does-summary_0028_0029-report-strange-results-for-the-R_005e2-estimate-when-I-fit-a-linear-model-with-no-intercept_003f" accesskey="p" rel="prev">Why does summary() report strange results for the R^2 estimate when I fit a linear model with no intercept?</a>, Up: <a href="#R-Miscellanea" accesskey="u" rel="up">R Miscellanea</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
</div>
<h3 class="section" id="Why-is-R-apparently-not-releasing-memory_003f-1"><span>7.42 Why is R apparently not releasing memory?<a class="copiable-link" href="#Why-is-R-apparently-not-releasing-memory_003f-1"> &para;</a></span></h3>

<p>This question is often asked in different flavors along the lines of
&ldquo;I have removed objects in R and run <code class="code">gc()</code> and yet
<code class="code">ps</code>/<code class="code">top</code> still shows the R process using a lot of
memory&rdquo;, often on Linux machines.
</p>
<p>This is an artifact of the way the operating system (OS) allocates
memory.  In general it is common that the OS is not capable of
releasing all unused memory.  In extreme cases it is possible that even
if R frees almost all its memory, the OS can not release any of it due
to its design and thus tools such as <code class="code">ps</code> or <code class="code">top</code> will
report substantial amount of resident RAM used by the R process even
though R has released all that memory.  In general such tools do
<em class="emph">not</em> report the actual memory usage of the process but rather
what the OS is reserving for that process.
</p>
<p>The short answer is that this is a limitation of the memory allocator
in the operating system and there is nothing R can do about it. That
space is simply kept by the OS in the hope that R will ask for it
later.  The following paragraph gives more in-depth answer with
technical details on how this happens.
</p>
<p>Most systems use two separate ways to allocate memory. For allocation
of large chunks they will use <code class="code">mmap</code> to map memory into the
process address space.  Such chunks can be released immediately when
they are completely free, because they can reside anywhere in the
virtual memory.  However, this is a relatively expensive operation and
many OSes have a limit on the number of such allocated chunks, so this
is only used for allocating large memory regions.  For smaller
allocations the system can expand the data segment of the process
(historically using the <code class="code">brk</code> system call), but this whole area
is always contiguous.  The OS can only move the end of this space, it
cannot create any &ldquo;holes&rdquo;. Since this operation is fairly cheap, it
is used for allocations of small pieces of memory.  However, the
side-effect is that even if there is just one byte that is in use
at the end of the data segment, the OS cannot release any memory
at all, because it cannot change the address of that byte.  This is
actually more common than it may seem, because allocating a lot of
intermediate objects, then allocating a result object and removing all
intermediate objects is a very common practice.  Since the result is
allocated at the end it will prevent the OS from releasing any memory
used by the intermediate objects.  In practice, this is not necessarily
a problem, because modern operating systems can page out unused
portions of the virtual memory so it does not necessarily reduce the
amount of real memory available for other applications.  Typically,
small objects such as strings or pairlists will be affected by this
behavior, whereas large objects such as long vectors will be allocated
using <code class="code">mmap</code> and thus not affected.  On Linux (and possibly other
Unix-like systems) it is possible to use the <code class="code">mallinfo</code> system call
(also see the <a class="url" href="https://rforge.net/mallinfo">mallinfo</a> package) to
query the allocator about the layout of the allocations, including the
actually used memory as well as unused memory that cannot be released.
</p>
<hr>
</div>
<div class="section-level-extent" id="How-can-I-enable-secure-https-downloads-in-R_003f">
<div class="nav-panel">
<p>
Next: <a href="#How-can-I-get-CRAN-package-binaries-for-outdated-versions-of-R_003f" accesskey="n" rel="next">How can I get CRAN package binaries for outdated versions of R?</a>, Previous: <a href="#Why-is-R-apparently-not-releasing-memory_003f" accesskey="p" rel="prev">Why is R apparently not releasing memory?</a>, Up: <a href="#R-Miscellanea" accesskey="u" rel="up">R Miscellanea</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
</div>
<h3 class="section" id="How-can-I-enable-secure-https-downloads-in-R_003f-1"><span>7.43 How can I enable secure https downloads in R?<a class="copiable-link" href="#How-can-I-enable-secure-https-downloads-in-R_003f-1"> &para;</a></span></h3>

<p>From R 4.2.0, <code class="code">&quot;libcurl&quot;</code> download method is always available and
used for <abbr class="abbr">HTTPS</abbr> by default on all platforms.  It has been used
since R 3.3.0 everywhere but Windows where the default method
<code class="code">&quot;wininet&quot;</code> also supported <abbr class="abbr">HTTPS</abbr>.
</p>
<p>So nothing needs to be done to access &lsquo;<samp class="samp">https://</samp>&rsquo; websites in recent
versions of R.
</p>
<hr>
</div>
<div class="section-level-extent" id="How-can-I-get-CRAN-package-binaries-for-outdated-versions-of-R_003f">
<div class="nav-panel">
<p>
Previous: <a href="#How-can-I-enable-secure-https-downloads-in-R_003f" accesskey="p" rel="prev">How can I enable secure https downloads in R?</a>, Up: <a href="#R-Miscellanea" accesskey="u" rel="up">R Miscellanea</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
</div>
<h3 class="section" id="How-can-I-get-CRAN-package-binaries-for-outdated-versions-of-R_003f-1"><span>7.44 How can I get CRAN package binaries for outdated versions of R?<a class="copiable-link" href="#How-can-I-get-CRAN-package-binaries-for-outdated-versions-of-R_003f-1"> &para;</a></span></h3>

<p>Since March 2016, Windows and macOS binaries of <abbr class="acronym">CRAN</abbr> packages for old
versions of R (released more than 5 years ago) are made available from a
central <abbr class="acronym">CRAN</abbr> archive server instead of the <abbr class="acronym">CRAN</abbr> mirrors.  To get
these, one should set the <abbr class="acronym">CRAN</abbr> &ldquo;mirror&rdquo; element of the <code class="code">repos</code>
option accordingly, by something like
</p><div class="example">
<pre class="example-preformatted">local({r &lt;- getOption(&quot;repos&quot;)
       r[&quot;CRAN&quot;] &lt;- &quot;http://CRAN-archive.R-project.org&quot;
       options(repos = r)
      })
</pre></div>
<p>(see <code class="code">?options</code> for more information).
</p>
<hr>
</div>
</div>
<div class="chapter-level-extent" id="R-Programming">
<div class="nav-panel">
<p>
Next: <a href="#R-Bugs" accesskey="n" rel="next">R Bugs</a>, Previous: <a href="#R-Miscellanea" accesskey="p" rel="prev">R Miscellanea</a>, Up: <a href="#Top" accesskey="u" rel="up">R FAQ</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
</div>
<h2 class="chapter" id="R-Programming-1"><span>8 R Programming<a class="copiable-link" href="#R-Programming-1"> &para;</a></span></h2>


<ul class="mini-toc">
<li><a href="#How-should-I-write-summary-methods_003f" accesskey="1">How should I write summary methods?</a></li>
<li><a href="#How-can-I-debug-dynamically-loaded-code_003f" accesskey="2">How can I debug dynamically loaded code?</a></li>
<li><a href="#How-can-I-inspect-R-objects-when-debugging_003f" accesskey="3">How can I inspect R objects when debugging?</a></li>
<li><a href="#How-can-I-change-compilation-flags_003f" accesskey="4">How can I change compilation flags?</a></li>
<li><a href="#How-can-I-debug-S4-methods_003f" accesskey="5">How can I debug S4 methods?</a></li>
</ul>
<hr>
<div class="section-level-extent" id="How-should-I-write-summary-methods_003f">
<div class="nav-panel">
<p>
Next: <a href="#How-can-I-debug-dynamically-loaded-code_003f" accesskey="n" rel="next">How can I debug dynamically loaded code?</a>, Previous: <a href="#R-Programming" accesskey="p" rel="prev">R Programming</a>, Up: <a href="#R-Programming" accesskey="u" rel="up">R Programming</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
</div>
<h3 class="section" id="How-should-I-write-summary-methods_003f-1"><span>8.1 How should I write summary methods?<a class="copiable-link" href="#How-should-I-write-summary-methods_003f-1"> &para;</a></span></h3>

<p>Suppose you want to provide a summary method for class <code class="code">&quot;foo&quot;</code>.
Then <code class="code">summary.foo()</code> should not print anything, but return an
object of class <code class="code">&quot;summary.foo&quot;</code>, <em class="emph">and</em> you should write a
method <code class="code">print.summary.foo()</code> which nicely prints the summary
information and invisibly returns its object.  This approach is
preferred over having <code class="code">summary.foo()</code> print summary information and
return something useful, as sometimes you need to grab something
computed by <code class="code">summary()</code> inside a function or similar.  In such
cases you don&rsquo;t want anything printed.
</p>
<hr>
</div>
<div class="section-level-extent" id="How-can-I-debug-dynamically-loaded-code_003f">
<div class="nav-panel">
<p>
Next: <a href="#How-can-I-inspect-R-objects-when-debugging_003f" accesskey="n" rel="next">How can I inspect R objects when debugging?</a>, Previous: <a href="#How-should-I-write-summary-methods_003f" accesskey="p" rel="prev">How should I write summary methods?</a>, Up: <a href="#R-Programming" accesskey="u" rel="up">R Programming</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
</div>
<h3 class="section" id="How-can-I-debug-dynamically-loaded-code_003f-1"><span>8.2 How can I debug dynamically loaded code?<a class="copiable-link" href="#How-can-I-debug-dynamically-loaded-code_003f-1"> &para;</a></span></h3>

<p>Roughly speaking, you need to start R inside the debugger, load the
code, send an interrupt, and then set the required breakpoints.
</p>
<p>See <a data-manual="R-exts" href="https://cran.r-project.org/doc/manuals/R-exts.html#Finding-entry-points">Finding entry points in dynamically loaded
code</a> in <cite class="cite">Writing R Extensions</cite>.
</p>
<hr>
</div>
<div class="section-level-extent" id="How-can-I-inspect-R-objects-when-debugging_003f">
<div class="nav-panel">
<p>
Next: <a href="#How-can-I-change-compilation-flags_003f" accesskey="n" rel="next">How can I change compilation flags?</a>, Previous: <a href="#How-can-I-debug-dynamically-loaded-code_003f" accesskey="p" rel="prev">How can I debug dynamically loaded code?</a>, Up: <a href="#R-Programming" accesskey="u" rel="up">R Programming</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
</div>
<h3 class="section" id="How-can-I-inspect-R-objects-when-debugging_003f-1"><span>8.3 How can I inspect R objects when debugging?<a class="copiable-link" href="#How-can-I-inspect-R-objects-when-debugging_003f-1"> &para;</a></span></h3>

<p>The most convenient way is to call <code class="code">R_PV</code> from the symbolic
debugger.
</p>
<p>See <a data-manual="R-exts" href="https://cran.r-project.org/doc/manuals/R-exts.html#Inspecting-R-objects">Inspecting R objects when debugging</a> in <cite class="cite">Writing R Extensions</cite>.
</p>
<hr>
</div>
<div class="section-level-extent" id="How-can-I-change-compilation-flags_003f">
<div class="nav-panel">
<p>
Next: <a href="#How-can-I-debug-S4-methods_003f" accesskey="n" rel="next">How can I debug S4 methods?</a>, Previous: <a href="#How-can-I-inspect-R-objects-when-debugging_003f" accesskey="p" rel="prev">How can I inspect R objects when debugging?</a>, Up: <a href="#R-Programming" accesskey="u" rel="up">R Programming</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
</div>
<h3 class="section" id="How-can-I-change-compilation-flags_003f-1"><span>8.4 How can I change compilation flags?<a class="copiable-link" href="#How-can-I-change-compilation-flags_003f-1"> &para;</a></span></h3>

<p>Suppose you have C code file for dynloading into R, but you want to use
<code class="code">R CMD SHLIB</code> with compilation flags other than the default ones
(which were determined when R was built).
</p>
<p>Starting with R 2.1.0, users can provide personal <samp class="file">Makevars</samp> configuration
files in <samp class="file">$<code class="env">HOME</code>/.R</samp> to override the default flags.
See <a data-manual="R-admin" href="https://cran.r-project.org/doc/manuals/R-admin.html#Add_002don-packages">Add-on packages</a> in <cite class="cite">R Installation and Administration</cite>.
</p>

<hr>
</div>
<div class="section-level-extent" id="How-can-I-debug-S4-methods_003f">
<div class="nav-panel">
<p>
Previous: <a href="#How-can-I-change-compilation-flags_003f" accesskey="p" rel="prev">How can I change compilation flags?</a>, Up: <a href="#R-Programming" accesskey="u" rel="up">R Programming</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
</div>
<h3 class="section" id="How-can-I-debug-S4-methods_003f-1"><span>8.5 How can I debug S4 methods?<a class="copiable-link" href="#How-can-I-debug-S4-methods_003f-1"> &para;</a></span></h3>

<p>Use the <code class="code">trace()</code> function with argument <code class="code">signature=</code> to add
calls to the browser or any other code to the method that will be
dispatched for the corresponding signature.  See <code class="code">?trace</code> for
details.
</p>
<hr>
</div>
</div>
<div class="chapter-level-extent" id="R-Bugs">
<div class="nav-panel">
<p>
Next: <a href="#Acknowledgments" accesskey="n" rel="next">Acknowledgments</a>, Previous: <a href="#R-Programming" accesskey="p" rel="prev">R Programming</a>, Up: <a href="#Top" accesskey="u" rel="up">R FAQ</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
</div>
<h2 class="chapter" id="R-Bugs-1"><span>9 R Bugs<a class="copiable-link" href="#R-Bugs-1"> &para;</a></span></h2>


<ul class="mini-toc">
<li><a href="#What-is-a-bug_003f" accesskey="1">What is a bug?</a></li>
<li><a href="#How-to-report-a-bug" accesskey="2">How to report a bug</a></li>
</ul>
<hr>
<div class="section-level-extent" id="What-is-a-bug_003f">
<div class="nav-panel">
<p>
Next: <a href="#How-to-report-a-bug" accesskey="n" rel="next">How to report a bug</a>, Previous: <a href="#R-Bugs" accesskey="p" rel="prev">R Bugs</a>, Up: <a href="#R-Bugs" accesskey="u" rel="up">R Bugs</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
</div>
<h3 class="section" id="What-is-a-bug_003f-1"><span>9.1 What is a bug?<a class="copiable-link" href="#What-is-a-bug_003f-1"> &para;</a></span></h3>

<p>If R executes an illegal instruction, or dies with an operating system
error message that indicates a problem in the program (as opposed to
something like &ldquo;disk full&rdquo;), then it is certainly a bug.  If you call
<code class="code">.C()</code>, <code class="code">.Fortran()</code>, <code class="code">.External()</code> or <code class="code">.Call()</code> (or
<code class="code">.Internal()</code>) yourself (or in a function you wrote), you can
always crash R by using wrong argument types (modes).  This is not a
bug.
</p>
<p>Taking forever to complete a command can be a bug, but you must make
certain that it was really R&rsquo;s fault.  Some commands simply take a long
time.  If the input was such that you <em class="emph">know</em> it should have been
processed quickly, report a bug.  If you don&rsquo;t know whether the command
should take a long time, find out by looking in the manual or by asking
for assistance.
</p>
<p>If a command you are familiar with causes an R error message in a case
where its usual definition ought to be reasonable, it is probably a bug.
If a command does the wrong thing, that is a bug.  But be sure you know
for certain what it ought to have done.  If you aren&rsquo;t familiar with the
command, or don&rsquo;t know for certain how the command is supposed to work,
then it might actually be working right.  For example, people sometimes
think there is a bug in R&rsquo;s mathematics because they don&rsquo;t understand
how finite-precision arithmetic works.  Rather than jumping to
conclusions, show the problem to someone who knows for certain.
Unexpected results of comparison of decimal numbers, for example
<code class="code">0.28 * 100 != 28</code> or <code class="code">0.1 + 0.2 != 0.3</code>, are not a bug.
See <a class="xref" href="#Why-doesn_0027t-R-think-these-numbers-are-equal_003f">Why doesn&rsquo;t R think these numbers are equal?</a>, for more details.
</p>
<p>Finally, a command&rsquo;s intended definition may not be best for statistical
analysis.  This is a very important sort of problem, but it is also a
matter of judgment.  Also, it is easy to come to such a conclusion out
of ignorance of some of the existing features.  It is probably best not
to complain about such a problem until you have checked the
documentation in the usual ways, feel confident that you understand it,
and know for certain that what you want is not available.  If you are
not sure what the command is supposed to do after a careful reading of
the manual this indicates a bug in the manual.  The manual&rsquo;s job is to
make everything clear.  It is just as important to report documentation
bugs as program bugs.  However, we know that the introductory
documentation is seriously inadequate, so you don&rsquo;t need to report this.
</p>
<p>If the online argument list of a function disagrees with the manual, one
of them must be wrong, so report the bug.
</p>
<p>See also &ldquo;Making sure it&rsquo;s a bug&rdquo; in
<a class="uref" href="https://www.r-project.org/bugs.html">Bug Reporting in R</a> for more
information.
</p>
<hr>
</div>
<div class="section-level-extent" id="How-to-report-a-bug">
<div class="nav-panel">
<p>
Previous: <a href="#What-is-a-bug_003f" accesskey="p" rel="prev">What is a bug?</a>, Up: <a href="#R-Bugs" accesskey="u" rel="up">R Bugs</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
</div>
<h3 class="section" id="How-to-report-a-bug-1"><span>9.2 How to report a bug<a class="copiable-link" href="#How-to-report-a-bug-1"> &para;</a></span></h3>

<p>When you decide that there is a bug, it is important to report it and to
report it in a way which is useful.  What is most useful is an exact
description of what commands you type, starting with the shell command
to run R, until the problem happens.  Always include the version of R,
machine, and operating system that you are using; type <kbd class="kbd">version</kbd> in
R to print this.
</p>
<p>The most important principle in reporting a bug is to report
<em class="emph">facts</em>, not hypotheses or categorizations.  It is always easier to
report the facts, but people seem to prefer to strain to posit
explanations and report them instead.  If the explanations are based on
guesses about how R is implemented, they will be useless; others will
have to try to figure out what the facts must have been to lead to such
speculations.  Sometimes this is impossible.  But in any case, it is
unnecessary work for the ones trying to fix the problem.
</p>
<p>For example, suppose that on a data set which you know to be quite large
the command
</p>
<div class="example">
<pre class="example-preformatted">R&gt; data.frame(x, y, z, monday, tuesday)
</pre></div>

<p>never returns.  Do not report that <code class="code">data.frame()</code> fails for large
data 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 class="code">data.frame()</code> command on a large data set, probably with no day of
the week variable name, and not see any problem.  There is no way in the
world that others could guess that they should try a day of the week
variable name.
</p>
<p>Or perhaps the command fails because the last command you used was a
method for <code class="code">&quot;[&quot;()</code> that had a bug causing R&rsquo;s internal data
structures to be corrupted and making the <code class="code">data.frame()</code> command
fail from then on.  This is why others need to know what other commands
you have typed (or read from your startup file).
</p>
<p>It is very useful to try and find simple examples that produce
apparently the same bug, and somewhat useful to find simple examples
that might be expected to produce the bug but actually do not.  If you
want to debug the problem and find exactly what caused it, that is
wonderful.  You should still report the facts as well as any
explanations or solutions.  Please include an example that reproduces
(e.g., <a class="url" href="https://en.wikipedia.org/wiki/Reproducibility">https://en.wikipedia.org/wiki/Reproducibility</a>) the problem,
preferably the simplest one you have found.
</p>
<p>Invoking R with the <samp class="option">--vanilla</samp> option may help in isolating a
bug.  This ensures that the site profile and saved data files are not
read.
</p>
<p>Before you actually submit a bug report, you should check whether the
bug has already been reported and/or fixed.  First, try the &ldquo;Show open
bugs new-to-old&rdquo; or the search facility on
<a class="url" href="https://bugs.R-project.org/">https://bugs.R-project.org/</a>.  Second, consult
<a class="url" href="https://svn.R-project.org/R/trunk/doc/NEWS.Rd">https://svn.R-project.org/R/trunk/doc/NEWS.Rd</a>, which
records changes that will appear in the <em class="emph">next</em> release of R,
including bug fixes that do not appear on the Bug Tracker.  
Third, if possible try the current r-patched or r-devel version of R.
If a bug has already been reported or fixed, please do not submit
further bug reports on it.  Finally, check carefully whether the bug is
with R, or a contributed package.  Bug reports on contributed packages
should be sent first to the package maintainer, and only submitted to
the R-bugs repository by package maintainers, mentioning the package in
the subject line.
</p>
<p>A bug report can be generated using the function <code class="code">bug.report()</code>.
For reports on R this will open the R Bugzilla page at
<a class="url" href="https://bugs.R-project.org/">https://bugs.R-project.org/</a>: for a contributed package it will open
the package&rsquo;s bug tracker Web page or help you compose an email to the
maintainer.  Since 2016, only &ldquo;members&rdquo; (including all who have
previously submitted bugs) can submit new bugs on the R Bugzilla.  See
&ldquo;Where to submit bug reports and patches&rdquo; on 
<a class="uref" href="https://www.r-project.org/bugs.html">Bug Reporting in R</a> for more
information.
</p>
<p>There is a section of the bug repository for suggestions for
enhancements for R labelled &lsquo;<samp class="samp">wishlist</samp>&rsquo;.  Suggestions can be
submitted in the same ways as bugs, but please ensure that the subject
line makes clear that this is for the wishlist and not a bug report, for
example by starting with &lsquo;<samp class="samp">Wishlist:</samp>&rsquo;.
</p>
<p>Comments on and suggestions for the Windows port of R should be sent to
<a class="email" href="mailto:[email protected]">[email protected]</a>.
</p>
<p>Corrections to and comments on message translations should be sent to the
last translator (listed at the top of the appropriate &lsquo;<samp class="samp">.po</samp>&rsquo; file)
or to the translation team as listed at
<a class="url" href="https://developer.R-project.org/TranslationTeams.html">https://developer.R-project.org/TranslationTeams.html</a>.
</p>
<hr>
</div>
</div>
<div class="chapter-level-extent" id="Acknowledgments">
<div class="nav-panel">
<p>
Previous: <a href="#R-Bugs" accesskey="p" rel="prev">R Bugs</a>, Up: <a href="#Top" accesskey="u" rel="up">R FAQ</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
</div>
<h2 class="chapter" id="Acknowledgments-1"><span>10 Acknowledgments<a class="copiable-link" href="#Acknowledgments-1"> &para;</a></span></h2>

<p>Of course, many many thanks to Robert and Ross for the R system, and to
the package writers and porters for adding to it.
</p>
<p>Special thanks go to 
Doug Bates, 
Peter Dalgaard, 
Paul Gilbert,
Stefano Iacus,
Fritz Leisch,
Jim Lindsey,
Thomas Lumley,
Martin Maechler,
Brian D. Ripley,
Anthony Rossini, and 
Andreas Weingessel
for their comments which helped me improve this <abbr class="acronym">FAQ</abbr>.
</p>
<p>More to come soon &hellip;
</p>
</div>
</div>



</body>
</html>