R/R-FAQ.html

4275 lines
238 KiB
HTML
Raw Permalink Normal View History

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
2016-07-05 18:26:48 +00:00
<!-- Created by GNU Texinfo 6.1, http://www.gnu.org/software/texinfo/ -->
<head>
<title>R FAQ</title>
<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="makeinfo">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="#Top" rel="start" title="Top">
<link href="#SEC_Contents" rel="contents" title="Table of Contents">
<style type="text/css">
<!--
a.summary-letter {text-decoration: none}
blockquote.indentedblock {margin-right: 0em}
blockquote.smallindentedblock {margin-right: 0em; font-size: smaller}
blockquote.smallquotation {font-size: smaller}
div.display {margin-left: 3.2em}
div.example {margin-left: 3.2em}
div.lisp {margin-left: 3.2em}
div.smalldisplay {margin-left: 3.2em}
div.smallexample {margin-left: 3.2em}
div.smalllisp {margin-left: 3.2em}
kbd {font-style: oblique}
pre.display {font-family: inherit}
pre.format {font-family: inherit}
pre.menu-comment {font-family: serif}
pre.menu-preformatted {font-family: serif}
pre.smalldisplay {font-family: inherit; font-size: smaller}
pre.smallexample {font-size: smaller}
pre.smallformat {font-family: inherit; font-size: smaller}
pre.smalllisp {font-size: smaller}
span.nolinebreak {white-space: nowrap}
2016-07-05 18:26:48 +00:00
span.roman {font-family: initial; font-weight: normal}
span.sansserif {font-family: sans-serif; font-weight: normal}
ul.no-bullet {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;
}
-->
</style>
</head>
<body lang="en">
<h1 class="settitle" align="center">R FAQ</h1>
<h2>Frequently Asked Questions on R</h2>
2016-07-05 18:26:48 +00:00
<h3 style="text-align: center;">Version 2016-06-06</h3>
<h3 style="text-align: center;">Kurt Hornik</h3>
<hr>
2016-07-05 18:26:48 +00:00
<a name="SEC_Contents"></a>
<h2 class="contents-heading">Table of Contents</h2>
<div class="contents">
<ul class="no-bullet">
<li><a name="toc-Introduction-1" href="#Introduction">1 Introduction</a>
<ul class="no-bullet">
<li><a name="toc-Legalese-1" href="#Legalese">1.1 Legalese</a></li>
<li><a name="toc-Obtaining-this-document-1" href="#Obtaining-this-document">1.2 Obtaining this document</a></li>
<li><a name="toc-Citing-this-document-1" href="#Citing-this-document">1.3 Citing this document</a></li>
<li><a name="toc-Notation-1" href="#Notation">1.4 Notation</a></li>
<li><a name="toc-Feedback-1" href="#Feedback">1.5 Feedback</a></li>
</ul></li>
<li><a name="toc-R-Basics-1" href="#R-Basics">2 R Basics</a>
<ul class="no-bullet">
<li><a name="toc-What-is-R_003f-1" href="#What-is-R_003f">2.1 What is R?</a></li>
<li><a name="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 name="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 name="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 name="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="no-bullet">
<li><a name="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 name="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 name="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 name="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 name="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 name="toc-Citing-R-1" href="#Citing-R">2.8 Citing R</a></li>
<li><a name="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 name="toc-What-is-CRAN_003f-1" href="#What-is-CRAN_003f">2.10 What is <acronym>CRAN</acronym>?</a></li>
<li><a name="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 name="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 name="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 name="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 name="toc-R-and-S-1" href="#R-and-S">3 R and S</a>
<ul class="no-bullet">
<li><a name="toc-What-is-S_003f-1" href="#What-is-S_003f">3.1 What is S?</a></li>
<li><a name="toc-What-is-S_002dPLUS_003f-1" href="#What-is-S_002dPLUS_003f">3.2 What is <small>S-PLUS</small>?</a></li>
<li><a name="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="no-bullet">
<li><a name="toc-Lexical-scoping-1" href="#Lexical-scoping">3.3.1 Lexical scoping</a></li>
<li><a name="toc-Models-1" href="#Models">3.3.2 Models</a></li>
<li><a name="toc-Others-1" href="#Others">3.3.3 Others</a></li>
</ul></li>
<li><a name="toc-Is-there-anything-R-can-do-that-S_002dPLUS-cannot_003f-1" href="#Is-there-anything-R-can-do-that-S_002dPLUS-cannot_003f">3.4 Is there anything R can do that <small>S-PLUS</small> cannot?</a></li>
<li><a name="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 name="toc-R-Web-Interfaces-1" href="#R-Web-Interfaces">4 R Web Interfaces</a></li>
<li><a name="toc-R-Add_002dOn-Packages-1" href="#R-Add_002dOn-Packages">5 R Add-On Packages</a>
<ul class="no-bullet">
<li><a name="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="no-bullet">
<li><a name="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 name="toc-Add_002don-packages-from-CRAN-1" href="#Add_002don-packages-from-CRAN">5.1.2 Add-on packages from <acronym>CRAN</acronym></a></li>
<li><a name="toc-Add_002don-packages-from-Omegahat-1" href="#Add_002don-packages-from-Omegahat">5.1.3 Add-on packages from Omegahat</a></li>
<li><a name="toc-Add_002don-packages-from-Bioconductor-1" href="#Add_002don-packages-from-Bioconductor">5.1.4 Add-on packages from Bioconductor</a></li>
<li><a name="toc-Other-add_002don-packages-1" href="#Other-add_002don-packages">5.1.5 Other add-on packages</a></li>
</ul></li>
<li><a name="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 name="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 name="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 name="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 name="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 name="toc-R-and-Emacs-1" href="#R-and-Emacs">6 R and Emacs</a>
<ul class="no-bullet">
<li><a name="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 name="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 name="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 name="toc-R-Miscellanea-1" href="#R-Miscellanea">7 R Miscellanea</a>
<ul class="no-bullet">
<li><a name="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 name="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 name="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 name="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 eval() and D() to work?</a></li>
<li><a name="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 name="toc-How-does-autoloading-work_003f-1" href="#How-does-autoloading-work_003f">7.6 How does autoloading work?</a></li>
<li><a name="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 name="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 name="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 name="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 name="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 name="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 name="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 name="toc-What-are-valid-names_003f-1" href="#What-are-valid-names_003f">7.14 What are valid names?</a></li>
<li><a name="toc-Are-GAMs-implemented-in-R_003f-1" href="#Are-GAMs-implemented-in-R_003f">7.15 Are GAMs implemented in R?</a></li>
<li><a name="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 name="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 name="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 anova() depend on the order of factors in the model?</a></li>
<li><a name="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 name="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 name="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 name="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 name="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 name="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 name="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 name="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 name="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 name="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 name="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 name="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 name="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 name="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 name="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 name="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 name="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>p</em>-values not displayed when using lmer()?</a></li>
<li><a name="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 name="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 name="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 name="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 name="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 name="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 name="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 name="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>
2016-07-05 18:26:48 +00:00
<li><a name="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 name="toc-R-Programming-1" href="#R-Programming">8 R Programming</a>
<ul class="no-bullet">
<li><a name="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 name="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 name="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 name="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 name="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 name="toc-R-Bugs-1" href="#R-Bugs">9 R Bugs</a>
<ul class="no-bullet">
<li><a name="toc-What-is-a-bug_003f-1" href="#What-is-a-bug_003f">9.1 What is a bug?</a></li>
<li><a name="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 name="toc-Acknowledgments-1" href="#Acknowledgments">10 Acknowledgments</a></li>
</ul>
</div>
<a name="Top"></a>
<div class="header">
<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>
<a name="R-FAQ"></a>
<h1 class="top">R FAQ</h1>
<table summary="" class="menu" border="0" cellspacing="0">
<tr><td align="left" valign="top">&bull; <a href="#Introduction" accesskey="1">Introduction</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="#R-Basics" accesskey="2">R Basics</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="#R-and-S" accesskey="3">R and S</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="#R-Web-Interfaces" accesskey="4">R Web Interfaces</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="#R-Add_002dOn-Packages" accesskey="5">R Add-On Packages</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="#R-and-Emacs" accesskey="6">R and Emacs</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="#R-Miscellanea" accesskey="7">R Miscellanea</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="#R-Programming" accesskey="8">R Programming</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="#R-Bugs" accesskey="9">R Bugs</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="#Acknowledgments">Acknowledgments</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
</table>
<hr>
<a name="Introduction"></a>
<div class="header">
<p>
Next: <a href="#R-Basics" accesskey="n" rel="next">R Basics</a>, Previous: <a href="#Top" accesskey="p" rel="prev">Top</a>, Up: <a href="#Top" accesskey="u" rel="up">Top</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
</div>
<a name="Introduction-1"></a>
<h2 class="chapter">1 Introduction</h2>
<p>This document contains answers to some of the most frequently asked
questions about R.
</p>
<table summary="" class="menu" border="0" cellspacing="0">
<tr><td align="left" valign="top">&bull; <a href="#Legalese" accesskey="1">Legalese</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="#Obtaining-this-document" accesskey="2">Obtaining this document</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="#Citing-this-document" accesskey="3">Citing this document</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="#Notation" accesskey="4">Notation</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="#Feedback" accesskey="5">Feedback</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
</table>
<hr>
<a name="Legalese"></a>
<div class="header">
<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>
<a name="Legalese-1"></a>
<h3 class="section">1.1 Legalese</h3>
2016-07-05 18:26:48 +00:00
<p>This document is copyright &copy; 1998&ndash;2016 by Kurt
Hornik.
</p>
<p>This document is free software; you can redistribute it and/or modify it
under the terms of the <acronym>GNU</acronym> 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
<acronym>GNU</acronym> General Public License for more details.
</p>
<p>Copies of the <acronym>GNU</acronym> General Public License versions are
available at
</p>
<div class="display">
<pre class="display"><a href="https://www.R-project.org/Licenses/">https://www.R-project.org/Licenses/</a>
</pre></div>
<hr>
<a name="Obtaining-this-document"></a>
<div class="header">
<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>
<a name="Obtaining-this-document-1"></a>
<h3 class="section">1.2 Obtaining this document</h3>
<p>The latest version of this document is always available from
</p>
<div class="display">
<pre class="display"><a href="https://CRAN.R-project.org/doc/FAQ/">https://CRAN.R-project.org/doc/FAQ/</a>
</pre></div>
<p>From there, you can obtain versions converted to
<a href="https://CRAN.R-project.org/doc/FAQ/R-FAQ.txt">plain
<acronym>ASCII</acronym> text</a>,
<a href="https://CRAN.R-project.org/doc/FAQ/R-FAQ.info.gz"><acronym>GNU</acronym>
info</a>, <a href="https://CRAN.R-project.org/doc/FAQ/R-FAQ.html"><acronym>HTML</acronym></a>,
<a href="https://CRAN.R-project.org/doc/FAQ/R-FAQ.pdf">PDF</a>,
as well as the <a href="https://CRAN.R-project.org/doc/FAQ/R-FAQ.texi">Texinfo source</a> used for creating all these formats using the
<acronym>GNU</acronym> Texinfo system.
</p>
<p>You can also obtain the R <acronym>FAQ</acronym> from the <samp>doc/FAQ</samp>
subdirectory of a <acronym>CRAN</acronym> site (see <a href="#What-is-CRAN_003f">What is CRAN?</a>).
</p>
<hr>
<a name="Citing-this-document"></a>
<div class="header">
<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>
<a name="Citing-this-document-1"></a>
<h3 class="section">1.3 Citing this document</h3>
<p>In publications, please refer to this <acronym>FAQ</acronym> as Hornik
2016-07-05 18:26:48 +00:00
(2016), &ldquo;The R <acronym>FAQ</acronym>&rdquo;, and give the above,
<em>official</em> <acronym>URL</acronym>:
</p>
<div class="example">
<pre class="example">@Misc{,
author = {Kurt Hornik},
title = {{R} {FAQ}},
2016-07-05 18:26:48 +00:00
year = {2016},
url = {https://CRAN.R-project.org/doc/FAQ/R-FAQ.html}
}
</pre></div>
<hr>
<a name="Notation"></a>
<div class="header">
<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>
<a name="Notation-1"></a>
<h3 class="section">1.4 Notation</h3>
<p>Everything should be pretty standard. &lsquo;<samp>R&gt;</samp>&rsquo; is used for the R
prompt, and a &lsquo;<samp>$</samp>&rsquo; for the shell prompt (where applicable).
</p>
<hr>
<a name="Feedback"></a>
<div class="header">
<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>
<a name="Feedback-1"></a>
<h3 class="section">1.5 Feedback</h3>
<p>Feedback via email to <a href="mailto:Kurt.Hornik@R-project.org">Kurt.Hornik@R-project.org</a> is of course
most welcome.
</p>
<p>In particular, note that I do not have access to Windows or Mac
systems. Features specific to the Windows and OS X ports of R are
described in the
<a href="https://CRAN.R-project.org/bin/windows/base/rw-FAQ.html">&ldquo;R for
Windows <acronym>FAQ</acronym>&rdquo;</a> and the
<a href="https://CRAN.R-project.org/bin/macosx/RMacOSX-FAQ.html">&ldquo;R for Mac
OS X <acronym>FAQ</acronym>&rdquo;</a>. If you have information on Mac or Windows
systems that you think should be added to this document, please let me
know.
</p>
<hr>
<a name="R-Basics"></a>
<div class="header">
<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">Top</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
</div>
<a name="R-Basics-1"></a>
<h2 class="chapter">2 R Basics</h2>
<table summary="" class="menu" border="0" cellspacing="0">
<tr><td align="left" valign="top">&bull; <a href="#What-is-R_003f" accesskey="1">What is R?</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="#What-machines-does-R-run-on_003f" accesskey="2">What machines does R run on?</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="#What-is-the-current-version-of-R_003f" accesskey="3">What is the current version of R?</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="#How-can-R-be-obtained_003f" accesskey="4">How can R be obtained?</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="#How-can-R-be-installed_003f" accesskey="5">How can R be installed?</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="#Are-there-Unix_002dlike-binaries-for-R_003f" accesskey="6">Are there Unix-like binaries for R?</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="#What-documentation-exists-for-R_003f" accesskey="7">What documentation exists for R?</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="#Citing-R" accesskey="8">Citing R</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="#What-mailing-lists-exist-for-R_003f" accesskey="9">What mailing lists exist for R?</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="#What-is-CRAN_003f">What is CRAN?</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="#Can-I-use-R-for-commercial-purposes_003f">Can I use R for commercial purposes?</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="#Why-is-R-named-R_003f">Why is R named R?</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="#What-is-the-R-Foundation_003f">What is the R Foundation?</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="#What-is-R_002dForge_003f">What is R-Forge?</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
</table>
<hr>
<a name="What-is-R_003f"></a>
<div class="header">
<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>
<a name="What-is-R_003f-1"></a>
<h3 class="section">2.1 What is R?</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 href="#What-is-S_003f">What is S?</a>) and Sussman&rsquo;s
<a href="https://www.cs.indiana.edu/scheme-repository/home.html">Scheme</a>.
Whereas the resulting language is very similar in appearance to S, the
underlying implementation and semantics are derived from Scheme.
See <a 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 href="#R-Add_002dOn-Packages">R Add-On Packages</a>).
</p>
<p>R was initially written by <a href="mailto:Ross.Ihaka@R-project.org">Ross Ihaka</a>
and <a href="mailto:Robert.Gentleman@R-project.org">Robert Gentleman</a> 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. The group currently consists of Doug
Bates, John Chambers, Peter Dalgaard, Seth Falcon, Robert Gentleman,
Kurt Hornik, Stefano Iacus, Ross Ihaka, Friedrich Leisch, Uwe Ligges,
Thomas Lumley, Martin Maechler, Duncan Murdoch, Paul Murrell, Martyn
Plummer, Brian Ripley, Deepayan Sarkar, Duncan Temple Lang, Luke
Tierney, and Simon Urbanek.
</p>
<p>R has a home page at <a href="https://www.R-project.org/">https://www.R-project.org/</a>. It is
<a href="https://www.gnu.org/philosophy/free-sw.html">free software</a>
distributed under a <acronym>GNU</acronym>-style
<a href="https://www.gnu.org/copyleft/copyleft.html">copyleft</a>, and an
official part of the <a href="https://www.gnu.org/"><acronym>GNU</acronym></a> project
(&ldquo;<acronym>GNU</acronym> S&rdquo;).
</p>
<hr>
<a name="What-machines-does-R-run-on_003f"></a>
<div class="header">
<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>
<a name="What-machines-does-R-run-on_003f-1"></a>
<h3 class="section">2.2 What machines does R run on?</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 href="https://en.wikipedia.org/wiki/Unix-like">https://en.wikipedia.org/wiki/Unix-like</a>)
platforms including <var>cpu</var>-linux-gnu for the i386, amd64, alpha,
arm/armel, hppa, ia64, m68k, mips/mipsel, powerpc, s390 and sparc
<acronym>CPU</acronym>s (e.g., <a href="https://buildd.debian.org/build.php?&amp;pkg=r-base">https://buildd.debian.org/build.php?&amp;pkg=r-base</a>),
i386-hurd-gnu, <var>cpu</var>-kfreebsd-gnu for i386 and amd64,
powerpc-apple-darwin, mips-sgi-irix,
i386-freebsd,
rs6000-ibm-aix, and sparc-sun-solaris.
</p>
<p>If you know about other platforms, please drop us a note.
</p>
<hr>
<a name="What-is-the-current-version-of-R_003f"></a>
<div class="header">
<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>
<a name="What-is-the-current-version-of-R_003f-1"></a>
<h3 class="section">2.3 What is the current version of R?</h3>
2016-07-05 18:26:48 +00:00
<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 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>
<a name="How-can-R-be-obtained_003f"></a>
<div class="header">
<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>
<a name="How-can-R-be-obtained_003f-1"></a>
<h3 class="section">2.4 How can R be obtained?</h3>
<p>Sources, binaries and documentation for R can be obtained via <acronym>CRAN</acronym>,
the &ldquo;Comprehensive R Archive Network&rdquo; (see <a href="#What-is-CRAN_003f">What is CRAN?</a>).
</p>
<p>Sources are also available via <a 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 href="https://stat.ethz.ch/R/daily">https://stat.ethz.ch/R/daily</a>.
</p>
<hr>
<a name="How-can-R-be-installed_003f"></a>
<div class="header">
<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>
<a name="How-can-R-be-installed_003f-1"></a>
<h3 class="section">2.5 How can R be installed?</h3>
<table summary="" class="menu" border="0" cellspacing="0">
<tr><td align="left" valign="top">&bull; <a href="#How-can-R-be-installed-_0028Unix_002dlike_0029" accesskey="1">How can R be installed (Unix-like)</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="#How-can-R-be-installed-_0028Windows_0029" accesskey="2">How can R be installed (Windows)</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="#How-can-R-be-installed-_0028Mac_0029" accesskey="3">How can R be installed (Mac)</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
</table>
<hr>
<a name="How-can-R-be-installed-_0028Unix_002dlike_0029"></a>
<div class="header">
<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>
<a name="How-can-R-be-installed-_0028Unix_002dlike_0029-1"></a>
<h4 class="subsection">2.5.1 How can R be installed (Unix-like)</h4>
<p>If R is already installed, it can be started by typing <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 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 href="#What-machines-does-R-run-on_003f">What machines does R run on?</a>). The file <samp>INSTALL</samp> that comes with the
R distribution contains a brief introduction, and the &ldquo;R Installation
and Administration&rdquo; guide (see <a href="#What-documentation-exists-for-R_003f">What documentation exists for R?</a>)
has full details.
</p>
<p>Note that you need a FORTRAN compiler or perhaps <code>f2c</code> in
addition to 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">$ ./configure
$ make
</pre></div>
<p>If these commands execute successfully, the R binary and a shell script
front-end called <samp>R</samp> are created and copied to the <samp>bin</samp>
directory. You can copy the script to a place where users can invoke
it, for example to <samp>/usr/local/bin</samp>. In addition, plain text help
pages as well as <acronym>HTML</acronym> and LaTeX versions of the documentation are
built.
</p>
<p>Use <kbd>make dvi</kbd> to create DVI versions of the R manuals, such as
<samp>refman.dvi</samp> (an R object reference index) and <samp>R-exts.dvi</samp>,
the &ldquo;R Extension Writers Guide&rdquo;, in the <samp>doc/manual</samp>
subdirectory. These files can be previewed and printed using standard
programs such as <code>xdvi</code> and <code>dvips</code>. You can also use
<kbd>make pdf</kbd> to build PDF (Portable Document Format) version of the
manuals, and view these using e.g. Acrobat. Manuals written in the
<acronym>GNU</acronym> Texinfo system can also be converted to info files
suitable for reading online with Emacs or stand-alone <acronym>GNU</acronym>
Info; use <kbd>make info</kbd> to create these versions (note that this
requires Makeinfo version 4.5).
</p>
<p>Finally, use <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>make
install</kbd>. By default, this will install to the following directories:
</p>
<dl compact="compact">
<dt><samp>${prefix}/bin</samp></dt>
<dd><p>the front-end shell script
</p></dd>
<dt><samp>${prefix}/man/man1</samp></dt>
<dd><p>the man page
</p></dd>
<dt><samp>${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>R_HOME</code>) of the installed system.
</p></dd>
</dl>
<p>In the above, <code>prefix</code> is determined during configuration
(typically <samp>/usr/local</samp>) and can be set by running
<code>configure</code> with the option
</p>
<div class="example">
<pre class="example">$ ./configure --prefix=/where/you/want/R/to/go
</pre></div>
<p>(E.g., the R executable will then be installed into
<samp>/where/you/want/R/to/go/bin</samp>.)
</p>
<p>To install DVI, info and PDF versions of the manuals, use <kbd>make
install-dvi</kbd>, <kbd>make install-info</kbd> and <kbd>make install-pdf</kbd>,
respectively.
</p>
<hr>
<a name="How-can-R-be-installed-_0028Windows_0029"></a>
<div class="header">
<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>
<a name="How-can-R-be-installed-_0028Windows_0029-1"></a>
<h4 class="subsection">2.5.2 How can R be installed (Windows)</h4>
<p>The <samp>bin/windows</samp> directory of a <acronym>CRAN</acronym> site contains binaries for
a base distribution and add-on packages from <acronym>CRAN</acronym> to run on Windows
XP and later (including 64-bit versions of Windows) on ix86 and x86_64
chips. The Windows version of R was created by Robert Gentleman and
Guido Masarotto, and is now being developed and maintained by
<a href="mailto:murdoch@stats.uwo.ca">Duncan Murdoch</a> and
<a href="mailto:Brian.Ripley@R-project.org">Brian D. Ripley</a>.
</p>
<p>The same directory has links to snapshots of the r-patched and r-devel
versions of R.
</p>
<p>See the <a href="https://CRAN.R-project.org/bin/windows/base/rw-FAQ.html">&ldquo;R for Windows <acronym>FAQ</acronym>&rdquo;</a> for more details.
</p>
<hr>
<a name="How-can-R-be-installed-_0028Mac_0029"></a>
<div class="header">
<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>
<a name="How-can-R-be-installed-_0028Mac_0029-1"></a>
<h4 class="subsection">2.5.3 How can R be installed (Mac)</h4>
<p>The <samp>bin/macosx</samp> directory of a <acronym>CRAN</acronym> site contains a standard
Apple installer package to run on OS X 10.6 (&lsquo;Snow Leopard&rsquo;) and later.
Once downloaded and executed, the installer will install the current
release of R and an R.app OS X <acronym>GUI</acronym>. This port of R for OS X
is maintained by <a href="mailto:Simon.Urbanek@R-project.org">Simon Urbanek</a>
(and previously by Stefano Iacus). The
<a href="https://CRAN.R-project.org/bin/macosx/RMacOSX-FAQ.html">&ldquo;R for Mac
OS X <acronym>FAQ</acronym></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 href="https://r.research.att.com">https://r.research.att.com</a>.
</p>
<hr>
<a name="Are-there-Unix_002dlike-binaries-for-R_003f"></a>
<div class="header">
<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>
<a name="Are-there-Unix_002dlike-binaries-for-R_003f-1"></a>
<h3 class="section">2.6 Are there Unix-like binaries for R?</h3>
<p>The <samp>bin/linux</samp> directory of a <acronym>CRAN</acronym> site contains the following
packages.
</p>
<blockquote>
<table summary="">
<thead><tr><th></th><th>CPU</th><th>Versions</th><th>Provider</th></tr></thead>
<tr><td>Debian</td><td>i386/amd64</td><td>squeeze/wheezy</td><td>Johannes Ranke</td></tr>
<tr><td></td><td>armel</td><td>wheezy</td><td>Johannes Ranke</td></tr>
<tr><td>Ubuntu</td><td>i386/amd64</td><td>lucid/precise/trusty</td><td>Michael Rutter</td></tr>
</table>
</blockquote>
<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>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>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>stable</em> distribution of Debian are provided by Johannes Ranke, and
available from <acronym>CRAN</acronym>. See
<a 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.
</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>yum</code>, the RPM installer/updater. Note that the &ldquo;Software&rdquo;
application (gnome-software), which is the default <acronym>GUI</acronym> 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 RPM is a &ldquo;meta-package&rdquo; which installs all the user and
developer components of R (available separately as <code>R-core</code> and
<code>R-devel</code>), as well as <code>R-java</code>, which ensures that R is
configured for use with Java. The R RPM also installs the standalone R
math library (<code>libRmath</code> and <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 RPM becomes publicly
available, as it must pass through the statutory Fedora review process.
RPMs for a selection of R packages are also provided by Fedora. The
Extra Packages for Enterprise Linux (EPEL) project
(<a href="https://fedoraproject.org/wiki/EPEL">https://fedoraproject.org/wiki/EPEL</a>) provides ports of the Fedora
RPMs for RedHat Enterprise Linux and compatible distributions (e.g.,
Centos, Scientific Linux, Oracle Linux).
</p>
<p>See <a 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 RPMs for openSUSE.
</p>
<p>No other binary distributions are currently publically available via
<acronym>CRAN</acronym>.
</p>
<hr>
<a name="What-documentation-exists-for-R_003f"></a>
<div class="header">
<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>
<a name="What-documentation-exists-for-R_003f-1"></a>
<h3 class="section">2.7 What documentation exists for R?</h3>
<p>Online documentation for most of the functions and variables in R
exists, and can be printed on-screen by typing <kbd>help(<var>name</var>)</kbd>
(or <kbd>?<var>name</var></kbd>) at the R prompt, where <var>name</var> is the name 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 be
quoted.)
</p>
<p>This documentation can also be made available as one reference manual
for on-line reading in <acronym>HTML</acronym> and PDF formats, and as hardcopy via
LaTeX, see <a href="#How-can-R-be-installed_003f">How can R be installed?</a>. An up-to-date <acronym>HTML</acronym>
version is always available for web browsing at
<a href="https://stat.ethz.ch/R-manual/">https://stat.ethz.ch/R-manual/</a>.
</p>
<p>Printed copies of the R reference manual for some version(s) are
available from Network Theory Ltd, at
<a href="http://www.network-theory.co.uk/R/base/">http://www.network-theory.co.uk/R/base/</a>. For each set of manuals
sold, the publisher donates USD 10 to the R Foundation (see <a href="#What-is-the-R-Foundation_003f">What is the R Foundation?</a>).
</p>
<p>The R distribution also comes with the following manuals.
</p>
<ul>
<li> &ldquo;An Introduction to R&rdquo; (<samp>R-intro</samp>)
includes information on data types, programming elements, statistical
modeling and graphics. This document is based on the &ldquo;Notes on
<small>S-PLUS</small>&rdquo; by Bill Venables and David Smith.
</li><li> &ldquo;Writing R Extensions&rdquo; (<samp>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
<acronym>API</acronym>.
</li><li> &ldquo;R Data Import/Export&rdquo; (<samp>R-data</samp>)
is a guide to importing and exporting data to and from R.
</li><li> &ldquo;The R Language Definition&rdquo; (<samp>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>R-admin</samp>).
</li><li> &ldquo;R Internals&rdquo; (<samp>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"><a 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>
<p>John M. Chambers (2008), &ldquo;Software for Data Analysis: Programming with
R&rdquo;. Springer, New York, ISBN 978-0-387-75935-7,
<a href="http://statweb.stanford.edu/~jmc4/Rbook/">http://statweb.stanford.edu/~jmc4/Rbook/</a>.
</p>
<p>Peter Dalgaard (2008), &ldquo;Introductory Statistics with R&rdquo;, 2nd edition.
Springer, ISBN 978-0-387-79053-4,
<a 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 href="https://www.bioconductor.org/pub/RBioinf/">https://www.bioconductor.org/pub/RBioinf/</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 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 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;,
<a href="http://www.amstat.org/publications/jcgs/"><em>Journal of
Computational and Graphical Statistics</em></a>, <strong>5</strong>, 299&ndash;314.
</p>
<hr>
<a name="Citing-R"></a>
<div class="header">
<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>
<a name="Citing-R-1"></a>
<h3 class="section">2.8 Citing R</h3>
<p>To cite R in publications, use
</p>
<div class="example">
<pre class="example">@Manual{,
title = {R: A Language and Environment for Statistical
Computing},
author = {{R Core Team}},
organization = {R Foundation for Statistical Computing},
address = {Vienna, Austria},
2016-07-05 18:26:48 +00:00
year = <var>YEAR</var>,
url = {https://www.R-project.org}
}
</pre></div>
2016-07-05 18:26:48 +00:00
<p>where <var>YEAR</var> is the release year of the version of R used and can
determined as <code>R.version$year</code>.
</p>
<p>Citation strings (or BibTeX entries) for R and R packages can also be
obtained by <code>citation()</code>.
</p>
<hr>
<a name="What-mailing-lists-exist-for-R_003f"></a>
<div class="header">
<p>
Next: <a href="#What-is-CRAN_003f" accesskey="n" rel="next">What is CRAN?</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>
<a name="What-mailing-lists-exist-for-R_003f-1"></a>
<h3 class="section">2.9 What mailing lists exist for R?</h3>
<p>Thanks to <a href="mailto:Martin.Maechler@R-project.org">Martin Maechler</a>, there
are several mailing lists devoted to R, including the following:
</p>
<dl compact="compact">
<dt><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>R-packages</code></dt>
<dd><p>A moderated list for announcements on the availability of new or
enhanced contributed packages.
</p></dd>
<dt><code>R-help</code></dt>
<dd><p>The &lsquo;main&rsquo; R mailing list, for discussion about problems and solutions
using R, announcements (not covered by &lsquo;R-announce&rsquo; and &lsquo;R-packages&rsquo;)
about the development of R and the availability of new code.
</p></dd>
<dt><code>R-devel</code></dt>
<dd><p>This list is for questions and discussion about code development in R.
</p></dd>
<dt><code>R-package-devel</code></dt>
<dd><p>A list which which provides a forum for learning about the R package
development process.
</p></dd>
</dl>
<p>Please read the <a href="https://www.R-project.org/posting-guide.html">posting guide</a> <em>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 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>subscribe</samp>&rsquo;
(or &lsquo;<samp>unsubscribe</samp>&rsquo;) in the <em>body</em> of the message (not in the
subject!) to <a href="mailto:R-help-request@lists.R-project.org">R-help-request@lists.R-project.org</a>.
</p>
<p>Send email to <a href="mailto:R-help@lists.R-project.org">R-help@lists.R-project.org</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>R-help</samp>&rsquo; replaced by
&lsquo;<samp>R-announce</samp>&rsquo;, &lsquo;<samp>R-packages</samp>&rsquo;, and &lsquo;<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 href="#R-Bugs">R Bugs</a> for more details.
</p>
<p>See <a 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>
<p>The R Core Team can be reached at <a href="mailto:R-core@lists.R-project.org">R-core@lists.R-project.org</a>
for comments and reports.
</p>
<p>Many of the R project&rsquo;s mailing lists are also available via
<a href="http://gmane.org">Gmane</a>, from which they can be read with a web
browser, using an NNTP news reader, or via RSS feeds. See
<a href="http://dir.gmane.org/index.php?prefix=gmane.comp.lang.r.">http://dir.gmane.org/index.php?prefix=gmane.comp.lang.r.</a> for
the available mailing lists, and <a href="http://www.gmane.org/rss.php">http://www.gmane.org/rss.php</a> for
details on RSS feeds.
</p>
<hr>
<a name="What-is-CRAN_003f"></a>
<div class="header">
<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>
<a name="What-is-CRAN_003f-1"></a>
<h3 class="section">2.10 What is <acronym>CRAN</acronym>?</h3>
<p>The &ldquo;Comprehensive R Archive Network&rdquo; (<acronym>CRAN</acronym>) 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 <acronym>CRAN</acronym> master site at WU (Wirtschaftsuniversit&auml;t Wien) in Austria
can be found at the <acronym>URL</acronym>
</p>
<blockquote>
<p><a 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 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 <acronym>CRAN</acronym> site closest to you to reduce network
load.
</p>
<p>From <acronym>CRAN</acronym>, 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,
OS X, and MS Windows). <acronym>CRAN</acronym> also provides access to
documentation on R, existing mailing lists and the R Bug Tracking
system.
</p>
2016-07-05 18:26:48 +00:00
<p>Since March 2016, &ldquo;old&rdquo; material is made available from a central
<acronym>CRAN</acronym> archive server (<a href="https://CRAN-archive.R-project.org/">https://CRAN-archive.R-project.org/</a>).
</p>
<p>Please always use the <acronym>URL</acronym> of the master site when referring to
<acronym>CRAN</acronym>.
</p>
<hr>
<a name="Can-I-use-R-for-commercial-purposes_003f"></a>
<div class="header">
<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 CRAN?</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>
<a name="Can-I-use-R-for-commercial-purposes_003f-1"></a>
<h3 class="section">2.11 Can I use R for commercial purposes?</h3>
<p>R is released under the
<a href="https://www.gnu.org/licenses/old-licenses/gpl-2.0.html"><acronym>GNU</acronym> General Public License (<acronym>GPL</acronym>), version 2</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 <acronym>GPL</acronym>, 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 href="https://opensource.org/docs/definition.html">Open Source
Definition</a>:
</p>
<blockquote>
<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>
<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>
<a name="Why-is-R-named-R_003f"></a>
<div class="header">
<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>
<a name="Why-is-R-named-R_003f-1"></a>
<h3 class="section">2.12 Why is R named R?</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 href="#What-is-S_003f">What is S?</a>).
</p>
<hr>
<a name="What-is-the-R-Foundation_003f"></a>
<div class="header">
<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>
<a name="What-is-the-R-Foundation_003f-1"></a>
<h3 class="section">2.13 What is the R Foundation?</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 href="https://www.R-project.org/foundation/">https://www.R-project.org/foundation/</a> for more information.
</p>
<hr>
<a name="What-is-R_002dForge_003f"></a>
<div class="header">
<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>
<a name="What-is-R_002dForge_003f-1"></a>
<h3 class="section">2.14 What is R-Forge?</h3>
<p>R-Forge (<a 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 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 href="https://journal.R-project.org/"><em>The R Journal</em></a>, <strong>1</strong>(1):9&ndash;14.
</p>
<hr>
<a name="R-and-S"></a>
<div class="header">
<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">Top</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
</div>
<a name="R-and-S-1"></a>
<h2 class="chapter">3 R and S</h2>
<table summary="" class="menu" border="0" cellspacing="0">
<tr><td align="left" valign="top">&bull; <a href="#What-is-S_003f" accesskey="1">What is S?</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="#What-is-S_002dPLUS_003f" accesskey="2">What is S-PLUS?</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="#What-are-the-differences-between-R-and-S_003f" accesskey="3">What are the differences between R and S?</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="#Is-there-anything-R-can-do-that-S_002dPLUS-cannot_003f" accesskey="4">Is there anything R can do that S-PLUS cannot?</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="#What-is-R_002dplus_003f" accesskey="5">What is R-plus?</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
</table>
<hr>
<a name="What-is-S_003f"></a>
<div class="header">
<p>
Next: <a href="#What-is-S_002dPLUS_003f" accesskey="n" rel="next">What is S-PLUS?</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>
<a name="What-is-S_003f-1"></a>
<h3 class="section">3.1 What is S?</h3>
<p>S is a very high level language and an environment for data analysis and
graphics. In 1998, the Association for Computing Machinery
(<acronym>ACM</acronym>) presented its Software System Award to John M. Chambers,
the principal designer of S, for
</p>
<blockquote>
<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>
<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>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>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>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 href="http://statweb.stanford.edu/~jmc4/Sbook/">http://statweb.stanford.edu/~jmc4/Sbook/</a>).
<p>This &ldquo;<em>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 href="http://statweb.stanford.edu/~jmc4/papers/96.7.ps">http://statweb.stanford.edu/~jmc4/papers/96.7.ps</a>
for further information on the &ldquo;Evolution of the S Language&rdquo;.
</p>
2016-07-05 18:26:48 +00:00
<hr>
<a name="What-is-S_002dPLUS_003f"></a>
<div class="header">
<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>
<a name="What-is-S_002dPLUS_003f-1"></a>
<h3 class="section">3.2 What is <small>S-PLUS</small>?</h3>
<p><small>S-PLUS</small> is a value-added version of S currently sold by
<a href="http://www.tibco.com/">TIBCO Software Inc</a> as &lsquo;TIBCO Spotfire S+&rsquo;.
See <a href="https://en.wikipedia.org/wiki/S-PLUS">https://en.wikipedia.org/wiki/S-PLUS</a> for more information.
</p>
<hr>
<a name="What-are-the-differences-between-R-and-S_003f"></a>
<div class="header">
<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 S-PLUS cannot?</a>, Previous: <a href="#What-is-S_002dPLUS_003f" accesskey="p" rel="prev">What is S-PLUS?</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>
<a name="What-are-the-differences-between-R-and-S_003f-1"></a>
<h3 class="section">3.3 What are the differences between R and S?</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>S-PLUS</small> 3.x and 4.x),
the &ldquo;new S engine&rdquo; (S version 4; <small>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>engines</em>.
</p>
<p>For the remainder of this section, &ldquo;S&rdquo; refers to the S engines and not
the S language.
</p>
<table summary="" class="menu" border="0" cellspacing="0">
<tr><td align="left" valign="top">&bull; <a href="#Lexical-scoping" accesskey="1">Lexical scoping</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="#Models" accesskey="2">Models</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="#Others" accesskey="3">Others</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
</table>
<hr>
<a name="Lexical-scoping"></a>
<div class="header">
<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>
<a name="Lexical-scoping-1"></a>
<h4 class="subsection">3.3.1 Lexical scoping</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>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">
<pre class="example">cube &lt;- function(n) {
sq &lt;- function() n * n
n * sq()
}
</pre></div>
<p>Under S, <code>sq()</code> does not &ldquo;know&rdquo; about the variable <code>n</code>
unless it is defined globally:
</p>
<div class="example">
<pre class="example">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>
<p>In R, the &ldquo;environment&rdquo; created when <code>cube()</code> was invoked is
also looked in:
</p>
<div class="example">
<pre class="example">R&gt; cube(2)
[1] 8
</pre></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>r</em>-th order
statistic from a sample of size <em>n</em> from a (continuous)
distribution. For simplicity, we shall use both the cdf and pdf of the
distribution as explicit arguments. (Example compiled from various
postings by Luke Tierney.)
</p>
<p>The <small>S-PLUS</small> documentation for <code>call()</code> basically suggests the
following:
</p>
<div class="example">
<pre class="example">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>
<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>substitute()</code> and seems to work
under both S and R is
</p>
<div class="example">
<pre class="example">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>
<p>(the <code>eval()</code> is not needed in S).
</p>
<p>However, in R there is a much easier solution:
</p>
<div class="example">
<pre class="example">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>
<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>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>MC()</code> (for &ldquo;make closure&rdquo;):
</p>
<div class="example">
<pre class="example">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>
<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>MC()</code> simply is
</p>
<div class="example">
<pre class="example">MC &lt;- function(f, env) f
</pre></div>
<p>(lexical scope!), a version for S is
</p>
<div class="example">
<pre class="example">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>
<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>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 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;,
<a href="http://www.amstat.org/publications/jcgs/"><em>Journal of
Computational and Graphical Statistics</em></a>, <strong>9</strong>, 491&ndash;508.
</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>.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>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 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>source()</code>.
</p>
<blockquote>
<p><b>Note:</b> If you run R from within Emacs (see <a 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>ess-transcript-mode</code>, as well as save source copies of
all functions and data used.
</p></blockquote>
<hr>
<a name="Models"></a>
<div class="header">
<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>
<a name="Models-1"></a>
<h4 class="subsection">3.3.2 Models</h4>
<p>There are some differences in the modeling code, such as
</p>
<ul>
<li> Whereas in S, you would use <code>lm(y ~ x^3)</code> to regress <code>y</code> on
<code>x^3</code>, in R, you have to insulate powers of numeric vectors (using
<code>I()</code>), i.e., you have to use <code>lm(y ~ I(x^3))</code>.
</li><li> The glm family objects are implemented differently in R and S. The same
functionality is available but the components have different names.
</li><li> Option <code>na.action</code> is set to <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>y ~ x + 0</code> is an alternative to <code>y ~ x - 1</code> for
specifying a model with no intercept. Models with no parameters at all
can be specified by <code>y ~ 0</code>.
</li></ul>
<hr>
<a name="Others"></a>
<div class="header">
<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>
<a name="Others-1"></a>
<h4 class="subsection">3.3.3 Others</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>
<li> In R, if <code>x</code> is a list, then <code>x[i] &lt;- NULL</code> and <code>x[[i]]
&lt;- NULL</code> remove the specified elements from <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>NULL</code> using <code>x[i] &lt;- list(NULL)</code>.)
</li><li> In S, the functions named <code>.First</code> and <code>.Last</code> in the
<samp>.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>--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>--no-site-file</samp> was given. This code is loaded in package
<strong>base</strong>. Then, unless <samp>--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>.RData</samp> in case there is one (unless <samp>--no-restore-data</samp> or
<samp>--no-restore</samp> were specified). Next, a function <code>.First()</code>
is run if found on the search path. Finally, function <code>.First.sys</code>
in the <strong>base</strong> package is run. When terminating an R session, by
default a function <code>.Last</code> is run if found on the search path,
followed by <code>.Last.sys</code>. If needed, the functions <code>.First()</code>
and <code>.Last()</code> should be defined in the appropriate startup
profiles. See the help pages for <code>.First</code> and <code>.Last</code> for
more details.
</p>
</li><li> In R, <code>T</code> and <code>F</code> are just variables being set to <code>TRUE</code>
and <code>FALSE</code>, respectively, but are not reserved words as in S and
hence can be overwritten by the user. (This helps e.g. when you have
factors with levels <code>&quot;T&quot;</code> or <code>&quot;F&quot;</code>.) Hence, when writing code
you should always use <code>TRUE</code> and <code>FALSE</code>.
</li><li> In R, <code>dyn.load()</code> can only load <em>shared objects</em>, as created
for example by <kbd>R CMD SHLIB</kbd>.
</li><li> In R, <code>attach()</code> currently only works for lists and data frames,
but not for directories. (In fact, <code>attach()</code> also works for R
data files created with <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>For()</code> loops are not necessary and hence not supported.
</li><li> In R, <code>assign()</code> uses the argument <samp>envir=</samp> rather than
<samp>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>int *</code> rather than <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>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">x &lt;- 1; fun &lt;- function() {y &lt;- 1; ls()}
</pre></div>
<p>then <code>fun()</code> returns <code>&quot;y&quot;</code> in R and <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>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>x</code> is a matrix, <code>x[, FALSE]</code>
is not <code>NULL</code> but a &ldquo;matrix&rdquo; with 0 columns. Hence, such objects
need to be tested for by checking whether their <code>length()</code> is zero
(which works in both R and S), and not using <code>is.null()</code>.
</li><li> Named vectors are considered vectors in R but not in S (e.g.,
<code>is.vector(c(a = 1:3))</code> returns <code>FALSE</code> in S and <code>TRUE</code>
in R).
</li><li> Data frames are not considered as matrices in R (i.e., if <code>DF</code> is a
data frame, then <code>is.matrix(DF)</code> returns <code>FALSE</code> in R and
<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>value</samp>&rsquo;. E.g., <code>f(a) &lt;- b</code> is
evaluated as <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>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>for()</code> loop is local to the inside
of the loop. In R it is local to the environment where the <code>for()</code>
statement is executed.
</li><li> In S, <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>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>&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>Sys.setlocale()</code> function.
</li><li> In S, <code>missing(<var>arg</var>)</code> remains <code>TRUE</code> if <var>arg</var> is
subsequently modified; in R it doesn&rsquo;t.
</li><li> From R version 1.3.0, <code>data.frame</code> strips <code>I()</code> when creating
(column) names.
</li><li> In R, the string <code>&quot;NA&quot;</code> is not treated as a missing value in a
character variable. Use <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>dump()</code>, <code>dput()</code> and <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>control</code> argument is used, but by default it
is not. By default <code>dump()</code> tries to write code that will evaluate
to reproduce the object, whereas <code>dput()</code> and <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>[</code> using
a character vector index looks only for exact matches (whereas <code>[[</code>
and <code>$</code> allow partial matches). In S, <code>[</code> allows partial
matches.
</li><li> S has a two-argument version of <code>atan</code> and no <code>atan2</code>. A call
in S such as <code>atan(x1, x2)</code> is equivalent to R&rsquo;s <code>atan2(x1,
x2)</code>. However, beware of named arguments since S&rsquo;s <code>atan(x = a, y
= b)</code> is equivalent to R&rsquo;s <code>atan2(y = a, x = b)</code> with the meanings
of <code>x</code> and <code>y</code> interchanged. (R used to have undocumented
support for a two-argument <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>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>
<a name="Is-there-anything-R-can-do-that-S_002dPLUS-cannot_003f"></a>
<div class="header">
<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>
<a name="Is-there-anything-R-can-do-that-S_002dPLUS-cannot_003f-1"></a>
<h3 class="section">3.4 Is there anything R can do that <small>S-PLUS</small> cannot?</h3>
<p>Since almost anything you can do in R has source code that you could
port to <small>S-PLUS</small> with little effort there will never be much you can do
in R that you couldn&rsquo;t do in <small>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>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>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;, <a href="http://www.amstat.org/publications/jcgs/"><em>Journal of Computational and Graphical Statistics</em></a>, <strong>9</strong>,
582&ndash;599.
</p>
<hr>
<a name="What-is-R_002dplus_003f"></a>
<div class="header">
<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 S-PLUS 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>
<a name="What-is-R_002dplus_003f-1"></a>
<h3 class="section">3.5 What is R-plus?</h3>
<p>For a very long time, there was no such thing.
</p>
<p><a href="http://www.xlsolutions-corp.com/">XLSolutions Corporation</a> is
currently beta testing a commercially supported version of R named R+
(read R plus).
</p>
<p><a href="http://www.revolution-computing.com/">Revolution Analytics</a> has
released
<a href="http://www.revolution-computing.com/products/revolution-r.php">REvolution R</a>, an enterprise-class statistical analysis system based on
R, suitable for deployment in professional, commercial and regulated
environments.
</p>
<p>See also
<a 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>
<a name="R-Web-Interfaces"></a>
<div class="header">
<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">Top</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
</div>
<a name="R-Web-Interfaces-1"></a>
<h2 class="chapter">4 R Web Interfaces</h2>
<p><strong>Rweb</strong> is developed and maintained by
<a href="mailto:jeff@math.montana.edu">Jeff Banfield</a>. The
<a href="http://www.math.montana.edu/Rweb/">Rweb Home Page</a> provides access
to all three versions of Rweb&mdash;a simple text entry form that returns
output and graphs, a more sophisticated JavaScript version that provides
a multiple window environment, and a set of point and click modules that
are useful for introductory statistics courses and require no knowledge
of the R language. All of the Rweb versions can analyze Web accessible
datasets if a <acronym>URL</acronym> is provided.
</p>
<p>The paper &ldquo;Rweb: Web-based Statistical Analysis&rdquo;, providing a detailed
explanation of the different versions of Rweb and an overview of how
Rweb works, was published in the Journal of Statistical Software
(<a href="http://www.jstatsoft.org/v04/i01/">http://www.jstatsoft.org/v04/i01/</a>).
</p>
<p><a href="mailto:ulfi@cs.tu-berlin.de">Ulf Bartel</a> has developed
<strong>R-Online</strong>, a simple on-line programming environment for R which
intends to make the first steps in statistical programming with R
(especially with time series) as easy as possible. There is no need for
a local installation since the only requirement for the user is a
JavaScript capable browser. See <a href="http://www.osvisions.com/r_online/">http://www.osvisions.com/r_online/</a>
for more information.
</p>
<p><strong>Rcgi</strong> is a CGI WWW interface to R by <a href="mailto:mjr@dsl.pipex.com">MJ Ray</a>. It had the ability to use &ldquo;embedded code&rdquo;: you could mix
user input and code, allowing the <acronym>HTML</acronym> author to do anything from
load in data sets to enter most of the commands for users without
writing CGI scripts. Graphical output was possible in PostScript or GIF
formats and the executed code was presented to the user for revision.
However, it is not clear if the project is still active.
</p>
<p>There are many additional examples of web interfaces to R which
basically allow to submit R code to a remote server, see for example the
collection of links available from
<a href="http://biostat.mc.vanderbilt.edu/twiki/bin/view/Main/StatCompCourse">http://biostat.mc.vanderbilt.edu/twiki/bin/view/Main/StatCompCourse</a>.
</p>
<p><a href="http://www.warwick.ac.uk/go/dfirth">David Firth</a> has written
<a href="https://CRAN.R-project.org/package=CGIwithR"><strong>CGIwithR</strong></a>, an R add-on package available from <acronym>CRAN</acronym>. It
provides some simple extensions to R to facilitate running R scripts
through the CGI interface to a web server, and allows submission of data
using both GET and POST methods. It is easily installed using Apache
under Linux and in principle should run on any platform that supports R
and a web server provided that the installer has the necessary security
permissions. David&rsquo;s paper &ldquo;CGIwithR: Facilities for Processing Web
Forms Using R&rdquo; was published in the Journal of Statistical Software
(<a href="http://www.jstatsoft.org/v08/i10/">http://www.jstatsoft.org/v08/i10/</a>). The package is now
2016-07-05 18:26:48 +00:00
maintained by <a href="mailto:duncan@wald.ucdavis.edu">Duncan Temple Lang</a>.
and has a web page at <a href="http://www.omegahat.net/CGIwithR/">http://www.omegahat.net/CGIwithR/</a>.
</p>
<p>Jeff Horner is working on the R/Apache Integration Project which embeds
the R interpreter inside Apache 2 (and beyond). A tutorial and
presentation are available from the project web page at
<a href="http://biostat.mc.vanderbilt.edu/twiki/bin/view/Main/RApacheProject">http://biostat.mc.vanderbilt.edu/twiki/bin/view/Main/RApacheProject</a>.
</p>
<p><a href="https://www.rforge.net/Rserve/">Rserve</a> is a project
actively developed by Simon Urbanek. It implements a TCP/IP server which
allows other programs to use facilities of R. Clients are available from
the web site for Java and C++ (and could be written for other languages
that support TCP/IP sockets).
</p>
<p>Two projects use PHP to provide a web interface to R.
<a href="http://steve-chen.net/R_PHP/">R_PHP_Online</a> by Steve Chen (though
it is unclear if this project is still active) is somewhat similar to
the above Rcgi and Rweb. <a href="http://dssm.unipa.it/R-php/?cmd=home">R-php</a> is actively developed by Alfredo Pontillo and Angelo Mineo and
provides both a web interface to R and a set of pre-specified analyses
that need no R code input.
</p>
<p><a href="https://www.bioconductor.org/">webbioc</a> is &ldquo;an integrated web
interface for doing microarray analysis using several of the
Bioconductor packages&rdquo; and is designed to be installed at local sites
as a shared computing resource.
</p>
<p><a href="http://sysbio.mrc-bsu.cam.ac.uk/Rwui">Rwui</a> is a web application to
create user-friendly web interfaces for R scripts. All code for the web
interface is created automatically. There is no need for the user to do
any extra scripting or learn any new scripting techniques.
</p>
<p>The <a href="https://CRAN.R-project.org/package=R.rsp"><strong>R.rsp</strong></a> package by Henrik Bengtsson introduces &ldquo;R Server
Pages&rdquo;. Analogous to Java Server Pages, an R server page is typically
<acronym>HTML</acronym> with embedded R code that gets evaluated when the page is
requested. The package includes an internal cross-platform
<acronym>HTTP</acronym> server implemented in Tcl, so provides a good framework
for including web-based user interfaces in packages. The approach is
similar to the use of the <a href="https://CRAN.R-project.org/package=brew"><strong>brew</strong></a> package with
<a href="http://rapache.net/">Rapache</a> with the advantage of cross-platform
support and easy installation.
</p>
<p>The <a href="https://CRAN.R-project.org/package=Rook"><strong>Rook</strong></a> package by Jeffrey Horner provides a web server
interface borrowing heavily from Ruby&rsquo;s Rack project.
</p>
<p>Finally, <a href="http://code.google.com/p/concerto-platform/">Concerto</a> is
a user friendly open-source Web Interface to R developed at the
Psychometrics Centre of Cambridge University. It was designed as an
online platform to design and run Computerized Adaptive Tests, but can
be also used as a general-purpose R Web Interface. It allows R users
with no programming or web designing background to quickly develop
flexible and powerful online applications, websites, and psychometrics
tests. To maximize its reliability, security, and performance, Concerto
relies on the popular and reliable open-source elements such as MySQL
server (exchange and storage of the data), <a href="https://rstudio.org/">Rstudio</a> (R code designing and testing, file management), CKEditor
(<acronym>HTML</acronym> Layer design), and PHP.
</p>
<hr>
<a name="R-Add_002dOn-Packages"></a>
<div class="header">
<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">Top</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
</div>
<a name="R-Add_002dOn-Packages-1"></a>
<h2 class="chapter">5 R Add-On Packages</h2>
<table summary="" class="menu" border="0" cellspacing="0">
<tr><td align="left" valign="top">&bull; <a href="#Which-add_002don-packages-exist-for-R_003f" accesskey="1">Which add-on packages exist for R?</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="#How-can-add_002don-packages-be-installed_003f" accesskey="2">How can add-on packages be installed?</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="#How-can-add_002don-packages-be-used_003f" accesskey="3">How can add-on packages be used?</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="#How-can-add_002don-packages-be-removed_003f" accesskey="4">How can add-on packages be removed?</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="#How-can-I-create-an-R-package_003f" accesskey="5">How can I create an R package?</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="#How-can-I-contribute-to-R_003f" accesskey="6">How can I contribute to R?</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
</table>
<hr>
<a name="Which-add_002don-packages-exist-for-R_003f"></a>
<div class="header">
<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>
<a name="Which-add_002don-packages-exist-for-R_003f-1"></a>
<h3 class="section">5.1 Which add-on packages exist for R?</h3>
<table summary="" class="menu" border="0" cellspacing="0">
<tr><td align="left" valign="top">&bull; <a href="#Add_002don-packages-in-R" accesskey="1">Add-on packages in R</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="#Add_002don-packages-from-CRAN" accesskey="2">Add-on packages from CRAN</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="#Add_002don-packages-from-Omegahat" accesskey="3">Add-on packages from Omegahat</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="#Add_002don-packages-from-Bioconductor" accesskey="4">Add-on packages from Bioconductor</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="#Other-add_002don-packages" accesskey="5">Other add-on packages</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
</table>
<hr>
<a name="Add_002don-packages-in-R"></a>
<div class="header">
<p>
Next: <a href="#Add_002don-packages-from-CRAN" accesskey="n" rel="next">Add-on packages from CRAN</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>
<a name="Add_002don-packages-in-R-1"></a>
<h4 class="subsection">5.1.1 Add-on packages in R</h4>
<p>The R distribution comes with the following packages:
</p>
<dl compact="compact">
<dt><strong>base</strong></dt>
<dd><p>Base R functions (and datasets before R 2.0.0).
</p></dd>
<dt><strong>compiler</strong></dt>
<dd><p>R byte code compiler (added in R 2.13.0).
</p></dd>
<dt><strong>datasets</strong></dt>
<dd><p>Base R datasets (added in R 2.0.0).
</p></dd>
<dt><strong>grDevices</strong></dt>
<dd><p>Graphics devices for base and grid graphics (added in R 2.0.0).
</p></dd>
<dt><strong>graphics</strong></dt>
<dd><p>R functions for base graphics.
</p></dd>
<dt><strong>grid</strong></dt>
<dd><p>A rewrite of the graphics layout capabilities, plus some support for
interaction.
</p></dd>
<dt><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>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>splines</strong></dt>
<dd><p>Regression spline functions and classes.
</p></dd>
<dt><strong>stats</strong></dt>
<dd><p>R statistical functions.
</p></dd>
<dt><strong>stats4</strong></dt>
<dd><p>Statistical functions using S4 classes.
</p></dd>
<dt><strong>tcltk</strong></dt>
<dd><p>Interface and language bindings to Tcl/Tk <acronym>GUI</acronym> elements.
</p></dd>
<dt><strong>tools</strong></dt>
<dd><p>Tools for package development and administration.
</p></dd>
<dt><strong>utils</strong></dt>
<dd><p>R utility functions.
</p></dd>
</dl>
<p>These &ldquo;base packages&rdquo; were substantially reorganized in R 1.9.0. The
former <strong>base</strong> was split into the four packages <strong>base</strong>,
<strong>graphics</strong>, <strong>stats</strong>, and <strong>utils</strong>. Packages <strong>ctest</strong>,
<strong>eda</strong>, <strong>modreg</strong>, <strong>mva</strong>, <strong>nls</strong>, <strong>stepfun</strong> and
<strong>ts</strong> were merged into <strong>stats</strong>, package <strong>lqs</strong> returned to the
recommended package <a href="https://CRAN.R-project.org/package=MASS"><strong>MASS</strong></a>, and package <strong>mle</strong> moved to
<strong>stats4</strong>.
</p>
<hr>
<a name="Add_002don-packages-from-CRAN"></a>
<div class="header">
<p>
Next: <a href="#Add_002don-packages-from-Omegahat" accesskey="n" rel="next">Add-on packages from Omegahat</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>
<a name="Add_002don-packages-from-CRAN-1"></a>
<h4 class="subsection">5.1.2 Add-on packages from <acronym>CRAN</acronym></h4>
<p>The <acronym>CRAN</acronym> <samp>src/contrib</samp> area contains a wealth of add-on
packages, including the following <em>recommended</em> packages which are
to be included in all binary distributions of R.
</p>
<dl compact="compact">
<dt><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>MASS</strong></dt>
<dd><p>Functions and datasets from the main package of Venables and Ripley,
&ldquo;Modern Applied Statistics with S&rdquo;.
(Contained in the <samp>VR</samp> bundle for R versions prior to 2.10.0.)
</p></dd>
<dt><strong>Matrix</strong></dt>
<dd><p>A Matrix package.
(Recommended for R 2.9.0 or later.)
</p></dd>
<dt><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></dt>
<dd><p>Functions for classification (<em>k</em>-nearest neighbor and LVQ).
(Contained in the <samp>VR</samp> bundle for R versions prior to 2.10.0.)
</p></dd>
<dt><strong>cluster</strong></dt>
<dd><p>Functions for cluster analysis.
</p></dd>
<dt><strong>codetools</strong></dt>
<dd><p>Code analysis tools.
(Recommended for R 2.5.0 or later.)
</p></dd>
<dt><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>lattice</strong></dt>
<dd><p>Lattice graphics, an implementation of Trellis Graphics functions.
</p></dd>
<dt><strong>mgcv</strong></dt>
<dd><p>Routines for GAMs and other generalized ridge regression problems with
multiple smoothing parameter selection by GCV or UBRE.
</p></dd>
<dt><strong>nlme</strong></dt>
<dd><p>Fit and compare Gaussian linear and nonlinear mixed-effects models.
</p></dd>
<dt><strong>nnet</strong></dt>
<dd><p>Software for single hidden layer perceptrons (&ldquo;feed-forward neural
networks&rdquo;), and for multinomial log-linear models.
(Contained in the <samp>VR</samp> bundle for R versions prior to 2.10.0.)
</p></dd>
<dt><strong>rpart</strong></dt>
<dd><p>Recursive PARTitioning and regression trees.
</p></dd>
<dt><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.
(Contained in the <samp>VR</samp> bundle for R versions prior to 2.10.0.)
</p></dd>
<dt><strong>survival</strong></dt>
<dd><p>Functions for survival analysis, including penalized likelihood.
</p></dd>
</dl>
<p>See the <a href="https://CRAN.R-project.org/web/packages/"><acronym>CRAN</acronym>
contributed packages page</a> for more information.
</p>
<p>Many of these packages are categorized into
<a href="https://CRAN.R-project.org/web/views/"><acronym>CRAN</acronym> Task Views</a>, allowing
to browse packages by topic and providing tools to automatically install
all packages for special areas of interest.
</p>
<p>Some <acronym>CRAN</acronym> packages that do not build out of the box on Windows,
require additional software, or are shipping third party libraries for
Windows cannot be made available on <acronym>CRAN</acronym> in form of a Windows binary
packages. Nevertheless, some of these packages are available at the
&ldquo;<acronym>CRAN</acronym> extras&rdquo; repository at
<a href="https://www.stats.ox.ac.uk/pub/RWin/">https://www.stats.ox.ac.uk/pub/RWin/</a> kindly provided by Brian
D. Ripley. Note that this repository is a default repository for recent
versions of R for Windows.
</p>
<hr>
<a name="Add_002don-packages-from-Omegahat"></a>
<div class="header">
<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-from-CRAN" accesskey="p" rel="prev">Add-on packages from CRAN</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>
<a name="Add_002don-packages-from-Omegahat-1"></a>
<h4 class="subsection">5.1.3 Add-on packages from Omegahat</h4>
2016-07-05 18:26:48 +00:00
<p>The <a href="http://www.omegahat.net/">Omega Project for Statistical
Computing</a> provides a variety of open-source software for statistical
applications, with special emphasis on web-based software, Java, the
Java virtual machine, and distributed computing. A <acronym>CRAN</acronym> style
2016-07-05 18:26:48 +00:00
R package repository is available via <a href="http://www.omegahat.net/R/">http://www.omegahat.net/R/</a>.
See <a href="http://www.omegahat.net/">http://www.omegahat.net/</a> for information on most R packages
available from the Omega project.
</p>
<hr>
<a name="Add_002don-packages-from-Bioconductor"></a>
<div class="header">
<p>
Next: <a href="#Other-add_002don-packages" accesskey="n" rel="next">Other add-on packages</a>, Previous: <a href="#Add_002don-packages-from-Omegahat" accesskey="p" rel="prev">Add-on packages from Omegahat</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>
<a name="Add_002don-packages-from-Bioconductor-1"></a>
<h4 class="subsection">5.1.4 Add-on packages from Bioconductor</h4>
<p><a 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 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 href="https://www.bioconductor.org/download/">https://www.bioconductor.org/download/</a> for available packages and a
complete taxonomy via BioC Views.
</p>
<hr>
<a name="Other-add_002don-packages"></a>
<div class="header">
<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>
<a name="Other-add_002don-packages-1"></a>
<h4 class="subsection">5.1.5 Other add-on packages</h4>
<p>Many more packages are available from places other than the three
default repositories discussed above (<acronym>CRAN</acronym>, Bioconductor and
Omegahat). In particular, R-Forge provides a <acronym>CRAN</acronym> style repository
at <a 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>
<a name="How-can-add_002don-packages-be-installed_003f"></a>
<div class="header">
<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>
<a name="How-can-add_002don-packages-be-installed_003f-1"></a>
<h3 class="section">5.2 How can add-on packages be installed?</h3>
<p>(Unix-like only.) The add-on packages on <acronym>CRAN</acronym> come as gzipped tar
files named <code><var>pkg</var>_<var>version</var>.tar.gz</code>, which may in fact be
&ldquo;bundles&rdquo; containing more than one package. Let <var>path</var> be the
path to such a package file. Provided that <code>tar</code> and
<code>gzip</code> are available on your system, type
</p>
<div class="example">
<pre class="example">$ R CMD INSTALL <var>path</var>/<var>pkg</var>_<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>.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">$ R CMD INSTALL -l <var>lib</var> <var>path</var>/<var>pkg</var>_<var>version</var>.tar.gz
</pre></div>
<p>where <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
<acronym>CRAN</acronym>. See the help page for <code>available.packages()</code> for more
information.
</p>
<hr>
<a name="How-can-add_002don-packages-be-used_003f"></a>
<div class="header">
<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>
<a name="How-can-add_002don-packages-be-used_003f-1"></a>
<h3 class="section">5.3 How can add-on packages be used?</h3>
<p>To find out which additional packages are available on your system, type
</p>
<div class="example">
<pre class="example">library()
</pre></div>
<p>at the R prompt.
</p>
<p>This produces something like
</p>
<blockquote>
<table summary="" class="cartouche" border="1"><tr><td>
<div class="smallexample">
<pre class="smallexample">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 Main Package of 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)
class Functions for Classification
cluster Functions for clustering (by 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>pkg</var> by
</p>
<div class="example">
<pre class="example">library(<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">library(help = <var>pkg</var>)
help(package = <var>pkg</var>)
</pre></div>
<p>You can unload the loaded package <var>pkg</var> by
</p>
<div class="example">
<pre class="example">detach(&quot;package:<var>pkg</var>&quot;, unload = TRUE)
</pre></div>
<p>(where <code>unload = TRUE</code> is needed only for packages with a
namespace, see <code>?unload</code>).
</p>
<hr>
<a name="How-can-add_002don-packages-be-removed_003f"></a>
<div class="header">
<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>
<a name="How-can-add_002don-packages-be-removed_003f-1"></a>
<h3 class="section">5.4 How can add-on packages be removed?</h3>
<p>Use
</p>
<div class="example">
<pre class="example">$ R CMD REMOVE <var>pkg_1</var> &hellip; <var>pkg_n</var>
</pre></div>
<p>to remove the packages <var>pkg_1</var>, &hellip;, <var>pkg_n</var> from the
library tree rooted at the first directory given in <code>R_LIBS</code> if this
is set and non-null, and from the default library otherwise. (Versions
of R prior to 1.3.0 removed from the default library by default.)
</p>
<p>To remove from library <var>lib</var>, do
</p>
<div class="example">
<pre class="example">$ R CMD REMOVE -l <var>lib</var> <var>pkg_1</var> &hellip; <var>pkg_n</var>
</pre></div>
<hr>
<a name="How-can-I-create-an-R-package_003f"></a>
<div class="header">
<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>
<a name="How-can-I-create-an-R-package_003f-1"></a>
<h3 class="section">5.5 How can I create an R package?</h3>
<p>A package consists of a subdirectory containing a file
<samp>DESCRIPTION</samp> and the subdirectories <samp>R</samp>, <samp>data</samp>,
<samp>demo</samp>, <samp>exec</samp>, <samp>inst</samp>, <samp>man</samp>, <samp>po</samp>,
<samp>src</samp>, and <samp>tests</samp> (some of which can be missing). The
package subdirectory may also contain files <samp>INDEX</samp>,
<samp>NAMESPACE</samp>, <samp>configure</samp>, <samp>cleanup</samp>, <samp>LICENSE</samp>,
<samp>LICENCE</samp>, <samp>COPYING</samp> and <samp>NEWS</samp>.
</p>
<p>See section &ldquo;Creating R packages&rdquo; in <cite>Writing R Extensions</cite>, for
details. This manual is included in the R distribution, see <a href="#What-documentation-exists-for-R_003f">What documentation exists for R?</a>, and gives information on package
structure, the configure and cleanup mechanisms, and on automated
package checking and building.
</p>
<p>R version 1.3.0 has added the function <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 href="#What-is-CRAN_003f">What is CRAN?</a>, for information on uploading a package to <acronym>CRAN</acronym>.
</p>
<hr>
<a name="How-can-I-contribute-to-R_003f"></a>
<div class="header">
<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>
<a name="How-can-I-contribute-to-R_003f-1"></a>
<h3 class="section">5.6 How can I contribute to R?</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 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>
<a name="R-and-Emacs"></a>
<div class="header">
<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">Top</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
</div>
<a name="R-and-Emacs-1"></a>
<h2 class="chapter">6 R and Emacs</h2>
<table summary="" class="menu" border="0" cellspacing="0">
<tr><td align="left" valign="top">&bull; <a href="#Is-there-Emacs-support-for-R_003f" accesskey="1">Is there Emacs support for R?</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="#Should-I-run-R-from-within-Emacs_003f" accesskey="2">Should I run R from within Emacs?</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="#Debugging-R-from-within-Emacs" accesskey="3">Debugging R from within Emacs</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
</table>
<hr>
<a name="Is-there-Emacs-support-for-R_003f"></a>
<div class="header">
<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>
<a name="Is-there-Emacs-support-for-R_003f-1"></a>
<h3 class="section">6.1 Is there Emacs support for R?</h3>
<p>There is an Emacs package called <acronym>ESS</acronym> (&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>S-PLUS</small>
3.x/4.x/5.x/6.x/7.x), LispStat dialects (XLispStat, ViSta), SAS, Stata,
and BUGS.
</p>
<p><acronym>ESS</acronym> grew out of the need for bug fixes and extensions to
S-mode 4.8 (which was a <acronym>GNU</acronym> Emacs interface to S/<small>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 <acronym>ESS</acronym> 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 <acronym>ESS</acronym> is available via <acronym>CRAN</acronym> or
the <a href="http://ESS.R-project.org/">ESS web page</a>. The <acronym>HTML</acronym> version
of the documentation can be found at <a href="https://stat.ethz.ch/ESS/">https://stat.ethz.ch/ESS/</a>.
</p>
<p><acronym>ESS</acronym> comes with detailed installation instructions.
</p>
<p>For help with <acronym>ESS</acronym>, send email to
<a href="mailto:ESS-help@stat.math.ethz.ch">ESS-help@stat.math.ethz.ch</a>.
</p>
<p>Please send bug reports and suggestions on <acronym>ESS</acronym> to
<a href="mailto:ESS-bugs@stat.math.ethz.ch">ESS-bugs@stat.math.ethz.ch</a>. The easiest way to do this from is
within Emacs by typing <kbd>M-x ess-submit-bug-report</kbd> or using the
[ESS] or [iESS] pulldown menus.
</p>
<hr>
<a name="Should-I-run-R-from-within-Emacs_003f"></a>
<div class="header">
<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>
<a name="Should-I-run-R-from-within-Emacs_003f-1"></a>
<h3 class="section">6.2 Should I run R from within Emacs?</h3>
<p>Yes, <em>definitely</em>. 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>C-u M-x R</kbd> for starting R.
</p>
<hr>
<a name="Debugging-R-from-within-Emacs"></a>
<div class="header">
<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>
<a name="Debugging-R-from-within-Emacs-1"></a>
<h3 class="section">6.3 Debugging R from within Emacs</h3>
<p>To debug R &ldquo;from within Emacs&rdquo;, there are several possibilities. To
use the Emacs GUD (Grand Unified Debugger) library with the recommended
debugger GDB, type <kbd>M-x gdb</kbd> and give the path to the R
<em>binary</em> as argument. At the <code>gdb</code> prompt, set
<code>R_HOME</code> and other environment variables as needed (using e.g.
<kbd>set env R_HOME /path/to/R/</kbd>, but see also below), and start the
binary with the desired arguments (e.g., <kbd>run --quiet</kbd>).
</p>
<p>If you have <acronym>ESS</acronym>, you can do <kbd>C-u M-x R <span class="key">RET</span> - d
<span class="key">SPC</span> g d b <span class="key">RET</span></kbd> to start an inferior R process with arguments
<samp>-d gdb</samp>.
</p>
<p>A third option is to start an inferior R process via <acronym>ESS</acronym>
(<kbd>M-x R</kbd>) and then start GUD (<kbd>M-x gdb</kbd>) giving the R binary
(using its full path name) as the program to debug. Use the program
<code>ps</code> to find the process number of the currently running R
process then use the <code>attach</code> command in gdb to attach it to that
process. One advantage of this method is that you have separate
<code>*R*</code> and <code>*gud-gdb*</code> windows. Within the <code>*R*</code> window
you have all the <acronym>ESS</acronym> facilities, such as object-name
completion, that we know and love.
</p>
<p>When using GUD 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>.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">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>
<a name="R-Miscellanea"></a>
<div class="header">
<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">Top</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
</div>
<a name="R-Miscellanea-1"></a>
<h2 class="chapter">7 R Miscellanea</h2>
<table summary="" class="menu" border="0" cellspacing="0">
<tr><td align="left" valign="top">&bull; <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>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="#How-can-I-save-my-workspace_003f" accesskey="2">How can I save my workspace?</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="#How-can-I-clean-up-my-workspace_003f" accesskey="3">How can I clean up my workspace?</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="#How-can-I-get-eval_0028_0029-and-D_0028_0029-to-work_003f" accesskey="4">How can I get eval() and D() to work?</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="#Why-do-my-matrices-lose-dimensions_003f" accesskey="5">Why do my matrices lose dimensions?</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="#How-does-autoloading-work_003f" accesskey="6">How does autoloading work?</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="#How-should-I-set-options_003f" accesskey="7">How should I set options?</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="#How-do-file-names-work-in-Windows_003f" accesskey="8">How do file names work in Windows?</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="#Why-does-plotting-give-a-color-allocation-error_003f" accesskey="9">Why does plotting give a color allocation error?</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="#How-do-I-convert-factors-to-numeric_003f">How do I convert factors to numeric?</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="#Are-Trellis-displays-implemented-in-R_003f">Are Trellis displays implemented in R?</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="#What-are-the-enclosing-and-parent-environments_003f">What are the enclosing and parent environments?</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="#How-can-I-substitute-into-a-plot-label_003f">How can I substitute into a plot label?</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="#What-are-valid-names_003f">What are valid names?</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="#Are-GAMs-implemented-in-R_003f">Are GAMs implemented in R?</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">&bull; <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>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="#Why-does-outer_0028_0029-behave-strangely-with-my-function_003f">Why does outer() behave strangely with my function?</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">&bull; <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 anova() depend on the order of factors in the model?</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="#How-do-I-produce-PNG-graphics-in-batch-mode_003f">How do I produce PNG graphics in batch mode?</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="#How-can-I-get-command-line-editing-to-work_003f">How can I get command line editing to work?</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="#How-can-I-turn-a-string-into-a-variable_003f">How can I turn a string into a variable?</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="#Why-do-lattice_002ftrellis-graphics-not-work_003f">Why do lattice/trellis graphics not work?</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="#How-can-I-sort-the-rows-of-a-data-frame_003f">How can I sort the rows of a data frame?</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="#Why-does-the-help_002estart_0028_0029-search-engine-not-work_003f">Why does the help.start() search engine not work?</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="#Why-did-my-_002eRprofile-stop-working-when-I-updated-R_003f">Why did my .Rprofile stop working when I updated R?</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="#Where-have-all-the-methods-gone_003f">Where have all the methods gone?</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="#How-can-I-create-rotated-axis-labels_003f">How can I create rotated axis labels?</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="#Why-is-read_002etable_0028_0029-so-inefficient_003f">Why is read.table() so inefficient?</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="#What-is-the-difference-between-package-and-library_003f">What is the difference between package and library?</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="#I-installed-a-package-but-the-functions-are-not-there">I installed a package but the functions are not there</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="#Why-doesn_0027t-R-think-these-numbers-are-equal_003f">Why doesn't R think these numbers are equal?</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">&bull; <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>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="#Why-are-powers-of-negative-numbers-wrong_003f">Why are powers of negative numbers wrong?</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">&bull; <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>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="#Why-are-p_002dvalues-not-displayed-when-using-lmer_0028_0029_003f">Why are p-values not displayed when using lmer()?</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="#Why-are-there-unwanted-borders">Why are there unwanted borders</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="#Why-does-backslash-behave-strangely-inside-strings_003f">Why does backslash behave strangely inside strings?</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">&bull; <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>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="#How-do-I-create-a-plot-with-two-y_002daxes_003f">How do I create a plot with two y-axes?</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="#How-do-I-access-the-source-code-for-a-function_003f">How do I access the source code for a function?</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">&bull; <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>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="#Why-is-R-apparently-not-releasing-memory_003f">Why is R apparently not releasing memory?</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="#How-can-I-enable-secure-https-downloads-in-R_003f">How can I enable secure https downloads in R?</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
2016-07-05 18:26:48 +00:00
<tr><td align="left" valign="top">&bull; <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>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
</table>
<hr>
<a name="How-can-I-set-components-of-a-list-to-NULL_003f"></a>
<div class="header">
<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>
<a name="How-can-I-set-components-of-a-list-to-NULL_003f-1"></a>
<h3 class="section">7.1 How can I set components of a list to NULL?</h3>
<p>You can use
</p>
<div class="example">
<pre class="example">x[i] &lt;- list(NULL)
</pre></div>
<p>to set component <code>i</code> of the list <code>x</code> to <code>NULL</code>, similarly
for named components. Do not set <code>x[i]</code> or <code>x[[i]]</code> to
<code>NULL</code>, because this will remove the corresponding component from
the list.
</p>
<p>For dropping the row names of a matrix <code>x</code>, it may be easier to use
<code>rownames(x) &lt;- NULL</code>, similarly for column names.
</p>
<hr>
<a name="How-can-I-save-my-workspace_003f"></a>
<div class="header">
<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>
<a name="How-can-I-save-my-workspace_003f-1"></a>
<h3 class="section">7.2 How can I save my workspace?</h3>
<p><code>save.image()</code> saves the objects in the user&rsquo;s <code>.GlobalEnv</code> to
the file <samp>.RData</samp> in the R startup directory. (This is also what
happens after <kbd>q(&quot;yes&quot;)</kbd>.) Using <code>save.image(<var>file</var>)</code> one
can save the image under a different name.
</p>
<hr>
<a name="How-can-I-clean-up-my-workspace_003f"></a>
<div class="header">
<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 eval() and D() 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>
<a name="How-can-I-clean-up-my-workspace_003f-1"></a>
<h3 class="section">7.3 How can I clean up my workspace?</h3>
<p>To remove all objects in the currently active environment (typically
<code>.GlobalEnv</code>), you can do
</p>
<div class="example">
<pre class="example">rm(list = ls(all = TRUE))
</pre></div>
<p>(Without <samp>all = TRUE</samp>, only the objects with names not starting
with a &lsquo;<samp>.</samp>&rsquo; are removed.)
</p>
<hr>
<a name="How-can-I-get-eval_0028_0029-and-D_0028_0029-to-work_003f"></a>
<div class="header">
<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>
<a name="How-can-I-get-eval_0028_0029-and-D_0028_0029-to-work_003f-1"></a>
<h3 class="section">7.4 How can I get eval() and D() to work?</h3>
<p>Strange things will happen if you use <code>eval(print(x), envir = e)</code>
or <code>D(x^2, &quot;x&quot;)</code>. The first one will either tell you that
&quot;<code>x</code>&quot; is not found, or print the value of the wrong <code>x</code>.
The other one will likely return zero if <code>x</code> exists, and an 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>&quot;expression&quot;</code> or <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>expression()</code>. For example,
</p>
<div class="example">
<pre class="example">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">D2 &lt;- function(e, n) D(D(e, n), n)
</pre></div>
<p>or
</p>
<div class="example">
<pre class="example">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>deriv()</code> for more examples.
</p>
<hr>
<a name="Why-do-my-matrices-lose-dimensions_003f"></a>
<div class="header">
<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 eval() and D() 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>
<a name="Why-do-my-matrices-lose-dimensions_003f-1"></a>
<h3 class="section">7.5 Why do my matrices lose dimensions?</h3>
<p>When a matrix with a single row or column is created by a subscripting
operation, e.g., <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>feature</em>.
</p>
<p>To prevent this happening, add the option <samp>drop = FALSE</samp> to the
subscripting. For example,
</p>
<div class="example">
<pre class="example">rowmatrix &lt;- mat[2, , drop = FALSE] # <span class="roman">creates a row matrix</span>
colmatrix &lt;- mat[, 2, drop = FALSE] # <span class="roman">creates a column matrix</span>
a &lt;- b[1, 1, 1, drop = FALSE] # <span class="roman">creates a 1 x 1 x 1 array</span>
</pre></div>
<p>The <samp>drop = FALSE</samp> option should be used defensively when
programming. For example, the statement
</p>
<div class="example">
<pre class="example">somerows &lt;- mat[index, ]
</pre></div>
<p>will return a vector rather than a matrix if <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">somerows &lt;- mat[index, , drop = FALSE]
</pre></div>
<hr>
<a name="How-does-autoloading-work_003f"></a>
<div class="header">
<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>
<a name="How-does-autoloading-work_003f-1"></a>
<h3 class="section">7.6 How does autoloading work?</h3>
<p>R has a special environment called <code>.AutoloadEnv</code>. Using
<kbd>autoload(<var>name</var>, <var>pkg</var>)</kbd>, where <var>name</var> and
<var>pkg</var> are strings giving the names of an object and the package
containing it, stores some information in this environment. When R
tries to evaluate <var>name</var>, it loads the corresponding package
<var>pkg</var> and reevaluates <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>autoload()</code> for a very nice example.
</p>
<hr>
<a name="How-should-I-set-options_003f"></a>
<div class="header">
<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>
<a name="How-should-I-set-options_003f-1"></a>
<h3 class="section">7.7 How should I set options?</h3>
<p>The function <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>.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">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">R&gt; test1()
3 3.14
R&gt; test2()
3 3.141593
</pre></div>
<p>What is really used is the <em>global</em> value of <code>.Options</code>, and
using <kbd>options(OPT = VAL)</kbd> correctly updates it. Local copies of
<code>.Options</code>, either in <code>.GlobalEnv</code> or in a function
environment (frame), are just silently disregarded.
</p>
<hr>
<a name="How-do-file-names-work-in-Windows_003f"></a>
<div class="header">
<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>
<a name="How-do-file-names-work-in-Windows_003f-1"></a>
<h3 class="section">7.8 How do file names work in Windows?</h3>
<p>As R uses C-style string handling, &lsquo;<samp>\</samp>&rsquo; is treated as an escape
character, so that for example one can enter a newline as &lsquo;<samp>\n</samp>&rsquo;.
When you really need a &lsquo;<samp>\</samp>&rsquo;, you have to escape it with another
&lsquo;<samp>\</samp>&rsquo;.
</p>
<p>Thus, in filenames use something like <code>&quot;c:\\data\\money.dat&quot;</code>. You
can also replace &lsquo;<samp>\</samp>&rsquo; by &lsquo;<samp>/</samp>&rsquo; (<code>&quot;c:/data/money.dat&quot;</code>).
</p>
<hr>
<a name="Why-does-plotting-give-a-color-allocation-error_003f"></a>
<div class="header">
<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>
<a name="Why-does-plotting-give-a-color-allocation-error_003f-1"></a>
<h3 class="section">7.9 Why does plotting give a color allocation error?</h3>
<p>On an X11 device, plotting sometimes, e.g., when running
<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>One application which is notorious for &ldquo;eating&rdquo; colors is Netscape.
If the problem occurs when Netscape is running, try (re)starting it with
either the <samp>-no-install</samp> (to use the default colormap) or the
<samp>-install</samp> (to install a private colormap) option.
</p>
<p>You could also set the <code>colortype</code> of <code>X11()</code> to
<code>&quot;pseudo.cube&quot;</code> rather than the default <code>&quot;pseudo&quot;</code>. See the
help page for <code>X11()</code> for more information.
</p>
<hr>
<a name="How-do-I-convert-factors-to-numeric_003f"></a>
<div class="header">
<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>
<a name="How-do-I-convert-factors-to-numeric_003f-1"></a>
<h3 class="section">7.10 How do I convert factors to numeric?</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>f</code> is such a
factor object, you can use
</p>
<div class="example">
<pre class="example">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">as.numeric(levels(f))[as.integer(f)]
</pre></div>
<p>In any case, do not call <code>as.numeric()</code> or their likes directly for
the task at hand (as <code>as.numeric()</code> or <code>unclass()</code> give the
internal codes).
</p>
<hr>
<a name="Are-Trellis-displays-implemented-in-R_003f"></a>
<div class="header">
<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>
<a name="Are-Trellis-displays-implemented-in-R_003f-1"></a>
<h3 class="section">7.11 Are Trellis displays implemented in R?</h3>
<p>The recommended package <a href="https://CRAN.R-project.org/package=lattice"><strong>lattice</strong></a> (which is based on base
package <strong>grid</strong>) provides graphical functionality that is compatible
with most Trellis commands.
</p>
<p>You could also look at <code>coplot()</code> and <code>dotchart()</code> which might
do at least some of what you want. Note also that the R version of
<code>pairs()</code> is fairly general and provides most of the functionality
of <code>splom()</code>, and that R&rsquo;s default plot method has an argument
<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>
<a name="What-are-the-enclosing-and-parent-environments_003f"></a>
<div class="header">
<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>
<a name="What-are-the-enclosing-and-parent-environments_003f-1"></a>
<h3 class="section">7.12 What are the enclosing and parent environments?</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>f()</code> inside another function <code>g()</code> its enclosing environment
is the environment inside <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>f()</code> using
<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>lm()</code> at the command line its
parent environment is the global workspace, if you invoke it inside a
function <code>f()</code> then its parent environment is the environment
inside <code>f()</code>. You can find out the parent environment for an
invocation of a function by using <code>parent.frame()</code> or
<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>f()</code> is defined inside another function
<code>g()</code> it will probably be used inside <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>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>always</em> the global workspace, but in R the enclosing environment
is wherever the function was created.
</p>
<hr>
<a name="How-can-I-substitute-into-a-plot-label_003f"></a>
<div class="header">
<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>
<a name="How-can-I-substitute-into-a-plot-label_003f-1"></a>
<h3 class="section">7.13 How can I substitute into a plot label?</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>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>parse()</code> on your pasted character string or use
<code>substitute()</code> on an expression. For example, if <code>ahat</code> is an
estimator of your parameter <em>a</em> of interest, use
</p>
<div class="example">
<pre class="example">title(substitute(hat(a) == ahat, list(ahat = ahat)))
</pre></div>
<p>(note that it is &lsquo;<samp>==</samp>&rsquo; and not &lsquo;<samp>=</samp>&rsquo;). Sometimes <code>bquote()</code>
gives a more compact form, e.g.,
</p>
<div class="example">
<pre class="example">title(bquote(hat(a) = .(ahat)))
</pre></div>
<p>where subexpressions enclosed in &lsquo;<samp>.()</samp>&rsquo; are replaced by their
values.
</p>
<p>There are more examples in the mailing list archives.
</p>
<hr>
<a name="What-are-valid-names_003f"></a>
<div class="header">
<p>
Next: <a href="#Are-GAMs-implemented-in-R_003f" accesskey="n" rel="next">Are GAMs 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>
<a name="What-are-valid-names_003f-1"></a>
<h3 class="section">7.14 What are valid names?</h3>
<p>When creating data frames using <code>data.frame()</code> or
<code>read.table()</code>, R by default ensures that the variable names are
syntactically valid. (The argument <samp>check.names</samp> to these
functions controls whether variable names are checked and adjusted by
<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>
<li> A <em>syntactic name</em> is a string the parser interprets as this type
of expression. It consists of letters, numbers, and the dot and (for
versions of R at least 1.9.0) 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>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>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>assign()</code>).
</li><li> An <em>argument name</em> is what appears to the left of the equals sign
when supplying an argument in a function call (for example,
<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>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>$</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>eval()</code> or <code>attach()</code>, the
element names become object names.)
</li><li> Finally, a <em>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>
<a name="Are-GAMs-implemented-in-R_003f"></a>
<div class="header">
<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>
<a name="Are-GAMs-implemented-in-R_003f-1"></a>
<h3 class="section">7.15 Are GAMs implemented in R?</h3>
<p>Package <a href="https://CRAN.R-project.org/package=gam"><strong>gam</strong></a> from <acronym>CRAN</acronym> 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>gam()</code> function for GAMs in package <a href="https://CRAN.R-project.org/package=mgcv"><strong>mgcv</strong></a>, but it is not
an exact clone of what is described in the White Book (no <code>lo()</code>
for example). Package <a href="https://CRAN.R-project.org/package=gss"><strong>gss</strong></a> can fit spline-based GAMs too. And
if you can accept regression splines you can use <code>glm()</code>. For
Gaussian GAMs you can use <code>bruto()</code> from package <a href="https://CRAN.R-project.org/package=mda"><strong>mda</strong></a>.
</p>
<hr>
<a name="Why-is-the-output-not-printed-when-I-source_0028_0029-a-file_003f"></a>
<div class="header">
<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 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>
<a name="Why-is-the-output-not-printed-when-I-source_0028_0029-a-file_003f-1"></a>
<h3 class="section">7.16 Why is the output not printed when I source() a file?</h3>
<p>Most R commands do not generate any output. The command
</p>
<div class="example">
<pre class="example">1+1
</pre></div>
<p>computes the value 2 and returns it; the command
</p>
<div class="example">
<pre class="example">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>&quot;summary.glm&quot;</code> (see <a href="#How-should-I-write-summary-methods_003f">How should I write summary methods?</a>).
</p>
<p>If you type &lsquo;<samp>1+1</samp>&rsquo; or &lsquo;<samp>summary(glm(y~x+z, family=binomial))</samp>&rsquo; at
the command line the returned value is automatically printed (unless it
is <code>invisible()</code>), but in other circumstances, such as in a
<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">print(1+1)
</pre></div>
<p>or
</p>
<div class="example">
<pre class="example">print(summary(glm(y~x+z, family=binomial)))
</pre></div>
<p>instead, or use <code>source(<var>file</var>, echo=TRUE)</code>.
</p>
<hr>
<a name="Why-does-outer_0028_0029-behave-strangely-with-my-function_003f"></a>
<div class="header">
<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 anova() 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>
<a name="Why-does-outer_0028_0029-behave-strangely-with-my-function_003f-1"></a>
<h3 class="section">7.17 Why does outer() behave strangely with my function?</h3>
<p>As the help for <code>outer()</code> indicates, it does not work on arbitrary
functions the way the <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>outer(x, y, FUN)</code> creates two large vectors
containing every possible combination of elements of <code>x</code> and
<code>y</code> and then passes this to <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>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">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">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>outer()</code> by writing, e.g.,
</p>
<div class="example">
<pre class="example">outer(1:4, 1:2, FUN = wrapper, my.fun = foo, happy = 10)
</pre></div>
<p>Scalar functions can also be vectorized using <code>Vectorize()</code>.
</p>
<hr>
<a name="Why-does-the-output-from-anova_0028_0029-depend-on-the-order-of-factors-in-the-model_003f"></a>
<div class="header">
<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>
<a name="Why-does-the-output-from-anova_0028_0029-depend-on-the-order-of-factors-in-the-model_003f-1"></a>
<h3 class="section">7.18 Why does the output from anova() depend on the order of factors in the model?</h3>
<p>In a model such as <code>~A+B+A:B</code>, R will report the difference in sums
of squares between the models <code>~1</code>, <code>~A</code>, <code>~A+B</code> and
<code>~A+B+A:B</code>. If the model were <code>~B+A+A:B</code>, R would report
differences between <code>~1</code>, <code>~B</code>, <code>~A+B</code>, and
<code>~A+B+A:B</code> . In the first case the sum of squares for <code>A</code> is
comparing <code>~1</code> and <code>~A</code>, in the second case it is comparing
<code>~B</code> and <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>anova(<var>model1</var>,
<var>model2</var>)</code>, and <code>drop1(<var>model1</var>)</code> will show the sums of
squares resulting from dropping single terms.
</p>
<hr>
<a name="How-do-I-produce-PNG-graphics-in-batch-mode_003f"></a>
<div class="header">
<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 anova() 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>
<a name="How-do-I-produce-PNG-graphics-in-batch-mode_003f-1"></a>
<h3 class="section">7.19 How do I produce PNG graphics in batch mode?</h3>
<p>Under a Unix-like, if your installation supports the
<code>type=&quot;cairo&quot;</code> option to the <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>png()</code> by default uses the Quartz device
on OS X, and that too works in batch mode.
</p>
<p>Earlier versions of the <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>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 href="http://www.x.org/">X.Org</a> (possibly as an optional
install), which is an X11 server that does not require a screen; and
there is the <a href="https://CRAN.R-project.org/package=GDD"><strong>GDD</strong></a> package from <acronym>CRAN</acronym>, which produces PNG,
JPEG and GIF bitmaps without X11.
</p>
<hr>
<a name="How-can-I-get-command-line-editing-to-work_003f"></a>
<div class="header">
<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>
<a name="How-can-I-get-command-line-editing-to-work_003f-1"></a>
<h3 class="section">7.20 How can I get command line editing to work?</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 <acronym>GNU</acronym> 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>libreadline-dev</code> (Debian) or
<code>readline-devel</code> (Red Hat).
</p>
<hr>
<a name="How-can-I-turn-a-string-into-a-variable_003f"></a>
<div class="header">
<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>
<a name="How-can-I-turn-a-string-into-a-variable_003f-1"></a>
<h3 class="section">7.21 How can I turn a string into a variable?</h3>
<p>If you have
</p>
<div class="example">
<pre class="example">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">get(varname[1]) + 2
</pre></div>
<p>for
</p>
<div class="example">
<pre class="example">a + 2
</pre></div>
<p>or
</p>
<div class="example">
<pre class="example">assign(varname[1], 2 + 2)
</pre></div>
<p>for
</p>
<div class="example">
<pre class="example">a &lt;- 2 + 2
</pre></div>
<p>or
</p>
<div class="example">
<pre class="example">eval(substitute(lm(y ~ x + variable),
list(variable = as.name(varname[1]))))
</pre></div>
<p>for
</p>
<div class="example">
<pre class="example">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">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>
<a name="Why-do-lattice_002ftrellis-graphics-not-work_003f"></a>
<div class="header">
<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>
<a name="Why-do-lattice_002ftrellis-graphics-not-work_003f-1"></a>
<h3 class="section">7.22 Why do lattice/trellis graphics not work?</h3>
<p>The most likely reason is that you forgot to tell R to display the
graph. Lattice functions such as <code>xyplot()</code> create a graph object,
but do not display it (the same is true of <a href="https://CRAN.R-project.org/package=ggplot2"><strong>ggplot2</strong></a> graphics,
and Trellis graphics in <small>S-PLUS</small>). The <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>source()</code> or inside your own functions you will need an
explicit <code>print()</code> statement.
</p>
<hr>
<a name="How-can-I-sort-the-rows-of-a-data-frame_003f"></a>
<div class="header">
<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>
<a name="How-can-I-sort-the-rows-of-a-data-frame_003f-1"></a>
<h3 class="section">7.23 How can I sort the rows of a data frame?</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>order()</code> (e.g.,
<code>DF[order(DF$a, DF[[&quot;b&quot;]]), ]</code> to sort the data frame <code>DF</code> on
columns named <code>a</code> and <code>b</code>).
</p>
<hr>
<a name="Why-does-the-help_002estart_0028_0029-search-engine-not-work_003f"></a>
<div class="header">
<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>
<a name="Why-does-the-help_002estart_0028_0029-search-engine-not-work_003f-1"></a>
<h3 class="section">7.24 Why does the help.start() search engine not work?</h3>
<p>The browser-based search engine in <code>help.start()</code> utilizes a Java
applet. In order for this to function properly, a compatible version of
Java must installed on your system and linked to your browser, and both
Java <em>and</em> JavaScript need to be enabled in your browser.
</p>
<p>There have been a number of compatibility issues with versions of Java
and of browsers.
For further details please consult section &ldquo;Enabling search in HTML
help&rdquo; in <cite>R Installation and Administration</cite>. This manual is
included in the R distribution, see <a href="#What-documentation-exists-for-R_003f">What documentation exists for R?</a>, and its <acronym>HTML</acronym> version is linked from the <acronym>HTML</acronym>
search page.
</p>
<hr>
<a name="Why-did-my-_002eRprofile-stop-working-when-I-updated-R_003f"></a>
<div class="header">
<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>
<a name="Why-did-my-_002eRprofile-stop-working-when-I-updated-R_003f-1"></a>
<h3 class="section">7.25 Why did my .Rprofile stop working when I updated R?</h3>
<p>Did you read the <samp>NEWS</samp> file? For functions that are not in the
<strong>base</strong> package you need to specify the correct package namespace,
since the code will be run <em>before</em> the packages are loaded. E.g.,
</p>
<div class="example">
<pre class="example">ps.options(horizontal = FALSE)
help.start()
</pre></div>
<p>needs to be
</p>
<div class="example">
<pre class="example">grDevices::ps.options(horizontal = FALSE)
utils::help.start()
</pre></div>
<p>(<code>graphics::ps.options(horizontal = FALSE)</code> in R 1.9.x).
</p>
<hr>
<a name="Where-have-all-the-methods-gone_003f"></a>
<div class="header">
<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>
<a name="Where-have-all-the-methods-gone_003f-1"></a>
<h3 class="section">7.26 Where have all the methods gone?</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>[.terms</code>) use
</p>
<div class="example">
<pre class="example">getS3method(&quot;[&quot;, &quot;terms&quot;)
</pre></div>
<p>To see the code for an unexported function <code>foo()</code> in the namespace
of package <code>&quot;bar&quot;</code> use <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>
<a name="How-can-I-create-rotated-axis-labels_003f"></a>
<div class="header">
<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>
<a name="How-can-I-create-rotated-axis-labels_003f-1"></a>
<h3 class="section">7.27 How can I create rotated axis labels?</h3>
<p>To rotate axis labels (using base graphics), you need to use
<code>text()</code>, rather than <code>mtext()</code>, as the latter does not
support <code>par(&quot;srt&quot;)</code>.
</p>
<div class="example">
<pre class="example">## <span class="roman">Increase bottom margin to make room for rotated labels</span>
par(mar = c(7, 4, 4, 2) + 0.1)
## <span class="roman">Create plot with no x axis and no x axis label</span>
plot(1 : 8, xaxt = &quot;n&quot;, xlab = &quot;&quot;)
## <span class="roman">Set up x axis with tick marks alone</span>
axis(1, labels = FALSE)
## <span class="roman">Create some text labels</span>
labels &lt;- paste(&quot;Label&quot;, 1:8, sep = &quot; &quot;)
## <span class="roman">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="roman">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>srt = 45</code> for text
rotation angle, <code>adj = 1</code> to place the right end of text at the
tick marks, and <code>xpd = TRUE</code> to allow for text outside the plot
region. You can adjust the value of the <code>0.25</code> offset as required
to move the axis labels up or down relative to the x axis. See
<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>R News</em>, <strong>3/2</strong>, 7&ndash;12.
</p>
<hr>
<a name="Why-is-read_002etable_0028_0029-so-inefficient_003f"></a>
<div class="header">
<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>
<a name="Why-is-read_002etable_0028_0029-so-inefficient_003f-1"></a>
<h3 class="section">7.28 Why is read.table() so inefficient?</h3>
<p>By default, <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>colClasses</code> argument to specify the classes to be assumed for the
columns of the table.
</p>
<hr>
<a name="What-is-the-difference-between-package-and-library_003f"></a>
<div class="header">
<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>
<a name="What-is-the-difference-between-package-and-library_003f-1"></a>
<h3 class="section">7.29 What is the difference between package and library?</h3>
<p>A <em>package</em> is a standardized collection of material extending R,
e.g. providing code, data, or documentation. A <em>library</em> is a
place (directory) where R knows to find packages it can use (i.e., which
were <em>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>library</code>.
I.e., <code>library()</code> is employed to load a package from libraries
containing packages.
</p>
<p>See <a 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>R News</em>, <strong>3/3</strong>,
37&ndash;39.
</p>
<hr>
<a name="I-installed-a-package-but-the-functions-are-not-there"></a>
<div class="header">
<p>
Next: <a href="#Why-doesn_0027t-R-think-these-numbers-are-equal_003f" accesskey="n" rel="next">Why doesn'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>
<a name="I-installed-a-package-but-the-functions-are-not-there-1"></a>
<h3 class="section">7.30 I installed a package but the functions are not there</h3>
<p>To actually <em>use</em> the package, it needs to be <em>loaded</em> using
<code>library()</code>.
</p>
<p>See <a href="#R-Add_002dOn-Packages">R Add-On Packages</a> and <a href="#What-is-the-difference-between-package-and-library_003f">What is the difference between package and library?</a> for more information.
</p>
<hr>
<a name="Why-doesn_0027t-R-think-these-numbers-are-equal_003f"></a>
<div class="header">
<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>
<a name="Why-doesn_0027t-R-think-these-numbers-are-equal_003f-1"></a>
<h3 class="section">7.31 Why doesn&rsquo;t R think these numbers are equal?</h3>
2016-07-05 18:26:48 +00:00
<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">R&gt; a &lt;- sqrt(2)
R&gt; a * a == 2
[1] FALSE
R&gt; a * a - 2
[1] 4.440892e-16
2016-07-05 18:26:48 +00:00
R&gt; print(a * a, digits = 18)
[1] 2.00000000000000044
</pre></div>
<p>The function <code>all.equal()</code> compares two objects using a numeric
tolerance of <code>.Machine$double.eps ^ 0.5</code>. If you want much greater
accuracy than this you will need to consider error propagation
carefully.
</p>
2016-07-05 18:26:48 +00:00
<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>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 href="http://link.springer.com/content/pdf/bbm%3A978-1-4939-2122-5%2F1.pdf">http://link.springer.com/content/pdf/bbm%3A978-1-4939-2122-5%2F1.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>ACM Computing Surveys</em>, <strong>23/1</strong>, 5&ndash;48, also available via
<a href="http://www.validlab.com/goldberg/paper.pdf">http://www.validlab.com/goldberg/paper.pdf</a>.
</p>
2016-07-05 18:26:48 +00:00
<p>Here is another example, this time using addition:
</p>
2016-07-05 18:26:48 +00:00
<div class="example">
<pre class="example">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>
<a name="How-can-I-capture-or-ignore-errors-in-a-long-simulation_003f"></a>
<div class="header">
<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'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>
<a name="How-can-I-capture-or-ignore-errors-in-a-long-simulation_003f-1"></a>
<h3 class="section">7.32 How can I capture or ignore errors in a long simulation?</h3>
<p>Use <code>try()</code>, which returns an object of class <code>&quot;try-error&quot;</code>
instead of an error, or preferably <code>tryCatch()</code>, where the return
value can be configured more flexibly. For example
</p>
<div class="example">
<pre class="example">beta[i,] &lt;- tryCatch(coef(lm(formula, data)),
error = function(e) rep(NaN, 4))
</pre></div>
<p>would return the coefficients if the <code>lm()</code> call succeeded and
would return <code>c(NaN, NaN, NaN, NaN)</code> if it failed (presumably there
are supposed to be 4 coefficients in this example).
</p>
<hr>
<a name="Why-are-powers-of-negative-numbers-wrong_003f"></a>
<div class="header">
<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>
<a name="Why-are-powers-of-negative-numbers-wrong_003f-1"></a>
<h3 class="section">7.33 Why are powers of negative numbers wrong?</h3>
<p>You are probably seeing something like
</p>
<div class="example">
<pre class="example">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">R&gt; (-2)^2
[1] 4
</pre></div>
<p>to get the square of <em>-2</em>.
</p>
<p>The precedence rules are documented in <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">R&gt; as.list(quote(-2^2))
[[1]]
`-`
[[2]]
2^2
</pre></div>
<hr>
<a name="How-can-I-save-the-result-of-each-iteration-in-a-loop-into-a-separate-file_003f"></a>
<div class="header">
<p>
Next: <a href="#Why-are-p_002dvalues-not-displayed-when-using-lmer_0028_0029_003f" accesskey="n" rel="next">Why are p-values not displayed when using lmer()?</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>
<a name="How-can-I-save-the-result-of-each-iteration-in-a-loop-into-a-separate-file_003f-1"></a>
<h3 class="section">7.34 How can I save the result of each iteration in a loop into a separate file?</h3>
<p>One way is to use <code>paste()</code> (or <code>sprintf()</code>) to concatenate a
stem filename and the iteration number while <code>file.path()</code>
constructs the path. For example, to save results into files
<samp>result1.rda</samp>, &hellip;, <samp>result100.rda</samp> in the subdirectory
<samp>Results</samp> of the current working directory, one can use
</p>
<div class="example">
<pre class="example">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>
<a name="Why-are-p_002dvalues-not-displayed-when-using-lmer_0028_0029_003f"></a>
<div class="header">
<p>
Next: <a href="#Why-are-there-unwanted-borders" accesskey="n" rel="next">Why are there unwanted borders</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>
<a name="Why-are-p_002dvalues-not-displayed-when-using-lmer_0028_0029_003f-1"></a>
<h3 class="section">7.35 Why are <em>p</em>-values not displayed when using lmer()?</h3>
<p>Doug Bates has kindly provided an extensive response in a post to the
r-help list, which can be reviewed at
<a 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>
<a name="Why-are-there-unwanted-borders"></a>
<div class="header">
<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 p-values not displayed when using lmer()?</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>
<a name="Why-are-there-unwanted-borders_002c-lines-or-grid_002dlike-artifacts-when-viewing-a-plot-saved-to-a-PS-or-PDF-file_003f"></a>
<h3 class="section">7.36 Why are there unwanted borders, lines or grid-like artifacts when viewing a plot saved to a PS or PDF file?</h3>
<p>This can occur when using functions such as <code>polygon()</code>,
<code>filled.contour()</code>, <code>image()</code> or other functions which may
call these internally. In the case of <code>polygon()</code>, you may observe
unwanted borders between the polygons even when setting the
<code>border</code> argument to <code>NA</code> or <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 compact="compact">
<dt>Acrobat Reader (cross platform)
<a name="index-Acrobat-Reader-_0028cross-platform_0029"></a>
</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>Preview (OS X)
<a name="index-Preview-_0028OS-X_0029"></a>
</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>GSview (cross platform)
<a name="index-GSview-_0028cross-platform_0029"></a>
</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>gv (Unix-like X)
<a name="index-gv-_0028Unix_002dlike-X_0029"></a>
</dt>
<dd><p>There is an option to enable/disable anti-aliasing.
Disable this option.
</p></dd>
<dt>Evince (Linux/GNOME)
<a name="index-Evince-_0028Linux_002fGNOME_0029"></a>
</dt>
<dd><p>There is not an option to disable anti-aliasing in this viewer.
</p></dd>
<dt>Okular (Linux/KDE)
<a name="index-Okular-_0028Linux_002fKDE_0029"></a>
</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="smallexample">
<pre class="smallexample">$ kwriteconfig --file okularpartrc --group 'Dlg Performance' \
--key GraphicsAntialias Disabled
</pre></div>
<p>Then restart Okular. Change the final word to &lsquo;<samp>Enabled</samp>&rsquo; to restore
the original setting.
</p></dd>
</dl>
<hr>
<a name="Why-does-backslash-behave-strangely-inside-strings_003f"></a>
<div class="header">
<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</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>
<a name="Why-does-backslash-behave-strangely-inside-strings_003f-1"></a>
<h3 class="section">7.37 Why does backslash behave strangely inside strings?</h3>
<p>This question most often comes up in relation to file names (see
<a 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>\</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>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">&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>escape sequences</em> &lsquo;<samp>\&quot;</samp>&rsquo; and &lsquo;<samp>\n</samp>&rsquo; represent a double
quote and the newline character respectively. Printing text strings,
using <code>print()</code> or by typing the name at the prompt will use the
escape sequences too, but the <code>cat()</code> function will display the
string as-is. Notice that &lsquo;<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">&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">&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>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>\p</samp>&rsquo;
was quietly interpreted as just &lsquo;<samp>p</samp>&rsquo;. Current versions of R emit a
warning.
</p>
<hr>
<a name="How-can-I-put-error-bars-or-confidence-bands-on-my-plot_003f"></a>
<div class="header">
<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>
<a name="How-can-I-put-error-bars-or-confidence-bands-on-my-plot_003f-1"></a>
<h3 class="section">7.38 How can I put error bars or confidence bands on my plot?</h3>
<p>Some functions will display a particular kind of plot with error bars,
such as the <code>bar.err()</code> function in the <a href="https://CRAN.R-project.org/package=agricolae"><strong>agricolae</strong></a>
package, the <code>plotCI()</code> function in the <a href="https://CRAN.R-project.org/package=gplots"><strong>gplots</strong></a> package,
the <code>plotCI()</code> and <code>brkdn.plot()</code> functions in the
<a href="https://CRAN.R-project.org/package=plotrix"><strong>plotrix</strong></a> package and the <code>error.bars()</code>,
<code>error.crosses()</code> and <code>error.bars.by()</code> functions in the
<a href="https://CRAN.R-project.org/package=psych"><strong>psych</strong></a> package. Within these types of functions, some will
accept the measures of dispersion (e.g., <code>plotCI</code>), some will
calculate the dispersion measures from the raw values (<code>bar.err</code>,
<code>brkdn.plot</code>), and some will do both (<code>error.bars</code>). Still
other functions will just display error bars, like the dispersion
function in the <a href="https://CRAN.R-project.org/package=plotrix"><strong>plotrix</strong></a> package. Most of the above functions
use the <code>arrows()</code> function in the base <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>grid.arrow()</code> function in the <strong>grid</strong>
package, and the <code>geom_errorbar()</code>, <code>geom_errorbarh()</code>,
<code>geom_pointrange()</code>, <code>geom_linerange()</code>,
<code>geom_crossbar()</code> and <code>geom_ribbon()</code> functions in the
<a href="https://CRAN.R-project.org/package=ggplot2"><strong>ggplot2</strong></a> package. In the lattice system, error bars can be
displayed with <code>Dotplot()</code> or <code>xYplot()</code> in the
<a href="https://CRAN.R-project.org/package=Hmisc"><strong>Hmisc</strong></a> package and <code>segplot()</code> in the
<a href="https://CRAN.R-project.org/package=latticeExtra"><strong>latticeExtra</strong></a> package.
</p>
<hr>
<a name="How-do-I-create-a-plot-with-two-y_002daxes_003f"></a>
<div class="header">
<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>
<a name="How-do-I-create-a-plot-with-two-y_002daxes_003f-1"></a>
<h3 class="section">7.39 How do I create a plot with two y-axes?</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>par(new=TRUE)</code> (see
<code>?par</code>); functions <code>twoord.plot()</code> (in the <a href="https://CRAN.R-project.org/package=plotrix"><strong>plotrix</strong></a>
package) and <code>doubleYScale()</code> (in the <a href="https://CRAN.R-project.org/package=latticeExtra"><strong>latticeExtra</strong></a>
package) automate the process somewhat.
</p>
<hr>
<a name="How-do-I-access-the-source-code-for-a-function_003f"></a>
<div class="header">
<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>
<a name="How-do-I-access-the-source-code-for-a-function_003f-1"></a>
<h3 class="section">7.40 How do I access the source code for a function?</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>R News</em>, <strong>6/4</strong>,
43&ndash;45 (<a 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>
<a name="Why-does-summary_0028_0029-report-strange-results-for-the-R_005e2-estimate-when-I-fit-a-linear-model-with-no-intercept_003f"></a>
<div class="header">
<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>
<a name="Why-does-summary_0028_0029-report-strange-results-for-the-R_005e2-estimate-when-I-fit-a-linear-model-with-no-intercept_003f-1"></a>
<h3 class="section">7.41 Why does summary() report strange results for the R^2 estimate when I fit a linear model with no intercept?</h3>
<p>As described in <code>?summary.lm</code>, when the intercept is zero (e.g.,
from <code>y ~ x - 1</code> or <code>y ~ x + 0</code>), <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>
<li> Otherwise the <em>R^2</em> could be negative (because the model with zero
intercept can fit <em>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>a priori</em> that
<em>E[Y]=0</em> when <em>x=0</em> then the &lsquo;null&rsquo; model that you should
compare to the fitted line, the model where <em>x</em> doesn&rsquo;t explain any
of the variance, is the model where <em>E[Y]=0</em> everywhere. (If you
don&rsquo;t know a priori that <em>E[Y]=0</em> when <em>x=0</em>, then you
probably shouldn&rsquo;t be fitting a line through the origin.)
</p>
<hr>
<a name="Why-is-R-apparently-not-releasing-memory_003f"></a>
<div class="header">
<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>
<a name="Why-is-R-apparently-not-releasing-memory_003f-1"></a>
<h3 class="section">7.42 Why is R apparently not releasing memory?</h3>
<p>This question is often asked in different flavors along the lines of
&ldquo;I have removed objects in R and run <code>gc()</code> and yet
<code>ps</code>/<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>ps</code> or <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>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>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>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>mmap</code> and thus not affected. On Linux (and possibly other
Unix-like systems) it is possible to use the <code>mallinfo</code> system call
(also see the <a 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>
<a name="How-can-I-enable-secure-https-downloads-in-R_003f"></a>
<div class="header">
<p>
2016-07-05 18:26:48 +00:00
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>
<a name="How-can-I-enable-secure-https-downloads-in-R_003f-1"></a>
<h3 class="section">7.43 How can I enable secure https downloads in R?</h3>
<p>When R transfers files over <acronym>HTTP</acronym> (e.g., using the
<code>install.packages()</code> or <code>download.file()</code> function), a
download method is chosen based on the <samp>download.file.method</samp>
option. There are several methods available and the default behavior if
no option is explicitly specified is to use R&rsquo;s internal <acronym>HTTP</acronym>
implementation. In most circumstances this internal method will not
support <acronym>HTTPS</acronym> URLs so you will need to override the default:
this is done automatically for such URLs as from R 3.2.2.
</p>
<p>R versions 3.2.0 and greater include two download methods
(<code>&quot;libcurl&quot;</code> and <code>&quot;wininet&quot;</code>) that both support
<acronym>HTTPS</acronym> connections: we recommend that you use these methods.
The requisite code to add to <samp>.Rprofile</samp> or <samp>Rprofile.site</samp> is:
</p>
<div class="example">
2016-07-05 18:26:48 +00:00
<pre class="example">options(download.file.method = &quot;wininet&quot;, url.method = &quot;wininet&quot;)
<span class="roman">(Windows)</span>
options(download.file.method = &quot;libcurl&quot;, url.method = &quot;libcurl&quot;)
<span class="roman">(Linux and OS X)</span>
</pre></div>
<p>(Method <code>&quot;wininet&quot;</code> is the default on Windows as from R 3.2.2.)
</p>
<p>Note that the <code>&quot;libcurl&quot;</code> method may or may not have been compiled
in. In the case that it was not, i.e.. <code>capabilities(&quot;libcurl&quot;) ==
FALSE</code>, we recommend method <code>&quot;wget&quot;</code> on Linux and <code>&quot;curl&quot;</code> on
OS X. It is possible that system versions of <code>&quot;libcurl&quot;</code>,
<code>wget</code> or <code>curl</code> may have been compiled without
<acronym>HTTPS</acronym> support, but this is unlikely. As from R 3.3.0
<code>&quot;libcurl&quot;</code> with <acronym>HTTPS</acronym> support is required except on
Windows.
</p>
2016-07-05 18:26:48 +00:00
<hr>
<a name="How-can-I-get-CRAN-package-binaries-for-outdated-versions-of-R_003f"></a>
<div class="header">
<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>
<a name="How-can-I-get-CRAN-package-binaries-for-outdated-versions-of-R_003f-1"></a>
<h3 class="section">7.44 How can I get CRAN package binaries for outdated versions of R?</h3>
2016-07-05 18:26:48 +00:00
<p>Since March 2016, Windows and OS X binaries of <acronym>CRAN</acronym> packages for old
versions of R (released more than 5 years ago) are made available from a
central <acronym>CRAN</acronym> archive server instead of the <acronym>CRAN</acronym> mirrors. To get
these, one should set the <acronym>CRAN</acronym> &ldquo;mirror&rdquo; element of the <code>repos</code>
option accordingly, by something like
</p><div class="example">
<pre class="example">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>?options</code> for more information).
</p>
<hr>
<a name="R-Programming"></a>
<div class="header">
<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">Top</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
</div>
<a name="R-Programming-1"></a>
<h2 class="chapter">8 R Programming</h2>
<table summary="" class="menu" border="0" cellspacing="0">
<tr><td align="left" valign="top">&bull; <a href="#How-should-I-write-summary-methods_003f" accesskey="1">How should I write summary methods?</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="#How-can-I-debug-dynamically-loaded-code_003f" accesskey="2">How can I debug dynamically loaded code?</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="#How-can-I-inspect-R-objects-when-debugging_003f" accesskey="3">How can I inspect R objects when debugging?</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="#How-can-I-change-compilation-flags_003f" accesskey="4">How can I change compilation flags?</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="#How-can-I-debug-S4-methods_003f" accesskey="5">How can I debug S4 methods?</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
</table>
<hr>
<a name="How-should-I-write-summary-methods_003f"></a>
<div class="header">
<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>
<a name="How-should-I-write-summary-methods_003f-1"></a>
<h3 class="section">8.1 How should I write summary methods?</h3>
<p>Suppose you want to provide a summary method for class <code>&quot;foo&quot;</code>.
Then <code>summary.foo()</code> should not print anything, but return an
object of class <code>&quot;summary.foo&quot;</code>, <em>and</em> you should write a
method <code>print.summary.foo()</code> which nicely prints the summary
information and invisibly returns its object. This approach is
preferred over having <code>summary.foo()</code> print summary information and
return something useful, as sometimes you need to grab something
computed by <code>summary()</code> inside a function or similar. In such
cases you don&rsquo;t want anything printed.
</p>
<hr>
<a name="How-can-I-debug-dynamically-loaded-code_003f"></a>
<div class="header">
<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>
<a name="How-can-I-debug-dynamically-loaded-code_003f-1"></a>
<h3 class="section">8.2 How can I debug dynamically loaded code?</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 section &ldquo;Finding entry points in dynamically loaded code&rdquo; in
<cite>Writing R Extensions</cite>. This manual is included in the R
distribution, see <a href="#What-documentation-exists-for-R_003f">What documentation exists for R?</a>.
</p>
<hr>
<a name="How-can-I-inspect-R-objects-when-debugging_003f"></a>
<div class="header">
<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>
<a name="How-can-I-inspect-R-objects-when-debugging_003f-1"></a>
<h3 class="section">8.3 How can I inspect R objects when debugging?</h3>
<p>The most convenient way is to call <code>R_PV</code> from the symbolic
debugger.
</p>
<p>See section &ldquo;Inspecting R objects when debugging&rdquo; in <cite>Writing R
Extensions</cite>.
</p>
<hr>
<a name="How-can-I-change-compilation-flags_003f"></a>
<div class="header">
<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>
<a name="How-can-I-change-compilation-flags_003f-1"></a>
<h3 class="section">8.4 How can I change compilation flags?</h3>
<p>Suppose you have C code file for dynloading into R, but you want to use
<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 Makevars configuration
files in <samp>$<code>HOME</code>/.R</samp> to override the default flags.
See section &ldquo;Add-on packages&rdquo; in <cite>R Installation and
Administration</cite>.
</p>
<p>For earlier versions of R, you could change the file
<samp><var>R_HOME</var>/etc/Makeconf</samp> to reflect your preferences, or (at
least for systems using <acronym>GNU</acronym> Make) override them by the
environment variable <code>MAKEFLAGS</code>.
See section &ldquo;Creating shared objects&rdquo; in <cite>Writing R Extensions</cite>.
</p>
<hr>
<a name="How-can-I-debug-S4-methods_003f"></a>
<div class="header">
<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>
<a name="How-can-I-debug-S4-methods_003f-1"></a>
<h3 class="section">8.5 How can I debug S4 methods?</h3>
<p>Use the <code>trace()</code> function with argument <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>?trace</code> for
details.
</p>
<hr>
<a name="R-Bugs"></a>
<div class="header">
<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">Top</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
</div>
<a name="R-Bugs-1"></a>
<h2 class="chapter">9 R Bugs</h2>
<table summary="" class="menu" border="0" cellspacing="0">
<tr><td align="left" valign="top">&bull; <a href="#What-is-a-bug_003f" accesskey="1">What is a bug?</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="#How-to-report-a-bug" accesskey="2">How to report a bug</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
</table>
<hr>
<a name="What-is-a-bug_003f"></a>
<div class="header">
<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>
<a name="What-is-a-bug_003f-1"></a>
<h3 class="section">9.1 What is a bug?</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>.C()</code>, <code>.Fortran()</code>, <code>.External()</code> or <code>.Call()</code> (or
<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>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>0.28 * 100 != 28</code> or <code>0.1 + 0.2 != 0.3</code>, are not a bug.
See <a href="#Why-doesn_0027t-R-think-these-numbers-are-equal_003f">Why doesn'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>
<hr>
<a name="How-to-report-a-bug"></a>
<div class="header">
<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>
<a name="How-to-report-a-bug-1"></a>
<h3 class="section">9.2 How to report a bug</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>version</kbd> in
R to print this.
</p>
<p>The most important principle in reporting a bug is to report
<em>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">R&gt; data.frame(x, y, z, monday, tuesday)
</pre></div>
<p>never returns. Do not report that <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>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>&quot;[&quot;()</code> that had a bug causing R&rsquo;s internal data
structures to be corrupted and making the <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 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>--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 href="https://bugs.R-project.org/">https://bugs.R-project.org/</a>. Second, consult
<a 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>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>bug.report()</code>.
For reports on R this will open the Web page at
<a 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.
</p>
<p>There is a section of the bug repository for suggestions for
enhancements for R labelled &lsquo;<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>Wishlist:</samp>&rsquo;.
</p>
<p>Comments on and suggestions for the Windows port of R should be sent to
<a href="mailto:R-windows@R-project.org">R-windows@R-project.org</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>.po</samp>&rsquo; file)
or to the translation team as listed at
<a href="https://developer.R-project.org/TranslationTeams.html">https://developer.R-project.org/TranslationTeams.html</a>.
</p>
<hr>
<a name="Acknowledgments"></a>
<div class="header">
<p>
Previous: <a href="#R-Bugs" accesskey="p" rel="prev">R Bugs</a>, Up: <a href="#Top" accesskey="u" rel="up">Top</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
</div>
<a name="Acknowledgments-1"></a>
<h2 class="chapter">10 Acknowledgments</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 <acronym>FAQ</acronym>.
</p>
<p>More to come soon &hellip;
</p>
<hr>
</body>
</html>