0byt3m1n1
Path:
C:
/
Program Files
/
R
/
R-4.4.1
/
doc
/
manual
/
[
Home
]
File: R-ints.html
<!DOCTYPE html> <html> <!-- Created by GNU Texinfo 7.1, https://www.gnu.org/software/texinfo/ --> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <!-- This manual is for R, version 4.4.1 (2024-06-14). Copyright © 1999-2024 R Core Team Permission is granted to make and distribute verbatim copies of this manual provided the copyright notice and this permission notice are preserved on all copies. Permission is granted to copy and distribute modified versions of this manual under the conditions for verbatim copying, provided that the entire resulting derived work is distributed under the terms of a permission notice identical to this one. Permission is granted to copy and distribute translations of this manual into another language, under the above conditions for modified versions, except that this permission notice may be stated in a translation approved by the R Core Team. --> <title>R Internals</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="description" content="R Internals"> <meta name="keywords" content="R Internals"> <meta name="resource-type" content="document"> <meta name="distribution" content="global"> <meta name="Generator" content="texi2any"> <meta name="viewport" content="width=device-width,initial-scale=1"> <link href="#Top" rel="start" title="Top"> <link href="#Function-and-variable-index" rel="index" title="Function and variable index"> <link href="#SEC_Contents" rel="contents" title="Table of Contents"> <link href="#R-Internal-Structures" rel="next" title="R Internal Structures"> <style type="text/css"> <!-- a.copiable-link {visibility: hidden; text-decoration: none; line-height: 0em} a.summary-letter-printindex {text-decoration: none} div.example {margin-left: 3.2em} kbd.kbd {font-style: oblique} span.r {font-family: initial; font-weight: normal; font-style: normal} span:hover a.copiable-link {visibility: visible} td.printindex-index-entry {vertical-align: top} td.printindex-index-section {vertical-align: top; padding-left: 1em} th.entries-header-printindex {text-align:left} th.sections-header-printindex {text-align:left; padding-left: 1em} ul.mark-bullet {list-style-type: disc} ul.toc-numbered-mark {list-style: none} body { margin-left: 5%; margin-right: 5%; } h1 { background: white; color: rgb(25%, 25%, 25%); font-family: monospace; font-size: xx-large; text-align: center; } h2 { background: white; color: rgb(40%, 40%, 40%); font-family: monospace; font-size: x-large; text-align: center; } h3 { background: white; color: rgb(40%, 40%, 40%); font-family: monospace; font-size: large; } h4 { background: white; color: rgb(40%, 40%, 40%); font-family: monospace; } span.samp { font-family: monospace; } span.command { font-family: monospace; } span.option { font-family: monospace; } span.file { font-family: monospace; } span.env { font-family: monospace; } ul { margin-top: 0.25ex; margin-bottom: 0.25ex; } li { margin-top: 0.25ex; margin-bottom: 0.25ex; } p { margin-top: 0.6ex; margin-bottom: 1.2ex; } /* hide top navigation bar in Texinfo >= 6.8 output */ #Top > .header, #Top > .nav-panel { display: none } --> </style> </head> <body lang="en"> <div class="top-level-extent" id="Top"> <div class="nav-panel"> <p> Next: <a href="#R-Internal-Structures" accesskey="n" rel="next">R Internal Structures</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-variable-index" title="Index" rel="index">Index</a>]</p> </div> <h1 class="top" id="R-Internals"><span>R Internals<a class="copiable-link" href="#R-Internals"> ¶</a></span></h1> <p>This is a guide to the internal structures of R and coding standards for the core team working on R itself. </p> <p>This manual is for R, version 4.4.1 (2024-06-14). </p> <p>Copyright © 1999–2024 R Core Team </p> <blockquote class="quotation"> <p>Permission is granted to make and distribute verbatim copies of this manual provided the copyright notice and this permission notice are preserved on all copies. </p> <p>Permission is granted to copy and distribute modified versions of this manual under the conditions for verbatim copying, provided that the entire resulting derived work is distributed under the terms of a permission notice identical to this one. </p> <p>Permission is granted to copy and distribute translations of this manual into another language, under the above conditions for modified versions, except that this permission notice may be stated in a translation approved by the R Core Team. </p></blockquote> <div class="element-contents" id="SEC_Contents"> <h2 class="contents-heading">Table of Contents</h2> <div class="contents"> <ul class="toc-numbered-mark"> <li><a id="toc-R-Internal-Structures-1" href="#R-Internal-Structures">1 R Internal Structures</a> <ul class="toc-numbered-mark"> <li><a id="toc-SEXPs-1" href="#SEXPs">1.1 SEXPs</a> <ul class="toc-numbered-mark"> <li><a id="toc-SEXPTYPEs-1" href="#SEXPTYPEs">1.1.1 SEXPTYPEs</a></li> <li><a id="toc-Rest-of-header-1" href="#Rest-of-header">1.1.2 Rest of header</a></li> <li><a id="toc-The-_0060data_0027" href="#The-_0027data_0027">1.1.3 The ‘data’</a></li> <li><a id="toc-Allocation-classes-1" href="#Allocation-classes">1.1.4 Allocation classes</a></li> </ul></li> <li><a id="toc-Environments-and-variable-lookup-1" href="#Environments-and-variable-lookup">1.2 Environments and variable lookup</a> <ul class="toc-numbered-mark"> <li><a id="toc-Search-paths-1" href="#Search-paths">1.2.1 Search paths</a></li> <li><a id="toc-Namespaces-1" href="#Namespaces">1.2.2 Namespaces</a></li> <li><a id="toc-Hash-table-1" href="#Hash-table">1.2.3 Hash table</a></li> </ul></li> <li><a id="toc-Attributes-1" href="#Attributes">1.3 Attributes</a></li> <li><a id="toc-Contexts-1" href="#Contexts">1.4 Contexts</a></li> <li><a id="toc-Argument-evaluation-1" href="#Argument-evaluation">1.5 Argument evaluation</a> <ul class="toc-numbered-mark"> <li><a id="toc-Missingness-1" href="#Missingness">1.5.1 Missingness</a></li> <li><a id="toc-Dot_002ddot_002ddot-arguments-1" href="#Dot_002ddot_002ddot-arguments">1.5.2 Dot-dot-dot arguments</a></li> </ul></li> <li><a id="toc-Autoprinting-1" href="#Autoprinting">1.6 Autoprinting</a></li> <li><a id="toc-The-write-barrier-and-the-garbage-collector" href="#The-write-barrier">1.7 The write barrier and the garbage collector</a></li> <li><a id="toc-Serialization-Formats-1" href="#Serialization-Formats">1.8 Serialization Formats</a></li> <li><a id="toc-Encodings-for-CHARSXPs-1" href="#Encodings-for-CHARSXPs">1.9 Encodings for <code class="code">CHARSXP</code>s</a></li> <li><a id="toc-The-CHARSXP-cache-1" href="#The-CHARSXP-cache">1.10 The <code class="code">CHARSXP</code> cache</a></li> <li><a id="toc-Warnings-and-errors-1" href="#Warnings-and-errors">1.11 Warnings and errors</a></li> <li><a id="toc-S4-objects-1" href="#S4-objects">1.12 S4 objects</a> <ul class="toc-numbered-mark"> <li><a id="toc-Representation-of-S4-objects-1" href="#Representation-of-S4-objects">1.12.1 Representation of S4 objects</a></li> <li><a id="toc-S4-classes-1" href="#S4-classes">1.12.2 S4 classes</a></li> <li><a id="toc-S4-methods-1" href="#S4-methods">1.12.3 S4 methods</a></li> <li><a id="toc-Mechanics-of-S4-dispatch-1" href="#Mechanics-of-S4-dispatch">1.12.4 Mechanics of S4 dispatch</a></li> </ul></li> <li><a id="toc-Memory-allocators-1" href="#Memory-allocators">1.13 Memory allocators</a> <ul class="toc-numbered-mark"> <li><a id="toc-Internals-of-R_005falloc-1" href="#Internals-of-R_005falloc">1.13.1 Internals of <code class="code">R_alloc</code></a></li> </ul></li> <li><a id="toc-Internal-use-of-global-and-base-environments-1" href="#Internal-use-of-global-and-base-environments">1.14 Internal use of global and base environments</a> <ul class="toc-numbered-mark"> <li><a id="toc-Base-environment-1" href="#Base-environment">1.14.1 Base environment</a></li> <li><a id="toc-Global-environment-1" href="#Global-environment">1.14.2 Global environment</a></li> </ul></li> <li><a id="toc-Modules-1" href="#Modules">1.15 Modules</a></li> <li><a id="toc-Visibility-1" href="#Visibility">1.16 Visibility</a> <ul class="toc-numbered-mark"> <li><a id="toc-Hiding-C-entry-points-1" href="#Hiding-C-entry-points">1.16.1 Hiding C entry points</a></li> <li><a id="toc-Variables-in-Windows-DLLs-1" href="#Variables-in-Windows-DLLs">1.16.2 Variables in Windows DLLs</a></li> </ul></li> <li><a id="toc-Lazy-loading-1" href="#Lazy-loading">1.17 Lazy loading</a></li> </ul></li> <li><a id="toc-_002eInternal-vs-_002ePrimitive-1" href="#g_t_002eInternal-vs-_002ePrimitive">2 <code class="code">.Internal</code> vs <code class="code">.Primitive</code></a> <ul class="toc-numbered-mark"> <li><a id="toc-Special-primitives-1" href="#Special-primitives">2.1 Special primitives</a></li> <li><a id="toc-Special-internals-1" href="#Special-internals">2.2 Special internals</a></li> <li><a id="toc-Prototypes-for-primitives-1" href="#Prototypes-for-primitives">2.3 Prototypes for primitives</a></li> <li><a id="toc-Adding-a-primitive-1" href="#Adding-a-primitive">2.4 Adding a primitive</a></li> </ul></li> <li><a id="toc-Internationalization-in-the-R-sources-1" href="#Internationalization-in-the-R-sources">3 Internationalization in the R sources</a> <ul class="toc-numbered-mark"> <li><a id="toc-R-code-1" href="#R-code">3.1 R code</a></li> <li><a id="toc-Main-C-code-1" href="#Main-C-code">3.2 Main C code</a></li> <li><a id="toc-Windows_002dGUI_002dspecific-code-1" href="#Windows_002dGUI_002dspecific-code">3.3 Windows-GUI-specific code</a></li> <li><a id="toc-macOS-GUI-1" href="#macOS-GUI">3.4 macOS GUI</a></li> <li><a id="toc-Updating-1" href="#Updating">3.5 Updating</a></li> </ul></li> <li><a id="toc-Structure-of-an-Installed-Package" href="#Package-Structure">4 Structure of an Installed Package</a> <ul class="toc-numbered-mark"> <li><a id="toc-Metadata-1" href="#Metadata">4.1 Metadata</a></li> <li><a id="toc-Help-1" href="#Help">4.2 Help</a></li> </ul></li> <li><a id="toc-Files-1" href="#Files">5 Files</a></li> <li><a id="toc-Graphics" href="#Graphics-Devices">6 Graphics</a> <ul class="toc-numbered-mark"> <li><a id="toc-Graphics-Devices-1" href="#Graphics-devices">6.1 Graphics Devices</a> <ul class="toc-numbered-mark"> <li><a id="toc-Device-structures-1" href="#Device-structures">6.1.1 Device structures</a></li> <li><a id="toc-Device-capabilities-1" href="#Device-capabilities">6.1.2 Device capabilities</a></li> <li><a id="toc-Handling-text-1" href="#Handling-text">6.1.3 Handling text</a></li> <li><a id="toc-Conventions-1" href="#Conventions">6.1.4 Conventions</a></li> <li><a id="toc-_0060Mode_0027" href="#g_t_0027Mode_0027">6.1.5 ‘Mode’</a></li> <li><a id="toc-Graphics-events-1" href="#Graphics-events">6.1.6 Graphics events</a></li> <li><a id="toc-Specific-devices-1" href="#Specific-devices">6.1.7 Specific devices</a> <ul class="toc-numbered-mark"> <li><a id="toc-X11_0028_0029-1" href="#X11_0028_0029">6.1.7.1 X11()</a></li> <li><a id="toc-windows_0028_0029-1" href="#windows_0028_0029">6.1.7.2 windows()</a></li> </ul></li> </ul></li> <li><a id="toc-Colours-1" href="#Colours">6.2 Colours</a></li> <li><a id="toc-Base-graphics-1" href="#Base-graphics">6.3 Base graphics</a> <ul class="toc-numbered-mark"> <li><a id="toc-Arguments-and-parameters-1" href="#Arguments-and-parameters">6.3.1 Arguments and parameters</a></li> </ul></li> <li><a id="toc-Grid-graphics-1" href="#Grid-graphics">6.4 Grid graphics</a></li> </ul></li> <li><a id="toc-GUI-consoles-1" href="#GUI-consoles">7 GUI consoles</a> <ul class="toc-numbered-mark"> <li><a id="toc-R_002eapp-1" href="#R_002eapp">7.1 R.app</a></li> </ul></li> <li><a id="toc-Tools-1" href="#Tools">8 Tools</a></li> <li><a id="toc-R-coding-standards-1" href="#R-coding-standards">9 R coding standards</a></li> <li><a id="toc-Testing-R-code-1" href="#Testing-R-code">10 Testing R code</a></li> <li><a id="toc-Use-of-TeX-dialects-1" href="#Use-of-TeX-dialects">11 Use of TeX dialects</a></li> <li><a id="toc-Current-and-future-directions-1" href="#Current-and-future-directions">12 Current and future directions</a> <ul class="toc-numbered-mark"> <li><a id="toc-Long-vectors-1" href="#Long-vectors">12.1 Long vectors</a></li> <li><a id="toc-64_002dbit-types-1" href="#g_t64_002dbit-types">12.2 64-bit types</a></li> <li><a id="toc-Large-matrices-1" href="#Large-matrices">12.3 Large matrices</a></li> </ul></li> <li><a id="toc-Function-and-variable-index-1" href="#Function-and-variable-index" rel="index">Function and variable index</a></li> <li><a id="toc-Concept-index-1" href="#Concept-index" rel="index">Concept index</a></li> </ul> </div> </div> <hr> <div class="chapter-level-extent" id="R-Internal-Structures"> <div class="nav-panel"> <p> Next: <a href="#g_t_002eInternal-vs-_002ePrimitive" accesskey="n" rel="next"><code class="code">.Internal</code> vs <code class="code">.Primitive</code></a>, Previous: <a href="#Top" accesskey="p" rel="prev">R Internals</a>, Up: <a href="#Top" accesskey="u" rel="up">R Internals</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-variable-index" title="Index" rel="index">Index</a>]</p> </div> <h2 class="chapter" id="R-Internal-Structures-1"><span>1 R Internal Structures<a class="copiable-link" href="#R-Internal-Structures-1"> ¶</a></span></h2> <p>This chapter is the beginnings of documentation about R internal structures. It is written for the core team and others studying the code in the <samp class="file">src/main</samp> directory. </p> <p>It is a work-in-progress and should be checked against the current version of the source code. Versions for R 2.x.y contain historical comments about when features were introduced: this version is for the 3.x.y series. </p> <ul class="mini-toc"> <li><a href="#SEXPs" accesskey="1">SEXPs</a></li> <li><a href="#Environments-and-variable-lookup" accesskey="2">Environments and variable lookup</a></li> <li><a href="#Attributes" accesskey="3">Attributes</a></li> <li><a href="#Contexts" accesskey="4">Contexts</a></li> <li><a href="#Argument-evaluation" accesskey="5">Argument evaluation</a></li> <li><a href="#Autoprinting" accesskey="6">Autoprinting</a></li> <li><a href="#The-write-barrier" accesskey="7">The write barrier and the garbage collector</a></li> <li><a href="#Serialization-Formats" accesskey="8">Serialization Formats</a></li> <li><a href="#Encodings-for-CHARSXPs" accesskey="9">Encodings for <code class="code">CHARSXP</code>s</a></li> <li><a href="#The-CHARSXP-cache">The <code class="code">CHARSXP</code> cache</a></li> <li><a href="#Warnings-and-errors">Warnings and errors</a></li> <li><a href="#S4-objects">S4 objects</a></li> <li><a href="#Memory-allocators">Memory allocators</a></li> <li><a href="#Internal-use-of-global-and-base-environments">Internal use of global and base environments</a></li> <li><a href="#Modules">Modules</a></li> <li><a href="#Visibility">Visibility</a></li> <li><a href="#Lazy-loading">Lazy loading</a></li> </ul> <hr> <div class="section-level-extent" id="SEXPs"> <div class="nav-panel"> <p> Next: <a href="#Environments-and-variable-lookup" accesskey="n" rel="next">Environments and variable lookup</a>, Previous: <a href="#R-Internal-Structures" accesskey="p" rel="prev">R Internal Structures</a>, Up: <a href="#R-Internal-Structures" accesskey="u" rel="up">R Internal Structures</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-variable-index" title="Index" rel="index">Index</a>]</p> </div> <h3 class="section" id="SEXPs-1"><span>1.1 SEXPs<a class="copiable-link" href="#SEXPs-1"> ¶</a></span></h3> <a class="index-entry-id" id="index-SEXP"></a> <a class="index-entry-id" id="index-SEXPREC"></a> <p>What R users think of as <em class="emph">variables</em> or <em class="emph">objects</em> are symbols which are bound to a value. The value can be thought of as either a <code class="code">SEXP</code> (a pointer), or the structure it points to, a <code class="code">SEXPREC</code> (and there are alternative forms used for vectors, namely <code class="code">VECSXP</code> pointing to <code class="code">VECTOR_SEXPREC</code> structures). So the basic building blocks of R objects are often called <em class="emph">nodes</em>, meaning <code class="code">SEXPREC</code>s or <code class="code">VECTOR_SEXPREC</code>s. </p> <p>Note that the internal structure of the <code class="code">SEXPREC</code> is not made available to R Extensions: rather <code class="code">SEXP</code> is an opaque pointer, and the internals can only be accessed by the functions provided. </p> <a class="index-entry-id" id="index-node"></a> <p>Both types of node structure have as their first three fields a 64-bit <code class="code">sxpinfo</code> header and then three pointers (to the attributes and the previous and next node in a doubly-linked list), and then some further fields. On a 32-bit platform a node<a class="footnote" id="DOCF1" href="#FOOT1"><sup>1</sup></a> occupies 32 bytes: on a 64-bit platform typically 56 bytes (depending on alignment constraints). </p> <p>The first five bits of the <code class="code">sxpinfo</code> header specify one of up to 32 <code class="code">SEXPTYPE</code>s. </p> <ul class="mini-toc"> <li><a href="#SEXPTYPEs" accesskey="1">SEXPTYPEs</a></li> <li><a href="#Rest-of-header" accesskey="2">Rest of header</a></li> <li><a href="#The-_0027data_0027" accesskey="3">The ‘data’</a></li> <li><a href="#Allocation-classes" accesskey="4">Allocation classes</a></li> </ul> <hr> <div class="subsection-level-extent" id="SEXPTYPEs"> <div class="nav-panel"> <p> Next: <a href="#Rest-of-header" accesskey="n" rel="next">Rest of header</a>, Previous: <a href="#SEXPs" accesskey="p" rel="prev">SEXPs</a>, Up: <a href="#SEXPs" accesskey="u" rel="up">SEXPs</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-variable-index" title="Index" rel="index">Index</a>]</p> </div> <h4 class="subsection" id="SEXPTYPEs-1"><span>1.1.1 SEXPTYPEs<a class="copiable-link" href="#SEXPTYPEs-1"> ¶</a></span></h4> <a class="index-entry-id" id="index-SEXPTYPE"></a> <p>Currently <code class="code">SEXPTYPE</code>s 0:10 and 13:25 are in use. Values 11 and 12 were used for internal factors and ordered factors and have since been withdrawn. Note that the <code class="code">SEXPTYPE</code> numbers are stored in <code class="code">save</code>d objects and that the ordering of the types is used, so the gap cannot easily be reused. </p> <a class="index-entry-id" id="index-SEXPTYPE-table"></a> <blockquote class="quotation"> <table summary="" class="multitable"> <thead><tr><th>no</th><th>SEXPTYPE</th><th>Description</th></tr></thead> <tbody><tr><td><code class="code">0</code></td><td><code class="code">NILSXP</code></td><td><code class="code">NULL</code></td></tr> <tr><td><code class="code">1</code></td><td><code class="code">SYMSXP</code></td><td>symbols</td></tr> <tr><td><code class="code">2</code></td><td><code class="code">LISTSXP</code></td><td>pairlists</td></tr> <tr><td><code class="code">3</code></td><td><code class="code">CLOSXP</code></td><td>closures</td></tr> <tr><td><code class="code">4</code></td><td><code class="code">ENVSXP</code></td><td>environments</td></tr> <tr><td><code class="code">5</code></td><td><code class="code">PROMSXP</code></td><td>promises</td></tr> <tr><td><code class="code">6</code></td><td><code class="code">LANGSXP</code></td><td>language objects</td></tr> <tr><td><code class="code">7</code></td><td><code class="code">SPECIALSXP</code></td><td>special functions</td></tr> <tr><td><code class="code">8</code></td><td><code class="code">BUILTINSXP</code></td><td>builtin functions</td></tr> <tr><td><code class="code">9</code></td><td><code class="code">CHARSXP</code></td><td>internal character strings</td></tr> <tr><td><code class="code">10</code></td><td><code class="code">LGLSXP</code></td><td>logical vectors</td></tr> <tr><td><code class="code">13</code></td><td><code class="code">INTSXP</code></td><td>integer vectors</td></tr> <tr><td><code class="code">14</code></td><td><code class="code">REALSXP</code></td><td>numeric vectors</td></tr> <tr><td><code class="code">15</code></td><td><code class="code">CPLXSXP</code></td><td>complex vectors</td></tr> <tr><td><code class="code">16</code></td><td><code class="code">STRSXP</code></td><td>character vectors</td></tr> <tr><td><code class="code">17</code></td><td><code class="code">DOTSXP</code></td><td>dot-dot-dot object</td></tr> <tr><td><code class="code">18</code></td><td><code class="code">ANYSXP</code></td><td>make “any” args work</td></tr> <tr><td><code class="code">19</code></td><td><code class="code">VECSXP</code></td><td>list (generic vector)</td></tr> <tr><td><code class="code">20</code></td><td><code class="code">EXPRSXP</code></td><td>expression vector</td></tr> <tr><td><code class="code">21</code></td><td><code class="code">BCODESXP</code></td><td>byte code</td></tr> <tr><td><code class="code">22</code></td><td><code class="code">EXTPTRSXP</code></td><td>external pointer</td></tr> <tr><td><code class="code">23</code></td><td><code class="code">WEAKREFSXP</code></td><td>weak reference</td></tr> <tr><td><code class="code">24</code></td><td><code class="code">RAWSXP</code></td><td>raw vector</td></tr> <tr><td><code class="code">25</code></td><td><code class="code">OBJSXP</code></td><td>objects not of simple type</td></tr> </tbody> </table> </blockquote> <a class="index-entry-id" id="index-atomic-vector-type"></a> <p>Many of these will be familiar from R level: the atomic vector types are <code class="code">LGLSXP</code>, <code class="code">INTSXP</code>, <code class="code">REALSXP</code>, <code class="code">CPLXSP</code>, <code class="code">STRSXP</code> and <code class="code">RAWSXP</code>. Lists are <code class="code">VECSXP</code> and names (also known as symbols) are <code class="code">SYMSXP</code>. Pairlists (<code class="code">LISTSXP</code>, the name going back to the origins of R as a Scheme-like language) are rarely seen at R level, but are for example used for argument lists. Character vectors are effectively lists all of whose elements are <code class="code">CHARSXP</code>, a type that is rarely visible at R level. </p> <a class="index-entry-id" id="index-language-object"></a> <a class="index-entry-id" id="index-argument-list"></a> <p>Language objects (<code class="code">LANGSXP</code>) are calls (including formulae and so on). Internally they are pairlists with first element a reference<a class="footnote" id="DOCF2" href="#FOOT2"><sup>2</sup></a> to the function to be called with remaining elements the actual arguments for the call (and with the tags if present giving the specified argument names). Although this is not enforced, many places in the code assume that the pairlist is of length one or more, often without checking. </p> <a class="index-entry-id" id="index-expression"></a> <p>Expressions are of type <code class="code">EXPRSXP</code>: they are a vector of (usually language) objects most often seen as the result of <code class="code">parse()</code>. </p> <a class="index-entry-id" id="index-function"></a> <p>The functions are of types <code class="code">CLOSXP</code>, <code class="code">SPECIALSXP</code> and <code class="code">BUILTINSXP</code>: where <code class="code">SEXPTYPE</code>s are stored in an integer these are sometimes lumped into a pseudo-type <code class="code">FUNSXP</code> with code 99. Functions defined via <code class="code">function</code> are of type <code class="code">CLOSXP</code> and have formals, body and environment. </p> <a class="index-entry-id" id="index-S4-type"></a> <p>The <code class="code">SEXPTYPE</code> <code class="code">OBJSXP</code> is for S4 and other objects which do not consist solely of a simple type such as an atomic vector or function. </p> <hr> </div> <div class="subsection-level-extent" id="Rest-of-header"> <div class="nav-panel"> <p> Next: <a href="#The-_0027data_0027" accesskey="n" rel="next">The ‘data’</a>, Previous: <a href="#SEXPTYPEs" accesskey="p" rel="prev">SEXPTYPEs</a>, Up: <a href="#SEXPs" accesskey="u" rel="up">SEXPs</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-variable-index" title="Index" rel="index">Index</a>]</p> </div> <h4 class="subsection" id="Rest-of-header-1"><span>1.1.2 Rest of header<a class="copiable-link" href="#Rest-of-header-1"> ¶</a></span></h4> <p>Note that the size and structure of the header changed in R 3.5.0: see earlier editions of this manual for the previous layout. </p> <p>The <code class="code">sxpinfo</code> header is defined as a 64-bit C structure by </p> <div class="example"> <pre class="example-preformatted">#define NAMED_BITS 16 struct sxpinfo_struct { SEXPTYPE type : 5; /* <span class="r">discussed above</span> */ unsigned int scalar: 1; /* <span class="r">is this a numeric vector of length 1?</span> unsigned int obj : 1; /* <span class="r">is this an object with a class attribute?</span> */ unsigned int alt : 1; /* <span class="r">is this an <code class="code">ALTREP</code> object?</span> */ unsigned int gp : 16; /* <span class="r">general purpose, see below</span> */ unsigned int mark : 1; /* <span class="r">mark object as ‘in use’ in GC</span> */ unsigned int debug : 1; unsigned int trace : 1; unsigned int spare : 1; /* <span class="r">debug once and with reference counting</span> */ unsigned int gcgen : 1; /* <span class="r">generation for GC</span> */ unsigned int gccls : 3; /* <span class="r">class of node for GC</span> */ unsigned int named : NAMED_BITS; /* <span class="r">used to control copying</span> */ unsigned int extra : 32 - NAMED_BITS; }; /* Tot: 64 */ </pre></div> <a class="index-entry-id" id="index-debug-bit"></a> <p>The <code class="code">debug</code> bit is used for closures and environments. For closures it is set by <code class="code">debug()</code> and unset by <code class="code">undebug()</code>, and indicates that evaluations of the function should be run under the browser. For environments it indicates whether the browsing is in single-step mode. </p> <a class="index-entry-id" id="index-trace-bit"></a> <p>The <code class="code">trace</code> bit is used for functions for <code class="code">trace()</code> and for other objects when tracing duplications (see <code class="code">tracemem</code>). </p> <a class="index-entry-id" id="index-spare-bit"></a> <p>The <code class="code">spare</code> bit is used for closures to mark them for one-time debugging. </p> <a class="index-entry-id" id="index-named-bits"></a> <a class="index-entry-id" id="index-NAMED"></a> <a class="index-entry-id" id="index-SET_005fNAMED"></a> <a class="index-entry-id" id="index-copying-semantics"></a> <p>The <code class="code">named</code> field is set and accessed by the <code class="code">SET_NAMED</code> and <code class="code">NAMED</code> macros, and take values <code class="code">0</code>, <code class="code">1</code> and <code class="code">2</code>, or possibly higher if <code class="code">NAMEDMAX</code> is set to a higher value. R has a ‘call by value’ illusion, so an assignment like </p><div class="example"> <pre class="example-preformatted">b <- a </pre></div> <p>[The <code class="code">NAMED</code> mechanism has been replaced by reference counting.] </p> <p>appears to make a copy of <code class="code">a</code> and refer to it as <code class="code">b</code>. However, if neither <code class="code">a</code> nor <code class="code">b</code> are subsequently altered there is no need to copy. What really happens is that a new symbol <code class="code">b</code> is bound to the same value as <code class="code">a</code> and the <code class="code">named</code> field on the value object is set (in this case to <code class="code">2</code>). When an object is about to be altered, the <code class="code">named</code> field is consulted. A value of <code class="code">2</code> or more means that the object must be duplicated before being changed. (Note that this does not say that it is necessary to duplicate, only that it should be duplicated whether necessary or not.) A value of <code class="code">0</code> means that it is known that no other <code class="code">SEXP</code> shares data with this object, and so it may safely be altered. A value of <code class="code">1</code> is used for situations like </p> <div class="example"> <pre class="example-preformatted">dim(a) <- c(7, 2) </pre></div> <p>where in principle two copies of <code class="code">a</code> exist for the duration of the computation as (in principle) </p> <div class="example"> <pre class="example-preformatted">a <- `dim<-`(a, c(7, 2)) </pre></div> <p>but for no longer, and so some primitive functions can be optimized to avoid a copy in this case. [This mechanism is scheduled to be replaced in R 4.0.0.] </p> <p>The <code class="code">gp</code> bits are by definition ‘general purpose’. We label these from 0 to 15. Bits 0–5 and bits 14–15 have been used as described below (mainly from detective work on the sources). </p> <a class="index-entry-id" id="index-gp-bits"></a> <a class="index-entry-id" id="index-LEVELS"></a> <a class="index-entry-id" id="index-SETLEVELS"></a> <p>The bits can be accessed and set by the <code class="code">LEVELS</code> and <code class="code">SETLEVELS</code> macros, which names appear to date back to the internal factor and ordered types and are now used in only a few places in the code. The <code class="code">gp</code> field is serialized/unserialized for the <code class="code">SEXPTYPE</code>s other than <code class="code">NILSXP</code>, <code class="code">SYMSXP</code> and <code class="code">ENVSXP</code>. </p> <p>Bits 14 and 15 of <code class="code">gp</code> are used for ‘fancy bindings’. Bit 14 is used to lock a binding or an environment, and bit 15 is used to indicate an active binding. (For the definition of an ‘active binding’ see the header comments in file <samp class="file">src/main/envir.c</samp>.) Bit 15 is used for an environment to indicate if it participates in the global cache. </p> <a class="index-entry-id" id="index-ARGSUSED"></a> <a class="index-entry-id" id="index-SET_005fARGUSED"></a> <p>The macros <code class="code">ARGUSED</code> and <code class="code">SET_ARGUSED</code> are used when matching actual and formal function arguments, and take the values 0, 1 and 2. </p> <a class="index-entry-id" id="index-MISSING"></a> <a class="index-entry-id" id="index-SET_005fMISSING"></a> <p>The macros <code class="code">MISSING</code> and <code class="code">SET_MISSING</code> are used for pairlists of arguments. Four bits are reserved, but only two are used (and exactly what for is not explained). It seems that bit 0 is used by <code class="code">matchArgs_NR</code> to mark missingness on the returned argument list, and bit 1 is used to mark the use of a default value for an argument copied to the evaluation frame of a closure. </p> <a class="index-entry-id" id="index-DDVAL"></a> <a class="index-entry-id" id="index-SET_005fDDVAL"></a> <a class="index-entry-id" id="index-_002e_002e_002e-argument"></a> <p>Bit 0 is used by macros <code class="code">DDVAL</code> and <code class="code">SET_DDVAL</code>. This indicates that a <code class="code">SYMSXP</code> is one of the symbols <code class="code">..n</code> which are implicitly created when <code class="code">...</code> is processed, and so indicates that it may need to be looked up in a <code class="code">DOTSXP</code>. </p> <a class="index-entry-id" id="index-PRSEEN"></a> <a class="index-entry-id" id="index-promise"></a> <p>Bit 0 is used for <code class="code">PRSEEN</code>, a flag to indicate if a promise has already been seen during the evaluation of the promise (and so to avoid recursive loops). </p> <p>Bit 0 is used for <code class="code">HASHASH</code>, on the <code class="code">PRINTNAME</code> of the <code class="code">TAG</code> of the frame of an environment. (This bit is not serialized for <code class="code">CHARSXP</code> objects.) </p> <p>Bits 0 and 1 are used for weak references (to indicate ‘ready to finalize’, ‘finalize on exit’). </p> <p>Bit 0 is used by the condition handling system (on a <code class="code">VECSXP</code>) to indicate a calling handler. </p> <p>Bit 4 is turned on to mark S4 objects. </p> <p>Bits 1, 2, 3, 5 and 6 are used for a <code class="code">CHARSXP</code> to denote its encoding. Bit 1 indicates that the <code class="code">CHARSXP</code> should be treated as a set of bytes, not necessarily representing a character in any known encoding. Bits 2, 3 and 6 are used to indicate that it is known to be in Latin-1, UTF-8 or <abbr class="acronym">ASCII</abbr> respectively. </p> <p>Bit 5 for a <code class="code">CHARSXP</code> indicates that it is hashed by its address, that is <code class="code">NA_STRING</code> or is in the <code class="code">CHARSXP</code> cache (this is not serialized). Only exceptionally is a <code class="code">CHARSXP</code> not hashed, and this should never happen in end-user code. </p> <hr> </div> <div class="subsection-level-extent" id="The-_0027data_0027"> <div class="nav-panel"> <p> Next: <a href="#Allocation-classes" accesskey="n" rel="next">Allocation classes</a>, Previous: <a href="#Rest-of-header" accesskey="p" rel="prev">Rest of header</a>, Up: <a href="#SEXPs" accesskey="u" rel="up">SEXPs</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-variable-index" title="Index" rel="index">Index</a>]</p> </div> <h4 class="subsection" id="The-_0060data_0027"><span>1.1.3 The ‘data’<a class="copiable-link" href="#The-_0060data_0027"> ¶</a></span></h4> <p>A <code class="code">SEXPREC</code> is a C structure containing the 64-bit header as described above, three pointers (to the attributes, previous and next node) and the node data, a union </p> <div class="example"> <pre class="example-preformatted">union { struct primsxp_struct primsxp; struct symsxp_struct symsxp; struct listsxp_struct listsxp; struct envsxp_struct envsxp; struct closxp_struct closxp; struct promsxp_struct promsxp; } u; </pre></div> <p>All of these alternatives apart from the first (an <code class="code">int</code>) are three pointers, so the union occupies three words. </p> <a class="index-entry-id" id="index-vector-type"></a> <p>The vector types are <code class="code">RAWSXP</code>, <code class="code">CHARSXP</code>, <code class="code">LGLSXP</code>, <code class="code">INTSXP</code>, <code class="code">REALSXP</code>, <code class="code">CPLXSXP</code>, <code class="code">STRSXP</code>, <code class="code">VECSXP</code>, <code class="code">EXPRSXP</code> and <code class="code">WEAKREFSXP</code>. Remember that such types are a <code class="code">VECTOR_SEXPREC</code>, which again consists of the header and the same three pointers, but followed by two integers giving the length and ‘true length’<a class="footnote" id="DOCF3" href="#FOOT3"><sup>3</sup></a> of the vector, and then followed by the data (aligned as required: on most 32-bit systems with a 28-byte <code class="code">VECTOR_SEXPREC</code> node the data can follow immediately after the node). The data are a block of memory of the appropriate length to store ‘true length’ elements (rounded up to a multiple of 8 bytes, with the 8-byte blocks being the ‘Vcells’ referred in the documentation for <code class="code">gc()</code>). </p> <p>The ‘data’ for the various types are given in the table below. A lot of this is interpretation, i.e. the types are not checked. </p> <dl class="table"> <dt><code class="code">NILSXP</code></dt> <dd><p>There is only one object of type <code class="code">NILSXP</code>, <code class="code">R_NilValue</code>, with no data. </p> </dd> <dt><code class="code">SYMSXP</code></dt> <dd><p>Pointers to three nodes, the name, value and internal, accessed by <code class="code">PRINTNAME</code> (a <code class="code">CHARSXP</code>), <code class="code">SYMVALUE</code> and <code class="code">INTERNAL</code>. (If the symbol’s value is a <code class="code">.Internal</code> function, the last is a pointer to the appropriate <code class="code">SEXPREC</code>.) Many symbols have <code class="code">SYMVALUE</code> <code class="code">R_UnboundValue</code>. </p> </dd> <dt><code class="code">LISTSXP</code></dt> <dd><p>Pointers to the CAR, CDR (usually a <code class="code">LISTSXP</code> or <code class="code">NULL</code>) and TAG (a <code class="code">SYMSXP</code> or <code class="code">NULL</code>). </p> </dd> <dt><code class="code">CLOSXP</code></dt> <dd><p>Pointers to the formals (a pairlist), the body and the environment. </p> </dd> <dt><code class="code">ENVSXP</code></dt> <dd><p>Pointers to the frame, enclosing environment and hash table (<code class="code">NULL</code> or a <code class="code">VECSXP</code>). A frame is a tagged pairlist with tag the symbol and CAR the bound value. </p> </dd> <dt><code class="code">PROMSXP</code></dt> <dd><p>Pointers to the value, expression and environment (in which to evaluate the expression). Once an promise has been evaluated, the environment is set to <code class="code">NULL</code>. </p> </dd> <dt><code class="code">LANGSXP</code></dt> <dd><p>A special type of <code class="code">LISTSXP</code> used for function calls. (The CAR references the function (perhaps via a symbol or language object), and the CDR the argument list with tags for named arguments.) R-level documentation references to ‘expressions’ / ‘language objects’ are mainly <code class="code">LANGSXP</code>s, but can be symbols (<code class="code">SYMSXP</code>s) or expression vectors (<code class="code">EXPRSXP</code>s). </p> </dd> <dt><code class="code">SPECIALSXP</code></dt> <dt><code class="code">BUILTINSXP</code></dt> <dd><p>An integer giving the offset into the table of primitives/<code class="code">.Internal</code>s. </p> </dd> <dt><code class="code">CHARSXP</code></dt> <dd><p><code class="code">length</code>, <code class="code">truelength</code> followed by a block of bytes (allowing for the <code class="code">nul</code> terminator). </p> </dd> <dt><code class="code">LGLSXP</code></dt> <dt><code class="code">INTSXP</code></dt> <dd><p><code class="code">length</code>, <code class="code">truelength</code> followed by a block of C <code class="code">int</code>s (which are 32 bits on all R platforms). </p> </dd> <dt><code class="code">REALSXP</code></dt> <dd><p><code class="code">length</code>, <code class="code">truelength</code> followed by a block of C <code class="code">double</code>s. </p> </dd> <dt><code class="code">CPLXSXP</code></dt> <dd><p><code class="code">length</code>, <code class="code">truelength</code> followed by a block of C99 <code class="code">double complex</code>s. </p> </dd> <dt><code class="code">STRSXP</code></dt> <dd><p><code class="code">length</code>, <code class="code">truelength</code> followed by a block of pointers (<code class="code">SEXP</code>s pointing to <code class="code">CHARSXP</code>s). </p> </dd> <dt><code class="code">DOTSXP</code></dt> <dd><p>A special type of <code class="code">LISTSXP</code> for the value bound to a <code class="code">...</code> symbol: a pairlist of promises. </p> </dd> <dt><code class="code">ANYSXP</code></dt> <dd><p>This is used as a place holder for any type: there are no actual objects of this type. </p> </dd> <dt><code class="code">VECSXP</code></dt> <dt><code class="code">EXPRSXP</code></dt> <dd><p><code class="code">length</code>, <code class="code">truelength</code> followed by a block of pointers. These are internally identical (and identical to <code class="code">STRSXP</code>) but differ in the interpretations placed on the elements. </p> </dd> <dt><code class="code">BCODESXP</code></dt> <dd><p>For the ‘byte-code’ objects generated by the compiler. </p> </dd> <dt><code class="code">EXTPTRSXP</code></dt> <dd><p>Has three pointers, to the pointer, the protection value (an R object which if alive protects this object) and a tag (a <code class="code">SYMSXP</code>?). </p> </dd> <dt><code class="code">WEAKREFSXP</code></dt> <dd><p>A <code class="code">WEAKREFSXP</code> is a special <code class="code">VECSXP</code> of length 4, with elements ‘<samp class="samp">key</samp>’, ‘<samp class="samp">value</samp>’, ‘<samp class="samp">finalizer</samp>’ and ‘<samp class="samp">next</samp>’. The ‘<samp class="samp">key</samp>’ is <code class="code">NULL</code>, an environment or an external pointer, and the ‘<samp class="samp">finalizer</samp>’ is a function or <code class="code">NULL</code>. </p> </dd> <dt><code class="code">RAWSXP</code></dt> <dd><p><code class="code">length</code>, <code class="code">truelength</code> followed by a block of bytes. </p> </dd> <dt><code class="code">OBJSXP</code></dt> <dd><p>two unused pointers and a tag. </p></dd> </dl> <hr> </div> <div class="subsection-level-extent" id="Allocation-classes"> <div class="nav-panel"> <p> Previous: <a href="#The-_0027data_0027" accesskey="p" rel="prev">The ‘data’</a>, Up: <a href="#SEXPs" accesskey="u" rel="up">SEXPs</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-variable-index" title="Index" rel="index">Index</a>]</p> </div> <h4 class="subsection" id="Allocation-classes-1"><span>1.1.4 Allocation classes<a class="copiable-link" href="#Allocation-classes-1"> ¶</a></span></h4> <a class="index-entry-id" id="index-allocation-classes"></a> <p>As we have seen, the field <code class="code">gccls</code> in the header is three bits to label up to 8 classes of nodes. Non-vector nodes are of class 0, and ‘small’ vector nodes are of classes 1 to 5, with a class for custom allocator vector nodes 6 and ‘large’ vector nodes being of class 7. The ‘small’ vector nodes are able to store vector data of up to 8, 16, 32, 64 and 128 bytes: larger vectors are <code class="code">malloc</code>-ed individually whereas the ‘small’ nodes are allocated from pages of about 2000 bytes. Vector nodes allocated using custom allocators (via <code class="code">allocVector3</code>) are not counted in the <abbr class="abbr">GC</abbr> memory usage statistics since their memory semantics is not under R’s control and may be non-standard (e.g., memory could be partially shared across nodes). </p> <hr> </div> </div> <div class="section-level-extent" id="Environments-and-variable-lookup"> <div class="nav-panel"> <p> Next: <a href="#Attributes" accesskey="n" rel="next">Attributes</a>, Previous: <a href="#SEXPs" accesskey="p" rel="prev">SEXPs</a>, Up: <a href="#R-Internal-Structures" accesskey="u" rel="up">R Internal Structures</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-variable-index" title="Index" rel="index">Index</a>]</p> </div> <h3 class="section" id="Environments-and-variable-lookup-1"><span>1.2 Environments and variable lookup<a class="copiable-link" href="#Environments-and-variable-lookup-1"> ¶</a></span></h3> <a class="index-entry-id" id="index-environment"></a> <a class="index-entry-id" id="index-variable-lookup"></a> <p>What users think of as ‘variables’ are symbols which are bound to objects in ‘environments’. The word ‘environment’ is used ambiguously in R to mean <em class="emph">either</em> the frame of an <code class="code">ENVSXP</code> (a pairlist of symbol-value pairs) <em class="emph">or</em> an <code class="code">ENVSXP</code>, a frame plus an enclosure. </p> <a class="index-entry-id" id="index-user-databases"></a> <p>There are additional places that ‘variables’ can be looked up, called ‘user databases’ in comments in the code. These seem undocumented in the R sources, but apparently refer to the <strong class="strong">RObjectTable</strong> package formerly available at <a class="uref" href="https://www.omegahat.net/RObjectTables/">https://www.omegahat.net/RObjectTables/</a>. </p> <a class="index-entry-id" id="index-base-environment"></a> <a class="index-entry-id" id="index-environment_002c-base"></a> <p>The base environment is special. There is an <code class="code">ENVSXP</code> environment with enclosure the empty environment <code class="code">R_EmptyEnv</code>, but the frame of that environment is not used. Rather its bindings are part of the global symbol table, being those symbols in the global symbol table whose values are not <code class="code">R_UnboundValue</code>. When R is started the internal functions are installed (by C code) in the symbol table, with primitive functions having values and <code class="code">.Internal</code> functions having what would be their values in the field accessed by the <code class="code">INTERNAL</code> macro. Then <code class="code">.Platform</code> and <code class="code">.Machine</code> are computed and the base package is loaded into the base environment followed by the system profile. </p> <p>The frames of environments (and the symbol table) are normally hashed for faster access (including insertion and deletion). </p> <p>By default R maintains a (hashed) global cache of ‘variables’ (that is symbols and their bindings) which have been found, and this refers only to environments which have been marked to participate, which consists of the global environment (aka the user workspace), the base environment plus environments<a class="footnote" id="DOCF4" href="#FOOT4"><sup>4</sup></a> which have been <code class="code">attach</code>ed. When an environment is either <code class="code">attach</code>ed or <code class="code">detach</code>ed, the names of its symbols are flushed from the cache. The cache is used whenever searching for variables from the global environment (possibly as part of a recursive search). </p> <ul class="mini-toc"> <li><a href="#Search-paths" accesskey="1">Search paths</a></li> <li><a href="#Namespaces" accesskey="2">Namespaces</a></li> <li><a href="#Hash-table" accesskey="3">Hash table</a></li> </ul> <hr> <div class="subsection-level-extent" id="Search-paths"> <div class="nav-panel"> <p> Next: <a href="#Namespaces" accesskey="n" rel="next">Namespaces</a>, Previous: <a href="#Environments-and-variable-lookup" accesskey="p" rel="prev">Environments and variable lookup</a>, Up: <a href="#Environments-and-variable-lookup" accesskey="u" rel="up">Environments and variable lookup</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-variable-index" title="Index" rel="index">Index</a>]</p> </div> <h4 class="subsection" id="Search-paths-1"><span>1.2.1 Search paths<a class="copiable-link" href="#Search-paths-1"> ¶</a></span></h4> <a class="index-entry-id" id="index-search-path"></a> <p>S has the notion of a ‘search path’: the lookup for a ‘variable’ leads (possibly through a series of frames) to the ‘session frame’ the ‘working directory’ and then along the search path. The search path is a series of databases (as returned by <code class="code">search()</code>) which contain the system functions (but not necessarily at the end of the path, as by default the equivalent of packages are added at the end). </p> <p>R has a variant on the S model. There is a search path (also returned by <code class="code">search()</code>) which consists of the global environment (aka user workspace) followed by environments which have been attached and finally the base environment. Note that unlike S it is not possible to attach environments before the workspace nor after the base environment. </p> <p>However, the notion of variable lookup is more general in R, hence the plural in the title of this subsection. Since environments have enclosures, from any environment there is a search path found by looking in the frame, then the frame of its enclosure and so on. Since loops are not allowed, this process will eventually terminate: it can terminate at either the base environment or the empty environment. (It can be conceptually simpler to think of the search always terminating at the empty environment, but with an optimization to stop at the base environment.) So the ‘search path’ describes the chain of environments which is traversed once the search reaches the global environment. </p> <hr> </div> <div class="subsection-level-extent" id="Namespaces"> <div class="nav-panel"> <p> Next: <a href="#Hash-table" accesskey="n" rel="next">Hash table</a>, Previous: <a href="#Search-paths" accesskey="p" rel="prev">Search paths</a>, Up: <a href="#Environments-and-variable-lookup" accesskey="u" rel="up">Environments and variable lookup</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-variable-index" title="Index" rel="index">Index</a>]</p> </div> <h4 class="subsection" id="Namespaces-1"><span>1.2.2 Namespaces<a class="copiable-link" href="#Namespaces-1"> ¶</a></span></h4> <a class="index-entry-id" id="index-namespace"></a> <p>Namespaces are environments associated with packages (and once again the base package is special and will be considered separately). A package <code class="code"><var class="var">pkg</var></code> defines two environments <code class="code">namespace:<var class="var">pkg</var></code> and <code class="code">package:<var class="var">pkg</var></code>: it is <code class="code">package:<var class="var">pkg</var></code> that can be <code class="code">attach</code>ed and form part of the search path. </p> <p>The objects defined by the R code in the package are symbols with bindings in the <code class="code">namespace:<var class="var">pkg</var></code> environment. The <code class="code">package:<var class="var">pkg</var></code> environment is populated by selected symbols from the <code class="code">namespace:<var class="var">pkg</var></code> environment (the exports). The enclosure of this environment is an environment populated with the explicit imports from other namespaces, and the enclosure of <em class="emph">that</em> environment is the base namespace. (So the illusion of the imports being in the namespace environment is created via the environment tree.) The enclosure of the base namespace is the global environment, so the search from a package namespace goes via the (explicit and implicit) imports to the standard ‘search path’. </p> <a class="index-entry-id" id="index-base-namespace"></a> <a class="index-entry-id" id="index-namespace_002c-base"></a> <a class="index-entry-id" id="index-R_005fBaseNamespace"></a> <p>The base namespace environment <code class="code">R_BaseNamespace</code> is another <code class="code">ENVSXP</code> that is special-cased. It is effectively the same thing as the base environment <code class="code">R_BaseEnv</code> <em class="emph">except</em> that its enclosure is the global environment rather than the empty environment: the internal code diverts lookups in its frame to the global symbol table. </p> <hr> </div> <div class="subsection-level-extent" id="Hash-table"> <div class="nav-panel"> <p> Previous: <a href="#Namespaces" accesskey="p" rel="prev">Namespaces</a>, Up: <a href="#Environments-and-variable-lookup" accesskey="u" rel="up">Environments and variable lookup</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-variable-index" title="Index" rel="index">Index</a>]</p> </div> <h4 class="subsection" id="Hash-table-1"><span>1.2.3 Hash table<a class="copiable-link" href="#Hash-table-1"> ¶</a></span></h4> <p>Environments in R usually have a hash table, and nowadays that is the default in <code class="code">new.env()</code>. It is stored as a <code class="code">VECSXP</code> where <code class="code">length</code> is used for the allocated size of the table and <code class="code">truelength</code> is the number of primary slots in use—the pointer to the <code class="code">VECSXP</code> is part of the header of a <code class="code">SEXP</code> of type <code class="code">ENVSXP</code>, and this points to <code class="code">R_NilValue</code> if the environment is not hashed. </p> <p>For the pros and cons of hashing, see a basic text on Computer Science. </p> <p>The code to implement hashed environments is in <samp class="file">src/main/envir.c</samp>. Unless set otherwise (e.g. by the <code class="code">size</code> argument of <code class="code">new.env()</code>) the initial table size is <code class="code">29</code>. The table will be resized by a factor of 1.2 once the load factor (the proportion of primary slots in use) reaches 85%. </p> <p>The hash chains are stored as pairlist elements of the <code class="code">VECSXP</code>: items are inserted at the front of the pairlist. Hashing is principally designed for fast searching of environments, which are from time to time added to but rarely deleted from, so items are not actually deleted but have their value set to <code class="code">R_UnboundValue</code>. </p> <hr> </div> </div> <div class="section-level-extent" id="Attributes"> <div class="nav-panel"> <p> Next: <a href="#Contexts" accesskey="n" rel="next">Contexts</a>, Previous: <a href="#Environments-and-variable-lookup" accesskey="p" rel="prev">Environments and variable lookup</a>, Up: <a href="#R-Internal-Structures" accesskey="u" rel="up">R Internal Structures</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-variable-index" title="Index" rel="index">Index</a>]</p> </div> <h3 class="section" id="Attributes-1"><span>1.3 Attributes<a class="copiable-link" href="#Attributes-1"> ¶</a></span></h3> <a class="index-entry-id" id="index-attributes"></a> <a class="index-entry-id" id="index-ATTRIB"></a> <a class="index-entry-id" id="index-SET_005fATTRIB"></a> <a class="index-entry-id" id="index-DUPLICATE_005fATTRIB"></a> <p>As we have seen, every <code class="code">SEXPREC</code> has a pointer to the attributes of the node (default <code class="code">R_NilValue</code>). The attributes can be accessed/set by the macros/functions <code class="code">ATTRIB</code> and <code class="code">SET_ATTRIB</code>, but such direct access is normally only used to check if the attributes are <code class="code">NULL</code> or to reset them. Otherwise access goes through the functions <code class="code">getAttrib</code> and <code class="code">setAttrib</code> which impose restrictions on the attributes. One thing to watch is that if you copy attributes from one object to another you may (un)set the <code class="code">"class"</code> attribute and so need to copy the object and S4 bits as well. There is a macro/function <code class="code">DUPLICATE_ATTRIB</code> to automate this. </p> <p>Note that the ‘attributes’ of a <code class="code">CHARSXP</code> are used as part of the management of the <code class="code">CHARSXP</code> cache: of course <code class="code">CHARSXP</code>’s are not user-visible but C-level code might look at their attributes. </p> <p>The code assumes that the attributes of a node are either <code class="code">R_NilValue</code> or a pairlist of non-zero length (and this is checked by <code class="code">SET_ATTRIB</code>). The attributes are named (via tags on the pairlist). The replacement function <code class="code">attributes<-</code> ensures that <code class="code">"dim"</code> precedes <code class="code">"dimnames"</code> in the pairlist. Attribute <code class="code">"dim"</code> is one of several that is treated specially: the values are checked, and any <code class="code">"names"</code> and <code class="code">"dimnames"</code> attributes are removed. Similarly, you cannot set <code class="code">"dimnames"</code> without having set <code class="code">"dim"</code>, and the value assigned must be a list of the correct length and with elements of the correct lengths (and all zero-length elements are replaced by <code class="code">NULL</code>). </p> <p>The other attributes which are given special treatment are <code class="code">"names"</code>, <code class="code">"class"</code>, <code class="code">"tsp"</code>, <code class="code">"comment"</code> and <code class="code">"row.names"</code>. For pairlist-like objects the names are not stored as an attribute but (as symbols) as the tags: however the R interface makes them look like conventional attributes, and for one-dimensional arrays they are stored as the first element of the <code class="code">"dimnames"</code> attribute. The C code ensures that the <code class="code">"tsp"</code> attribute is an <code class="code">REALSXP</code>, the frequency is positive and the implied length agrees with the number of rows of the object being assigned to. Classes and comments are restricted to character vectors, and assigning a zero-length comment or class removes the attribute. Setting or removing a <code class="code">"class"</code> attribute sets the object bit appropriately. Integer row names are converted to and from the internal compact representation. </p> <a class="index-entry-id" id="index-copying-semantics-1"></a> <p>Care needs to be taken when adding attributes to objects of the types with non-standard copying semantics. There is only one object of type <code class="code">NILSXP</code>, <code class="code">R_NilValue</code>, and that should never have attributes (and this is enforced in <code class="code">installAttrib</code>). For environments, external pointers and weak references, the attributes should be relevant to all uses of the object: it is for example reasonable to have a name for an environment, and also a <code class="code">"path"</code> attribute for those environments populated from R code in a package. </p> <a class="index-entry-id" id="index-attributes_002c-preserving"></a> <a class="index-entry-id" id="index-preserving-attributes"></a> <p>When should attributes be preserved under operations on an object? Becker, Chambers & Wilks (1988, pp. 144–6) give some guidance. Scalar functions (those which operate element-by-element on a vector and whose output is similar to the input) should preserve attributes (except perhaps class, and if they do preserve class they need to preserve the <code class="code">OBJECT</code> and S4 bits). Binary operations normally call <a class="index-entry-id" id="index-copyMostAttrib"></a> <code class="code">copyMostAttrib</code> to copy most attributes from the longer argument (and if they are of the same length from both, preferring the values on the first). Here ‘most’ means all except the <code class="code">names</code>, <code class="code">dim</code> and <code class="code">dimnames</code> which are set appropriately by the code for the operator. </p> <p>Subsetting (other than by an empty index) generally drops all attributes except <code class="code">names</code>, <code class="code">dim</code> and <code class="code">dimnames</code> which are reset as appropriate. On the other hand, subassignment generally preserves such attributes even if the length is changed. Coercion drops all attributes. For example: </p> <div class="example"> <pre class="example-preformatted">> x <- structure(1:8, names=letters[1:8], comm="a comment") > x[] a b c d e f g h 1 2 3 4 5 6 7 8 attr(,"comm") [1] "a comment" > x[1:3] a b c 1 2 3 > x[3] <- 3 > x a b c d e f g h 1 2 3 4 5 6 7 8 attr(,"comm") [1] "a comment" > x[9] <- 9 > x a b c d e f g h 1 2 3 4 5 6 7 8 9 attr(,"comm") [1] "a comment" </pre></div> <hr> </div> <div class="section-level-extent" id="Contexts"> <div class="nav-panel"> <p> Next: <a href="#Argument-evaluation" accesskey="n" rel="next">Argument evaluation</a>, Previous: <a href="#Attributes" accesskey="p" rel="prev">Attributes</a>, Up: <a href="#R-Internal-Structures" accesskey="u" rel="up">R Internal Structures</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-variable-index" title="Index" rel="index">Index</a>]</p> </div> <h3 class="section" id="Contexts-1"><span>1.4 Contexts<a class="copiable-link" href="#Contexts-1"> ¶</a></span></h3> <a class="index-entry-id" id="index-context"></a> <p><em class="emph">Contexts</em> are the internal mechanism used to keep track of where a computation has got to (and from where), so that control-flow constructs can work and reasonable information can be produced on error conditions (such as <em class="emph">via</em> traceback), and otherwise (the <code class="code">sys.<var class="var">xxx</var></code> functions). </p> <p>Execution contexts are a stack of C <code class="code">structs</code>: </p> <div class="example"> <pre class="example-preformatted">typedef struct RCNTXT { struct RCNTXT *nextcontext; /* <span class="r">The next context up the chain</span> */ int callflag; /* <span class="r">The context ‘type’</span> */ JMP_BUF cjmpbuf; /* <span class="r">C stack and register information</span> */ int cstacktop; /* <span class="r">Top of the pointer protection stack</span> */ int evaldepth; /* <span class="r">Evaluation depth at inception</span> */ SEXP promargs; /* <span class="r">Promises supplied to closure</span> */ SEXP callfun; /* <span class="r">The closure called</span> */ SEXP sysparent; /* <span class="r">Environment the closure was called from</span> */ SEXP call; /* <span class="r">The call that effected this context</span> */ SEXP cloenv; /* <span class="r">The environment</span> */ SEXP conexit; /* <span class="r">Interpreted <code class="code">on.exit</code> code</span> */ void (*cend)(void *); /* <span class="r">C <code class="code">on.exit</code> thunk</span> */ void *cenddata; /* <span class="r">Data for C <code class="code">on.exit</code> thunk</span> */ char *vmax; /* <span class="r">Top of the <code class="code">R_alloc</code> stack</span> */ int intsusp; /* <span class="r">Interrupts are suspended</span> */ SEXP handlerstack; /* <span class="r">Condition handler stack</span> */ SEXP restartstack; /* <span class="r">Stack of available restarts</span> */ struct RPRSTACK *prstack; /* <span class="r">Stack of pending promises</span> */ } RCNTXT, *context; </pre></div> <p>plus additional fields for the byte-code compiler. The ‘types’ are from </p> <div class="example"> <pre class="example-preformatted">enum { CTXT_TOPLEVEL = 0, /* <span class="r">toplevel context</span> */ CTXT_NEXT = 1, /* <span class="r">target for <code class="code">next</code></span> */ CTXT_BREAK = 2, /* <span class="r">target for <code class="code">break</code></span> */ CTXT_LOOP = 3, /* <span class="r"><code class="code">break</code> or <code class="code">next</code> target</span> */ CTXT_FUNCTION = 4, /* <span class="r">function closure</span> */ CTXT_CCODE = 8, /* <span class="r">other functions that need error cleanup</span> */ CTXT_RETURN = 12, /* <span class="r"><code class="code">return()</code> from a closure</span> */ CTXT_BROWSER = 16, /* <span class="r">return target on exit from browser</span> */ CTXT_GENERIC = 20, /* <span class="r">rather, running an S3 method</span> */ CTXT_RESTART = 32, /* <span class="r">a call to <code class="code">restart</code> was made from a closure</span> */ CTXT_BUILTIN = 64 /* <span class="r">builtin internal function</span> */ }; </pre></div> <p>where the <code class="code">CTXT_FUNCTION</code> bit is on wherever function closures are involved. </p> <p>Contexts are created by a call to <code class="code">begincontext</code> and ended by a call to <code class="code">endcontext</code>: code can search up the stack for a particular type of context via <code class="code">findcontext</code> (and jump there) or jump to a specific context via <code class="code">R_JumpToContext</code>. <code class="code">R_ToplevelContext</code> is the ‘idle’ state (normally the command prompt), and <code class="code">R_GlobalContext</code> is the top of the stack. </p> <p>Note that whilst calls to closures set a context, internal functions never do and primitive builtins only set it when profiling or when they are interfaces to foreign functions. </p> <p>The byte-code compiler generates a map of instructions to source references and expressions at compile time, which allows to produce information on error conditions. As an optimization, the byte-code interpreter then does not set a context in some cases, such as in simple loops or when inlining simple builtins or wrappers for internal functions. </p> <a class="index-entry-id" id="index-UseMethod"></a> <a class="index-entry-id" id="index-method-dispatch"></a> <p>Dispatching from a S3 generic (via <code class="code">UseMethod</code> or its internal equivalent) or calling <code class="code">NextMethod</code> sets the context type to <code class="code">CTXT_GENERIC</code>. This is used to set the <code class="code">sysparent</code> of the method call to that of the <code class="code">generic</code>, so the method appears to have been called in place of the generic rather than from the generic. </p> <p>The R <code class="code">sys.frame</code> and <code class="code">sys.call</code> functions work by counting calls to closures (type <code class="code">CTXT_FUNCTION</code>) from either end of the context stack. </p> <p>Note that the <code class="code">sysparent</code> element of the structure is not the same thing as <code class="code">sys.parent()</code>. Element <code class="code">sysparent</code> is primarily used in managing changes of the function being evaluated, i.e. by <code class="code">Recall</code> and method dispatch. </p> <p><code class="code">CTXT_CCODE</code> contexts are currently used in <code class="code">cat()</code>, <code class="code">load()</code>, <code class="code">scan()</code> and <code class="code">write.table()</code> (to close the connection on error), by <code class="code">PROTECT</code>, serialization (to recover from errors, e.g. free buffers) and within the error handling code (to raise the C stack limit and reset some variables). </p> <hr> </div> <div class="section-level-extent" id="Argument-evaluation"> <div class="nav-panel"> <p> Next: <a href="#Autoprinting" accesskey="n" rel="next">Autoprinting</a>, Previous: <a href="#Contexts" accesskey="p" rel="prev">Contexts</a>, Up: <a href="#R-Internal-Structures" accesskey="u" rel="up">R Internal Structures</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-variable-index" title="Index" rel="index">Index</a>]</p> </div> <h3 class="section" id="Argument-evaluation-1"><span>1.5 Argument evaluation<a class="copiable-link" href="#Argument-evaluation-1"> ¶</a></span></h3> <a class="index-entry-id" id="index-argument-evaluation"></a> <p>As we have seen, functions in R come in three types, closures (<code class="code">SEXPTYPE</code> <code class="code">CLOSXP</code>), specials (<code class="code">SPECIALSXP</code>) and builtins (<code class="code">BUILTINSXP</code>). In this section we consider when (and if) the actual arguments of function calls are evaluated. The rules are different for the internal (special/builtin) and R-level functions (closures). </p> <p>For a call to a closure, the actual and formal arguments are matched and a matched call (another <code class="code">LANGSXP</code>) is constructed. This process first replaces the actual argument list by a list of promises to the values supplied. It then constructs a new environment which contains the names of the formal parameters matched to actual or default values: all the matched values are promises, the defaults as promises to be evaluated in the environment just created. That environment is then used for the evaluation of the body of the function, and promises will be forced (and hence actual or default arguments evaluated) when they are encountered. <a class="index-entry-id" id="index-NAMED-1"></a> (Evaluating a promise sets <code class="code">NAMED = NAMEDMAX</code> on its value, so if the argument was a symbol its binding is regarded as having multiple references during the evaluation of the closure call.) [The <code class="code">NAMED</code> mechanism has been replaced by reference counting.] </p> <p>If the closure is an S3 generic (that is, contains a call to <code class="code">UseMethod</code>) the evaluation process is the same until the <code class="code">UseMethod</code> call is encountered. At that point the argument on which to do dispatch (normally the first) will be evaluated if it has not been already. If a method has been found which is a closure, a new evaluation environment is created for it containing the matched arguments. (Note that this means changes to the values of the formal arguments in the body of the generic are discarded when calling the method, but <em class="emph">actual</em> argument promises which have been forced retain the values found when they were forced. On the other hand, missing arguments have values which are promises to use the default supplied by the method and not by the generic.) If the method found is a primitive it is called with the matched argument list of promises (possibly already forced) used for the generic. </p> <a class="index-entry-id" id="index-builtin-function"></a> <a class="index-entry-id" id="index-special-function"></a> <a class="index-entry-id" id="index-primitive-function"></a> <a class="index-entry-id" id="index-_002eInternal-function"></a> <p>The essential difference<a class="footnote" id="DOCF5" href="#FOOT5"><sup>5</sup></a> between special and builtin functions is that the arguments of specials are not evaluated before the C code is called, and those of builtins are. Note that being a special/builtin is separate from being primitive or <code class="code">.Internal</code>: <code class="code">quote</code> is a special primitive, <code class="code">+</code> is a builtin primitive, <code class="code">cbind</code> is a special <code class="code">.Internal</code> and <code class="code">grep</code> is a builtin <code class="code">.Internal</code>. </p> <a class="index-entry-id" id="index-generic_002c-internal"></a> <a class="index-entry-id" id="index-DispatchOrEval"></a> <p>Many of the internal functions are internal generics, which for specials means that they do not evaluate their arguments on call, but the C code starts with a call to <code class="code">DispatchOrEval</code>. The latter evaluates the first argument, and looks for a method based on its class. (If S4 dispatch is on, S4 methods are looked for first, even for S3 classes.) If it finds a method, it dispatches to that method with a call based on promises to evaluate the remaining arguments. If no method is found, the remaining arguments are evaluated before return to the internal generic. </p> <a class="index-entry-id" id="index-generic_002c-generic"></a> <a class="index-entry-id" id="index-DispatchGeneric"></a> <p>The other way that internal functions can be generic is to be group generic. Most such functions are builtins (so immediately evaluate all their arguments), and all contain a call to the C function <code class="code">DispatchGeneric</code>. There are some peculiarities over the number of arguments for the <code class="code">"Math"</code> group generic, with some members allowing only one argument, some having two (with a default for the second) and <code class="code">trunc</code> allows one or more but the default method only accepts one. </p> <ul class="mini-toc"> <li><a href="#Missingness" accesskey="1">Missingness</a></li> <li><a href="#Dot_002ddot_002ddot-arguments" accesskey="2">Dot-dot-dot arguments</a></li> </ul> <hr> <div class="subsection-level-extent" id="Missingness"> <div class="nav-panel"> <p> Next: <a href="#Dot_002ddot_002ddot-arguments" accesskey="n" rel="next">Dot-dot-dot arguments</a>, Previous: <a href="#Argument-evaluation" accesskey="p" rel="prev">Argument evaluation</a>, Up: <a href="#Argument-evaluation" accesskey="u" rel="up">Argument evaluation</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-variable-index" title="Index" rel="index">Index</a>]</p> </div> <h4 class="subsection" id="Missingness-1"><span>1.5.1 Missingness<a class="copiable-link" href="#Missingness-1"> ¶</a></span></h4> <a class="index-entry-id" id="index-missingness"></a> <p>Actual arguments to (non-internal) R functions can be fewer than are required to match the formal arguments of the function. Having unmatched formal arguments will not matter if the argument is never used (by lazy evaluation), but when the argument is evaluated, either its default value is evaluated (within the evaluation environment of the function) or an error is thrown with a message along the lines of </p> <div class="example"> <pre class="example-preformatted">argument "foobar" is missing, with no default </pre></div> <a class="index-entry-id" id="index-MISSING-1"></a> <a class="index-entry-id" id="index-R_005fMissingArg"></a> <p>Internally missingness is handled by two mechanisms. The object <code class="code">R_MissingArg</code> is used to indicate that a formal argument has no (default) value. When matching the actual arguments to the formal arguments, a new argument list is constructed from the formals all of whose values are <code class="code">R_MissingArg</code> with the first <code class="code">MISSING</code> bit set. Then whenever a formal argument is matched to an actual argument, the corresponding member of the new argument list has its value set to that of the matched actual argument, and if that is not <code class="code">R_MissingArg</code> the missing bit is unset. </p> <p>This new argument list is used to form the evaluation frame for the function, and if named arguments are subsequently given a new value (before they are evaluated) the missing bit is cleared. </p> <p>Missingness of arguments can be interrogated via the <code class="code">missing()</code> function. An argument is clearly missing if its missing bit is set or if the value is <code class="code">R_MissingArg</code>. However, missingness can be passed on from function to function, for using a formal argument as an actual argument in a function call does not count as evaluation. So <code class="code">missing()</code> has to examine the value (a promise) of a non-yet-evaluated formal argument to see if it might be missing, which might involve investigating a promise and so on …. </p> <p>Special primitives also need to handle missing arguments, and in some case (e.g. <code class="code">log</code>) that is why they are special and not builtin. This is usually done by testing if an argument’s value is <code class="code">R_MissingArg</code>. </p> <hr> </div> <div class="subsection-level-extent" id="Dot_002ddot_002ddot-arguments"> <div class="nav-panel"> <p> Previous: <a href="#Missingness" accesskey="p" rel="prev">Missingness</a>, Up: <a href="#Argument-evaluation" accesskey="u" rel="up">Argument evaluation</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-variable-index" title="Index" rel="index">Index</a>]</p> </div> <h4 class="subsection" id="Dot_002ddot_002ddot-arguments-1"><span>1.5.2 Dot-dot-dot arguments<a class="copiable-link" href="#Dot_002ddot_002ddot-arguments-1"> ¶</a></span></h4> <a class="index-entry-id" id="index-_002e_002e_002e-argument-1"></a> <p>Dot-dot-dot arguments are convenient when writing functions, but complicate the internal code for argument evaluation. </p> <p>The formals of a function with a <code class="code">...</code> argument represent that as a single argument like any other argument, with tag the symbol <code class="code">R_DotsSymbol</code>. When the actual arguments are matched to the formals, the value of the <code class="code">...</code> argument is of <code class="code">SEXPTYPE</code> <code class="code">DOTSXP</code>, a pairlist of promises (as used for matched arguments) but distinguished by the <code class="code">SEXPTYPE</code>. </p> <p>Recall that the evaluation frame for a function initially contains the <code class="code"><var class="var">name</var>=<var class="var">value</var></code> pairs from the matched call, and hence this will be true for <code class="code">...</code> as well. The value of <code class="code">...</code> is a (special) pairlist whose elements are referred to by the special symbols <code class="code">..1</code>, <code class="code">..2</code>, … which have the <code class="code">DDVAL</code> bit set: when one of these is encountered it is looked up (via <code class="code">ddfindVar</code>) in the value of the <code class="code">...</code> symbol in the evaluation frame. </p> <p>Values of arguments matched to a <code class="code">...</code> argument can be missing. </p> <p>Special primitives may need to handle <code class="code">...</code> arguments: see for example the internal code of <code class="code">switch</code> in file <samp class="file">src/main/builtin.c</samp>. </p> <hr> </div> </div> <div class="section-level-extent" id="Autoprinting"> <div class="nav-panel"> <p> Next: <a href="#The-write-barrier" accesskey="n" rel="next">The write barrier and the garbage collector</a>, Previous: <a href="#Argument-evaluation" accesskey="p" rel="prev">Argument evaluation</a>, Up: <a href="#R-Internal-Structures" accesskey="u" rel="up">R Internal Structures</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-variable-index" title="Index" rel="index">Index</a>]</p> </div> <h3 class="section" id="Autoprinting-1"><span>1.6 Autoprinting<a class="copiable-link" href="#Autoprinting-1"> ¶</a></span></h3> <a class="index-entry-id" id="index-autoprinting"></a> <a class="index-entry-id" id="index-R_005fVisible"></a> <p>Whether the returned value of a top-level R expression is printed is controlled by the global boolean variable <code class="code">R_Visible</code>. This is set (to true or false) on entry to all primitive and internal functions based on the <code class="code">eval</code> column of the table in file <samp class="file">src/main/names.c</samp>: the appropriate setting can be extracted by the macro <code class="code">PRIMPRINT</code>. <a class="index-entry-id" id="index-PRIMPRINT"></a> </p> <a class="index-entry-id" id="index-invisible"></a> <p>The R primitive function <code class="code">invisible</code> makes use of this mechanism: it just sets <code class="code">R_Visible = FALSE</code> before entry and returns its argument. </p> <p>For most functions the intention will be that the setting of <code class="code">R_Visible</code> when they are entered is the setting used when they return, but there need to be exceptions. The R functions <code class="code">identify</code>, <code class="code">options</code>, <code class="code">system</code> and <code class="code">writeBin</code> determine whether the result should be visible from the arguments or user action. Other functions themselves dispatch functions which may change the visibility flag: examples<a class="footnote" id="DOCF6" href="#FOOT6"><sup>6</sup></a> are <code class="code">.Internal</code>, <code class="code">do.call</code>, <code class="code">eval</code>, <code class="code">withVisible</code>, <code class="code">if</code>, <code class="code">NextMethod</code>, <code class="code">Recall</code>, <code class="code">recordGraphics</code>, <code class="code">standardGeneric</code>, <code class="code">switch</code> and <code class="code">UseMethod</code>. </p> <p>‘Special’ primitive and internal functions evaluate their arguments internally <em class="emph">after</em> <code class="code">R_Visible</code> has been set, and evaluation of the arguments (e.g. an assignment as in PR#9263) can change the value of the flag. </p> <p>The <code class="code">R_Visible</code> flag can also get altered during the evaluation of a function, with comments in the code about <code class="code">warning</code>, <code class="code">writeChar</code> and graphics functions calling <code class="code">GText</code> (PR#7397). (Since the C-level function <code class="code">eval</code> sets <code class="code">R_Visible</code>, this could apply to any function calling it. Since it is called when evaluating promises, even object lookup can change <code class="code">R_Visible</code>.) Internal and primitive functions force the documented setting of <code class="code">R_Visible</code> on return, unless the C code is allowed to change it (the exceptions above are indicated by <code class="code">PRIMPRINT</code> having value 2). </p> <p>The actual autoprinting is done by <code class="code">PrintValueEnv</code> in file <samp class="file">print.c</samp>. If the object to be printed has the S4 bit set and S4 methods dispatch is on, <code class="code">show</code> is called to print the object. Otherwise, if the object bit is set (so the object has a <code class="code">"class"</code> attribute), <code class="code">print</code> is called to dispatch methods: for objects without a class the internal code of <code class="code">print.default</code> is called. </p> <hr> </div> <div class="section-level-extent" id="The-write-barrier"> <div class="nav-panel"> <p> Next: <a href="#Serialization-Formats" accesskey="n" rel="next">Serialization Formats</a>, Previous: <a href="#Autoprinting" accesskey="p" rel="prev">Autoprinting</a>, Up: <a href="#R-Internal-Structures" accesskey="u" rel="up">R Internal Structures</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-variable-index" title="Index" rel="index">Index</a>]</p> </div> <h3 class="section" id="The-write-barrier-and-the-garbage-collector"><span>1.7 The write barrier and the garbage collector<a class="copiable-link" href="#The-write-barrier-and-the-garbage-collector"> ¶</a></span></h3> <a class="index-entry-id" id="index-write-barrier"></a> <a class="index-entry-id" id="index-garbage-collector"></a> <p>R has long had a generational garbage collector, and bit <code class="code">gcgen</code> in the <code class="code">sxpinfo</code> header is used in the implementation of this. This is used in conjunction with the <code class="code">mark</code> bit to identify two previous generations. </p> <p>There are three levels of collections. Level 0 collects only the youngest generation, level 1 collects the two youngest generations and level 2 collects all generations. After 20 level-0 collections the next collection is at level 1, and after 5 level-1 collections at level 2. Further, if a level-<var class="var">n</var> collection fails to provide 20% free space (for each of nodes and the vector heap), the next collection will be at level <var class="var">n+1</var>. (The R-level function <code class="code">gc()</code> performs a level-2 collection.) </p> <p>A generational collector needs to efficiently ‘age’ the objects, especially list-like objects (including <code class="code">STRSXP</code>s). This is done by ensuring that the elements of a list are regarded as at least as old as the list <em class="emph">when they are assigned</em>. This is handled by the functions <code class="code">SET_VECTOR_ELT</code> and <code class="code">SET_STRING_ELT</code>, which is why they are functions and not macros. Ensuring the integrity of such operations is termed the <em class="dfn">write barrier</em> and is done by making the <code class="code">SEXP</code> opaque and only providing access via functions (which cannot be used as lvalues in assignments in C). </p> <p>All code in R extensions is behind the write barrier. R extensions cannot directly access the internals of the <code class="code">SEXPREC</code>s. Base code can access internals if ‘<samp class="samp">USE_RINTERNALS</samp>’ is defined. This is normally defined in <samp class="file">Defn.h</samp> when R is compiled. To enable a check on the way that the access is used, R can be compiled with flag <samp class="option">--enable-strict-barrier</samp> which ensures that header <samp class="file">Defn.h</samp> does not define ‘<samp class="samp">USE_RINTERNALS</samp>’ and hence that <code class="code">SEXP</code> is opaque in most of R itself. (There are some necessary exceptions: foremost in file <samp class="file">memory.c</samp> where the accessor functions are defined and also in file <samp class="file">size.c</samp> which needs access to the sizes of the internal structures.) </p> <p>For background papers see <a class="uref" href="https://homepage.stat.uiowa.edu/~luke/R/barrier.html">https://homepage.stat.uiowa.edu/~luke/R/barrier.html</a> and <a class="uref" href="https://homepage.stat.uiowa.edu/~luke/R/gengcnotes.html">https://homepage.stat.uiowa.edu/~luke/R/gengcnotes.html</a>. </p> <hr> </div> <div class="section-level-extent" id="Serialization-Formats"> <div class="nav-panel"> <p> Next: <a href="#Encodings-for-CHARSXPs" accesskey="n" rel="next">Encodings for <code class="code">CHARSXP</code>s</a>, Previous: <a href="#The-write-barrier" accesskey="p" rel="prev">The write barrier and the garbage collector</a>, Up: <a href="#R-Internal-Structures" accesskey="u" rel="up">R Internal Structures</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-variable-index" title="Index" rel="index">Index</a>]</p> </div> <h3 class="section" id="Serialization-Formats-1"><span>1.8 Serialization Formats<a class="copiable-link" href="#Serialization-Formats-1"> ¶</a></span></h3> <a class="index-entry-id" id="index-serialization"></a> <p>Serialized versions of R objects are used by <code class="code">load</code>/<code class="code">save</code> and also at a slightly lower level by <code class="code">saveRDS</code>/<code class="code">readRDS</code> (and their earlier ‘internal’ dot-name versions) and <code class="code">serialize</code>/<code class="code">unserialize</code>. These differ in what they serialize to (a file, a connection, a raw vector) and whether they are intended to serialize a single object or a collection of objects (typically the workspace). <code class="code">save</code> writes a header at the beginning of the file (a single <abbr class="abbr">LF</abbr>-terminated line) which the lower-level versions do not. </p> <p><code class="code">save</code> and <code class="code">saveRDS</code> allow various forms of compression, and <code class="command">gzip</code> compression is the default (except for <abbr class="acronym">ASCII</abbr> saves). Compression is applied to the whole file stream, including the headers, so serialized files can be uncompressed or re-compressed by external programs. Both <code class="code">load</code> and <code class="code">readRDS</code> can read <code class="command">gzip</code>, <code class="command">bzip2</code> and <code class="command">xz</code> forms of compression when reading from a file, and <code class="command">gzip</code> compression when reading from a connection. </p> <p>R has used the same serialization format called ‘version 2’ from R 1.4.0 in December 2001 until R 3.5.3 in March 2019. It has been expanded in back-compatible ways since its inception, for example to support additional <code class="code">SEXPTYPE</code>s. Earlier formats are still supported via <code class="code">load</code> and <code class="code">save</code> but such formats are not described here. The current default serialization format is called ‘version 3’, and has been introduced in R 3.5.0. </p> <p><code class="code">save</code> works by writing a single-line header (typically <code class="code">RDX2\n</code> for a binary save: the only other current value is <code class="code">RDA2\n</code> for <code class="code">save(files=TRUE)</code>), then creating a tagged pairlist of the objects to be saved and serializing that single object. <code class="code">load</code> reads the header line, unserializes a single object (a pairlist or a vector list) and assigns the elements of the object in the specified environment. The header line serves two purposes in R: it identifies the serialization format so <code class="code">load</code> can switch to the appropriate reader code, and the newline <code class="code">\n</code> allows the detection of files which have been subjected to a non-binary transfer which re-mapped line endings. It can also be thought of as a ‘magic number’ in the sense used by the <code class="command">file</code> program (although R save files are not yet by default known to that program). </p> <p>Serialization in R needs to take into account that objects may contain references to environments, which then have enclosing environments and so on. (Environments recognized as package or name space environments are saved by name.) There are ‘reference objects’ which are not duplicated on copy and should remain shared on unserialization. These are weak references, external pointers and environments other than those associated with packages, namespaces and the global environment. These are handled via a hash table, and references after the first are written out as a reference marker indexed by the table entry. </p> <p>Version-2 serialization first writes a header indicating the format (normally ‘<samp class="samp">X\n</samp>’ for an <abbr class="abbr">XDR</abbr> format binary save, but ‘<samp class="samp">A\n</samp>’, ASCII, and ‘<samp class="samp">B\n</samp>’, native word-order binary, can also occur) and then three integers giving the version of the format and two R versions (packed by the <code class="code">R_Version</code> macro from <samp class="file">Rversion.h</samp>). (Unserialization interprets the two versions as the version of R which wrote the file followed by the minimal version of R needed to read the format.) Serialization then writes out the object recursively using function <code class="code">WriteItem</code> in file <samp class="file">src/main/serialize.c</samp>. </p> <p>Some objects are written as if they were <code class="code">SEXPTYPE</code>s: such pseudo-<code class="code">SEXPTYPE</code>s cover <code class="code">R_NilValue</code>, <code class="code">R_EmptyEnv</code>, <code class="code">R_BaseEnv</code>, <code class="code">R_GlobalEnv</code>, <code class="code">R_UnboundValue</code>, <code class="code">R_MissingArg</code> and <code class="code">R_BaseNamespace</code>. </p> <p>For all <code class="code">SEXPTYPE</code>s except <code class="code">NILSXP</code>, <code class="code">SYMSXP</code> and <code class="code">ENVSXP</code> serialization starts with an integer with the <code class="code">SEXPTYPE</code> in bits 0:7<a class="footnote" id="DOCF7" href="#FOOT7"><sup>7</sup></a> followed by the object bit, two bits indicating if there are any attributes and if there is a tag (for the pairlist types), an unused bit and then the <code class="code">gp</code> field<a class="footnote" id="DOCF8" href="#FOOT8"><sup>8</sup></a> in bits 12:27. Pairlist-like objects write their attributes (if any), tag (if any), CAR and then CDR (using tail recursion): other objects write their attributes after themselves. Atomic vector objects write their length followed by the data: generic vector-list objects write their length followed by a call to <code class="code">WriteItem</code> for each element. The code for <code class="code">CHARSXP</code>s special-cases <code class="code">NA_STRING</code> and writes it as length <code class="code">-1</code> with no data. Lengths no more than <code class="code">2^31 - 1</code> are written in that way and larger lengths (which only occur on 64-bit systems) as <code class="code">-1</code> followed by the upper and lower 32-bits as integers (regarded as unsigned). </p> <p>Environments are treated in several ways: as we have seen, some are written as specific pseudo-<code class="code">SEXPTYPE</code>s. Package and namespace environments are written with pseudo-<code class="code">SEXPTYPE</code>s followed by the name. ‘Normal’ environments are written out as <code class="code">ENVSXP</code>s with an integer indicating if the environment is locked followed by the enclosure, frame, ‘tag’ (the hash table) and attributes. </p> <p>In the ‘<abbr class="abbr">XDR</abbr>’ format integers and doubles are written in big-endian order: however the format is not fully <abbr class="abbr">XDR</abbr> (as defined in RFC 1832) as byte quantities (such as the contents of <code class="code">CHARSXP</code> and <code class="code">RAWSXP</code> types) are written as-is and not padded to a multiple of four bytes. </p> <p>The ‘ASCII’ format writes 7-bit characters. Integers are formatted with <code class="code">%d</code> (except that <code class="code">NA_integer_</code> is written as <code class="code">NA</code>), doubles formatted with <code class="code">%.16g</code> (plus <code class="code">NA</code>, <code class="code">Inf</code> and <code class="code">-Inf</code>) and bytes with <code class="code">%02x</code>. Strings are written using standard escapes (e.g. <code class="code">\t</code> and <code class="code">\013</code>) for non-printing and non-<abbr class="acronym">ASCII</abbr> bytes. </p> <p>Version-3 serialization extends version-2 by support for custom serialization of <code class="code">ALTREP</code> framework objects. It also stores the current native encoding at serialization time, so that unflagged strings can be converted if unserialized in R running under different native encoding. </p> <hr> </div> <div class="section-level-extent" id="Encodings-for-CHARSXPs"> <div class="nav-panel"> <p> Next: <a href="#The-CHARSXP-cache" accesskey="n" rel="next">The <code class="code">CHARSXP</code> cache</a>, Previous: <a href="#Serialization-Formats" accesskey="p" rel="prev">Serialization Formats</a>, Up: <a href="#R-Internal-Structures" accesskey="u" rel="up">R Internal Structures</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-variable-index" title="Index" rel="index">Index</a>]</p> </div> <h3 class="section" id="Encodings-for-CHARSXPs-1"><span>1.9 Encodings for <code class="code">CHARSXP</code>s<a class="copiable-link" href="#Encodings-for-CHARSXPs-1"> ¶</a></span></h3> <p>Character data in R are stored in the <code class="code">SEXPTYPE</code> <code class="code">CHARSXP</code>. </p> <p>There is support for encodings other than that of the current locale, in particular UTF-8 and the multi-byte encodings used on Windows for CJK languages. A limited means to indicate the encoding of a <code class="code">CHARSXP</code> is <em class="emph">via</em> two of the ‘general purpose’ bits which are used to declare the encoding to be either Latin-1 or UTF-8. (Note that it is possible for a character vector to contain elements in different encodings.) Both printing and plotting notice the declaration and convert the string to the current locale (possibly using <code class="code"><xx></code> to display in hexadecimal bytes that are not valid in the current locale). Many (but not all) of the character manipulation functions will either preserve the declaration or re-encode the character string. </p> <p>Strings that refer to the OS such as file names need to be passed through a wide-character interface on some OSes (e.g. Windows). </p> <p>When are character strings declared to be of known encoding? One way is to do so directly via <code class="code">Encoding</code>. The parser declares the encoding if this is known, either via the <code class="code">encoding</code> argument to <code class="code">parse</code> or from the locale within which parsing is being done at the R command line. (Other ways are recorded on the help page for <code class="code">Encoding</code>.) </p> <p>It is not necessary to declare the encoding of <abbr class="acronym">ASCII</abbr> strings as they will work in any locale. <abbr class="acronym">ASCII</abbr> strings should never have a marked encoding, as any encoding will be ignored when entering such strings into the <code class="code">CHARSXP</code> cache. </p> <p>The rationale behind considering only UTF-8 and Latin-1 was that most systems are capable of producing UTF-8 strings and this is the nearest we have to a universal format. For those that do not (for example those lacking a powerful enough <code class="code">iconv</code>), it is likely that they work in Latin-1, the old R assumption. Then the parser can return a UTF-8-encoded string if it encounters a ‘<samp class="samp">\uxxxx</samp>’ escape for a Unicode point that cannot be represented in the current charset. (This needs <abbr class="abbr">MBCS</abbr> support, and in the past was only enabled<a class="footnote" id="DOCF9" href="#FOOT9"><sup>9</sup></a> on Windows.) Now this is enabled for all platforms, and a ‘<samp class="samp">\uxxxx</samp>’ or ‘<samp class="samp">\Uxxxxxxxx</samp>’ escape ensures that the parsed string will be marked as UTF-8. </p> <p>Most of the character manipulation functions now preserve UTF-8 encodings: there are some notes as to which at the top of file <samp class="file">src/main/character.c</samp> and in file <samp class="file">src/library/base/man/Encoding.Rd</samp>. </p> <p>Graphics devices are offered the possibility of handing UTF-8-encoded strings without re-encoding to the native character set, by setting <code class="code">hasTextUTF8</code> to be ‘<samp class="samp">TRUE</samp>’ and supplying functions <code class="code">textUTF8</code> and <code class="code">strWidthUTF8</code> that expect UTF-8-encoded inputs. Normally the symbol font is encoded in Adobe Symbol encoding, but that can be re-encoded to UTF-8 by setting <code class="code">wantSymbolUTF8</code> to ‘<samp class="samp">TRUE</samp>’. The Windows’ port of cairographics has a rather peculiar assumption: it wants the symbol font to be encoded in UTF-8 as if it were encoded in Latin-1 rather than Adobe Symbol: this is selected by <code class="code">wantSymbolUTF8 = NA_LOGICAL</code>. </p> <p>Windows with <abbr class="abbr">MSVCRT</abbr> as the C runtime has no UTF-8 locales, but rather expects to work with UCS-2<a class="footnote" id="DOCF10" href="#FOOT10"><sup>10</sup></a> strings. R (being written in standard C) would not work internally with UCS-2 without extensive changes. The <samp class="file">Rgui</samp> console<a class="footnote" id="DOCF11" href="#FOOT11"><sup>11</sup></a> uses UCS-2 internally, but communicates with the R engine in the native encoding. To allow UTF-8 strings to be printed in UTF-8 in <samp class="file">Rgui.exe</samp>, an escape convention is used (see header file <samp class="file">rgui_UTF8.h</samp>) by <code class="code">cat</code>, <code class="code">print</code> and autoprinting. </p> <p>‘Unicode’ (UCS-2LE) files are common in the Windows world, and <code class="code">readLines</code> and <code class="code">scan</code> will read them into UTF-8 strings on Windows if the encoding is declared explicitly on an unopened connection passed to those functions. </p> <p>Windows have multiple notions of the current locale encoding, one is in the C runtime (C library) and another is the active code page (system locale). The active code page is used when calling non-UTF-16 variants of Windows API functions (earlier referred to as ANSI calls), either directly or indirectly via POSIX wrappers inside MinGW-w64, from R, R packages and libraries they link to. While R has handled many cases by calling directly the UTF-16 variants of the Windows API, it still may sometimes use the non-UTF-16 ones, and external libraries also primarily developed for POSIX systems typically do that. Therefore, for R to reliably work with (non-ASCII) strings on Windows, both the C locale encoding and the active code page on Windows must be the same, and by default they are. </p> <p>The Windows <abbr class="abbr">UCRT</abbr> C runtime supports UTF-8 locales. Historically, the active code page was a system-wide setting, changing which required a reboot, and UTF-8 was not supported. Later a "BETA: Use Unicode UTF-8 for worldwide language support" feature has been added to set the active code page to UTF-8, but this still required a reboot and impacted all applications, many of which would not work correctly with that unexpected setting, so it could not be used in practice. </p> <p>Windows since Windows 10 (version 1903), Windows Server 2022 (LTSC), and Windows Server 1903 (semi-annual channel) allow setting the active code page to UTF-8 in the application manifest. This changes the active code page only for the given application and does so together with changing also the <abbr class="abbr">UCRT</abbr> C locale to UTF-8. R 4.2 for Windows uses this feature to get UTF-8 as the native encoding on Windows. To make that possible, R had to switch to <abbr class="abbr">UCRT</abbr>, which in turn required creation of Rtools42. </p> <p>Older versions of Windows still rely on the previous encoding support where the native encoding cannot be UTF-8. R 4.2 requires <abbr class="abbr">UCRT</abbr> to work, but <abbr class="abbr">UCRT</abbr> can be installed on Windows since Vista SP2 and Windows Server 2008 SP2. It is shipped with Windows since Windows 10 and Windows Server 2016. </p> <hr> </div> <div class="section-level-extent" id="The-CHARSXP-cache"> <div class="nav-panel"> <p> Next: <a href="#Warnings-and-errors" accesskey="n" rel="next">Warnings and errors</a>, Previous: <a href="#Encodings-for-CHARSXPs" accesskey="p" rel="prev">Encodings for <code class="code">CHARSXP</code>s</a>, Up: <a href="#R-Internal-Structures" accesskey="u" rel="up">R Internal Structures</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-variable-index" title="Index" rel="index">Index</a>]</p> </div> <h3 class="section" id="The-CHARSXP-cache-1"><span>1.10 The <code class="code">CHARSXP</code> cache<a class="copiable-link" href="#The-CHARSXP-cache-1"> ¶</a></span></h3> <a class="index-entry-id" id="index-mkChar"></a> <p>There is a global cache for <code class="code">CHARSXP</code>s created by <code class="code">mkChar</code> — the cache ensures that most <code class="code">CHARSXP</code>s with the same contents share storage (‘contents’ including any declared encoding). Not all <code class="code">CHARSXP</code>s are part of the cache – notably ‘<samp class="samp">NA_STRING</samp>’ is not. <code class="code">CHARSXP</code>s reloaded from the <code class="code">save</code> formats of R prior to 0.99.0 are not cached (since the code used is frozen and very few examples still exist). </p> <a class="index-entry-id" id="index-mkCharLenCE"></a> <p>The cache records the encoding of the string as well as the bytes: all requests to create a <code class="code">CHARSXP</code> should be <em class="emph">via</em> a call to <code class="code">mkCharLenCE</code>. Any encoding given in <code class="code">mkCharLenCE</code> call will be ignored if the string’s bytes are all <abbr class="acronym">ASCII</abbr> characters. </p> <hr> </div> <div class="section-level-extent" id="Warnings-and-errors"> <div class="nav-panel"> <p> Next: <a href="#S4-objects" accesskey="n" rel="next">S4 objects</a>, Previous: <a href="#The-CHARSXP-cache" accesskey="p" rel="prev">The <code class="code">CHARSXP</code> cache</a>, Up: <a href="#R-Internal-Structures" accesskey="u" rel="up">R Internal Structures</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-variable-index" title="Index" rel="index">Index</a>]</p> </div> <h3 class="section" id="Warnings-and-errors-1"><span>1.11 Warnings and errors<a class="copiable-link" href="#Warnings-and-errors-1"> ¶</a></span></h3> <a class="index-entry-id" id="index-warning"></a> <a class="index-entry-id" id="index-warningcall"></a> <a class="index-entry-id" id="index-error"></a> <a class="index-entry-id" id="index-errorcall"></a> <p>Each of <code class="code">warning</code> and <code class="code">stop</code> have two C-level equivalents, <code class="code">warning</code>, <code class="code">warningcall</code>, <code class="code">error</code> and <code class="code">errorcall</code>. The relationship between the pairs is similar: <code class="code">warning</code> tries to fathom out a suitable call, and then calls <code class="code">warningcall</code> with that call as the first argument if it succeeds, and with <code class="code">call = R_NilValue</code> if it does not. When <code class="code">warningcall</code> is called, it includes the deparsed call in its printout unless <code class="code">call = R_NilValue</code>. </p> <p><code class="code">warning</code> and <code class="code">error</code> look at the context stack. If the topmost context is not of type <code class="code">CTXT_BUILTIN</code>, it is used to provide the call, otherwise the next context provides the call. This means that when these functions are called from a primitive or <code class="code">.Internal</code>, the imputed call will not be to primitive/<code class="code">.Internal</code> but to the function calling the primitive/<code class="code">.Internal</code> . This is exactly what one wants for a <code class="code">.Internal</code>, as this will give the call to the closure wrapper. (Further, for a <code class="code">.Internal</code>, the call is the argument to <code class="code">.Internal</code>, and so may not correspond to any R function.) However, it is unlikely to be what is needed for a primitive. </p> <p>The upshot is that <code class="code">warningcall</code> and <code class="code">errorcall</code> should normally be used for code called from a primitive, and <code class="code">warning</code> and <code class="code">error</code> should be used for code called from a <code class="code">.Internal</code> (and necessarily from <code class="code">.Call</code>, <code class="code">.C</code> and so on, where the call is not passed down). However, there are two complications. One is that code might be called from either a primitive or a <code class="code">.Internal</code>, in which case probably <code class="code">warningcall</code> is more appropriate. The other involves replacement functions, where the call was once of the form </p><div class="example"> <pre class="example-preformatted">> length(x) <- y ~ x Error in "length<-"(`*tmp*`, value = y ~ x) : invalid value </pre></div> <p>which is unpalatable to the end user. For replacement functions there will be a suitable context at the top of the stack, so <code class="code">warning</code> should be used. (The results for <code class="code">.Internal</code> replacement functions such as <code class="code">substr<-</code> are not ideal.) </p> <hr> </div> <div class="section-level-extent" id="S4-objects"> <div class="nav-panel"> <p> Next: <a href="#Memory-allocators" accesskey="n" rel="next">Memory allocators</a>, Previous: <a href="#Warnings-and-errors" accesskey="p" rel="prev">Warnings and errors</a>, Up: <a href="#R-Internal-Structures" accesskey="u" rel="up">R Internal Structures</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-variable-index" title="Index" rel="index">Index</a>]</p> </div> <h3 class="section" id="S4-objects-1"><span>1.12 S4 objects<a class="copiable-link" href="#S4-objects-1"> ¶</a></span></h3> <p>[This section is currently a preliminary draft and should not be taken as definitive. The description assumes that <code class="env">R_NO_METHODS_TABLES</code> has not been set.] </p> <ul class="mini-toc"> <li><a href="#Representation-of-S4-objects" accesskey="1">Representation of S4 objects</a></li> <li><a href="#S4-classes" accesskey="2">S4 classes</a></li> <li><a href="#S4-methods" accesskey="3">S4 methods</a></li> <li><a href="#Mechanics-of-S4-dispatch" accesskey="4">Mechanics of S4 dispatch</a></li> </ul> <hr> <div class="subsection-level-extent" id="Representation-of-S4-objects"> <div class="nav-panel"> <p> Next: <a href="#S4-classes" accesskey="n" rel="next">S4 classes</a>, Previous: <a href="#S4-objects" accesskey="p" rel="prev">S4 objects</a>, Up: <a href="#S4-objects" accesskey="u" rel="up">S4 objects</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-variable-index" title="Index" rel="index">Index</a>]</p> </div> <h4 class="subsection" id="Representation-of-S4-objects-1"><span>1.12.1 Representation of S4 objects<a class="copiable-link" href="#Representation-of-S4-objects-1"> ¶</a></span></h4> <p>S4 objects can be of any <code class="code">SEXPTYPE</code>. They are either an object of a simple type (such as an atomic vector or function) with S4 class information or of type <code class="code">OBJSXP</code>. In all cases, the ‘S4 bit’ (bit 4 of the ‘general purpose’ field) is set, and can be tested by the macro/function <code class="code">IS_S4_OBJECT</code>. </p> <p>S4 objects are created via <code class="code">new()</code><a class="footnote" id="DOCF12" href="#FOOT12"><sup>12</sup></a> and thence via the C function <code class="code">R_do_new_object</code>. This duplicates the prototype of the class, adds a class attribute and sets the S4 bit. All S4 class attributes should be character vectors of length one with an attribute giving (as a character string) the name of the package (or <code class="code">.GlobalEnv</code>) containing the class definition. Since S4 objects have a class attribute, the <code class="code">OBJECT</code> bit is set. </p> <p>It is currently unclear what should happen if the class attribute is removed from an S4 object, or if this should be allowed. </p> <hr> </div> <div class="subsection-level-extent" id="S4-classes"> <div class="nav-panel"> <p> Next: <a href="#S4-methods" accesskey="n" rel="next">S4 methods</a>, Previous: <a href="#Representation-of-S4-objects" accesskey="p" rel="prev">Representation of S4 objects</a>, Up: <a href="#S4-objects" accesskey="u" rel="up">S4 objects</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-variable-index" title="Index" rel="index">Index</a>]</p> </div> <h4 class="subsection" id="S4-classes-1"><span>1.12.2 S4 classes<a class="copiable-link" href="#S4-classes-1"> ¶</a></span></h4> <p>S4 classes are stored as R objects in the environment in which they are created, with names <code class="code">.__C__<var class="var">classname</var></code>: as such they are not listed by default by <code class="code">ls</code>. </p> <p>The objects are S4 objects of class <code class="code">"classRepresentation"</code> which is defined in the <strong class="strong">methods</strong> package. </p> <p>Since these are just objects, they are subject to the normal scoping rules and can be imported and exported from namespaces like other objects. The directives <code class="code">importClassesFrom</code> and <code class="code">exportClasses</code> are merely convenient ways to refer to class objects without needing to know their internal ‘metaname’ (although <code class="code">exportClasses</code> does a little sanity checking via <code class="code">isClass</code>). </p> <hr> </div> <div class="subsection-level-extent" id="S4-methods"> <div class="nav-panel"> <p> Next: <a href="#Mechanics-of-S4-dispatch" accesskey="n" rel="next">Mechanics of S4 dispatch</a>, Previous: <a href="#S4-classes" accesskey="p" rel="prev">S4 classes</a>, Up: <a href="#S4-objects" accesskey="u" rel="up">S4 objects</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-variable-index" title="Index" rel="index">Index</a>]</p> </div> <h4 class="subsection" id="S4-methods-1"><span>1.12.3 S4 methods<a class="copiable-link" href="#S4-methods-1"> ¶</a></span></h4> <p>Details of the methods are stored in environments (typically hidden in the respective namespace) with a non-syntactic name of the form <code class="code">.__T__<var class="var">generic</var>:<var class="var">package</var></code> containing objects of class <code class="code">MethodDefinition</code> for all methods defined in the current environment for the named generic derived from a specific package (which might be <code class="code">.GlobalEnv</code>). This is sometimes referred to as a ‘methods table’. </p> <p>For example, </p><div class="example"> <pre class="example-preformatted"> length(nM <- asNamespace("Matrix") ) # 941 for Matrix 1.2-6 length(meth <- grep("^[.]__T__", names(nM), value=TRUE))# 107 generics with methods length(meth.Ops <- nM$`.__T__Ops:base‘) # 71 methods for the ’Ops' (group)generic head(sort(names(meth.Ops))) ## "abIndex#abIndex" ... "ANY#ddiMatrix" "ANY#ldiMatrix" "ANY#Matrix" </pre></div> <p>During an R session there is an environment associated with each non-primitive generic containing objects <code class="code">.AllMTable</code>, <code class="code">.Generic</code>, <code class="code">.Methods</code>, <code class="code">.MTable</code>, <code class="code">.SigArgs</code> and <code class="code">.SigLength</code>. <code class="code">.MTable</code> and <code class="code">AllMTable</code> are merged methods tables containing all the methods defined directly and via inheritance respectively. <code class="code">.Methods</code> is a merged methods list. </p> <p>Exporting methods from a namespace is more complicated than exporting a class. Note first that you do not export a method, but rather the directive <code class="code">exportMethods</code> will export all the methods defined in the namespace for a specified generic: the code also adds to the list of generics any that are exported directly. For generics which are listed via <code class="code">exportMethods</code> or exported themselves, the corresponding environment is exported and so will appear (as hidden object) in the package environment. </p> <p>Methods for primitives which are internally S4 generic (see below) are always exported, whether mentioned in the <samp class="file">NAMESPACE</samp> file or not. </p> <p>Methods can be imported either via the directive <code class="code">importMethodsFrom</code> or via importing a namespace by <code class="code">import</code>. Also, if a generic is imported via <code class="code">importFrom</code>, its methods are also imported. In all cases the generic will be imported if it is in the namespace, so <code class="code">importMethodsFrom</code> is most appropriate for methods defined on generics in other packages. Since methods for a generic could be imported from several different packages, the methods tables are merged. </p> <p>When a package is attached <code class="code">methods:::cacheMetaData</code> is called to update the internal tables: only the visible methods will be cached. </p> <hr> </div> <div class="subsection-level-extent" id="Mechanics-of-S4-dispatch"> <div class="nav-panel"> <p> Previous: <a href="#S4-methods" accesskey="p" rel="prev">S4 methods</a>, Up: <a href="#S4-objects" accesskey="u" rel="up">S4 objects</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-variable-index" title="Index" rel="index">Index</a>]</p> </div> <h4 class="subsection" id="Mechanics-of-S4-dispatch-1"><span>1.12.4 Mechanics of S4 dispatch<a class="copiable-link" href="#Mechanics-of-S4-dispatch-1"> ¶</a></span></h4> <p>This subsection does not discuss how S4 methods are chosen: see <a class="uref" href="https://developer.r-project.org/howMethodsWork.pdf">https://developer.r-project.org/howMethodsWork.pdf</a>. </p> <p>For all but primitive functions, setting a method on an existing function that is not itself S4 generic creates a new object in the current environment which is a call to <code class="code">standardGeneric</code> with the old definition as the default method. Such S4 generics can also be created <em class="emph">via</em> a call to <code class="code">setGeneric</code><a class="footnote" id="DOCF13" href="#FOOT13"><sup>13</sup></a> and are standard closures in the R language, with environment the environment within which they are created. With the advent of namespaces this is somewhat problematic: if <code class="code">myfn</code> was previously in a package with a name space there will be two functions called <code class="code">myfn</code> on the search paths, and which will be called depends on which search path is in use. This is starkest for functions in the base namespace, where the original will be found ahead of the newly created function from any other package. </p> <p>Primitive functions are treated quite differently, for efficiency reasons: this results in different semantics. <code class="code">setGeneric</code> is disallowed for primitive functions. The <strong class="strong">methods</strong> namespace contains a list <code class="code">.BasicFunsList</code> named by primitive functions: the entries are either <code class="code">FALSE</code> or a standard S4 generic showing the effective definition. When <code class="code">setMethod</code> (or <code class="code">setReplaceMethod</code>) is called, it either fails (if the list entry is <code class="code">FALSE</code>) or a method is set on the effective generic given in the list. </p> <p>Actual dispatch of S4 methods for almost all primitives piggy-backs on the S3 dispatch mechanism, so S4 methods can only be dispatched for primitives which are internally S3 generic. When a primitive that is internally S3 generic is called with a first argument which is an S4 object and S4 dispatch is on (that is, the <strong class="strong">methods</strong> namespace is loaded), <code class="code">DispatchOrEval</code> calls <code class="code">R_possible_dispatch</code> (defined in file <samp class="file">src/main/objects.c</samp>). (Members of the S3 group generics, which includes all the generic operators, are treated slightly differently: the first two arguments are checked and <code class="code">DispatchGroup</code> is called.) <code class="code">R_possible_dispatch</code> first checks an internal table to see if any S4 methods are set for that generic (and S4 dispatch is currently enabled for that generic), and if so proceeds to S4 dispatch using methods stored in another internal table. All primitives are in the base namespace, and this mechanism means that S4 methods can be set for (some) primitives and will always be used, in contrast to setting methods on non-primitives. </p> <p>The exception is <code class="code">%*%</code>, which is S4 generic but not S3 generic as its C code contains a direct call to <code class="code">R_possible_dispatch</code>. </p> <p>The primitive <code class="code">as.double</code> is special, as <code class="code">as.numeric</code> and <code class="code">as.real</code> are copies of it. The <strong class="strong">methods</strong> package code partly refers to generics by name and partly by function, and maps <code class="code">as.double</code> and <code class="code">as.real</code> to <code class="code">as.numeric</code> (since that is the name used by packages exporting methods for it). </p> <p>Some elements of the language are implemented as primitives, for example <code class="code">}</code>. This includes the subset and subassignment ‘functions’ and they are S4 generic, again piggybacking on S3 dispatch. </p> <p><code class="code">.BasicFunsList</code> is generated when <strong class="strong">methods</strong> is installed, by computing all primitives, initially disallowing methods on all and then setting generics for members of <code class="code">.GenericArgsEnv</code>, the S4 group generics and a short exceptions list in file <samp class="file">BasicFunsList.R</samp>: this currently contains the subsetting and subassignment operators and an override for <code class="code">c</code>. </p> <hr> </div> </div> <div class="section-level-extent" id="Memory-allocators"> <div class="nav-panel"> <p> Next: <a href="#Internal-use-of-global-and-base-environments" accesskey="n" rel="next">Internal use of global and base environments</a>, Previous: <a href="#S4-objects" accesskey="p" rel="prev">S4 objects</a>, Up: <a href="#R-Internal-Structures" accesskey="u" rel="up">R Internal Structures</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-variable-index" title="Index" rel="index">Index</a>]</p> </div> <h3 class="section" id="Memory-allocators-1"><span>1.13 Memory allocators<a class="copiable-link" href="#Memory-allocators-1"> ¶</a></span></h3> <p>R’s memory allocation is almost all done via routines in file <samp class="file">src/main/memory.c</samp>. </p> <p>The rest of R should where possible make use of the allocators made available by file <samp class="file">src/main/memory.c</samp>, which are also the methods recommended in <a data-manual="R-exts" href="https://cran.r-project.org/doc/manuals/R-exts.html#Memory-allocation">Memory allocation</a> in <cite class="cite">Writing R Extensions</cite> <a class="index-entry-id" id="index-R_005falloc"></a> <a class="index-entry-id" id="index-R_005fCalloc"></a> <a class="index-entry-id" id="index-R_005fRealloc"></a> <a class="index-entry-id" id="index-R_005fFree"></a> for use in R packages, namely the use of <code class="code">R_alloc</code>, <code class="code">R_Calloc</code>, <code class="code">R_Realloc</code> and <code class="code">R_Free</code>. Memory allocated by <code class="code">R_alloc</code> is freed by the garbage collector once the ‘watermark’ has been reset by calling <a class="index-entry-id" id="index-vmaxset"></a> <code class="code">vmaxset</code>. This is done automatically by the wrapper code calling primitives and <code class="code">.Internal</code> functions (and also by the wrapper code to <code class="code">.Call</code> and <code class="code">.External</code>), but <a class="index-entry-id" id="index-vmaxget"></a> <code class="code">vmaxget</code> and <code class="code">vmaxset</code> can be used to reset the watermark from within internal code if the memory is only required for a short time. </p> <a class="index-entry-id" id="index-alloca"></a> <p>All of the methods of memory allocation mentioned so far are relatively expensive. All R platforms support <code class="code">alloca</code>, and in almost all cases<a class="footnote" id="DOCF14" href="#FOOT14"><sup>14</sup></a> this is managed by the compiler, allocates memory on the C stack and is very efficient. </p> <p>There are two disadvantages in using <code class="code">alloca</code>. First, it is fragile and care is needed to avoid writing (or even reading) outside the bounds of the allocation block returned. Second, it increases the danger of overflowing the C stack. It is suggested that it is only used for smallish allocations (up to tens of thousands of bytes), and that </p> <a class="index-entry-id" id="index-R_005fCheckStack"></a> <div class="example"> <pre class="example-preformatted"> R_CheckStack(); </pre></div> <p>is called immediately after the allocation (as R’s stack checking mechanism will warn far enough from the stack limit to allow for modest use of <code class="code">alloca</code>). (<code class="code">do_makeunique</code> in file <samp class="file">src/main/unique.c</samp> provides an example of both points.) </p> <p>There is an alternative check, <a class="index-entry-id" id="index-R_005fCheckStack2"></a> </p><div class="example"> <pre class="example-preformatted"> R_CheckStack2(size_t extra); </pre></div> <p>to be called immediately <em class="emph">before</em> trying an allocation of <code class="code">extra</code> bytes. </p> <p>An alternative strategy has been used for various functions which require intermediate blocks of storage of varying but usually small size, and this has been consolidated into the routines in the header file <samp class="file">src/main/RBufferUtils.h</samp>. This uses a structure which contains a buffer, the current size and the default size. A call to <a class="index-entry-id" id="index-R_005fAllocStringBuffer"></a> </p><div class="example"> <pre class="example-preformatted"> R_AllocStringBuffer(size_t blen, R_StringBuffer *buf); </pre></div> <p>sets <code class="code">buf->data</code> to a memory area of at least <code class="code">blen+1</code> bytes. At least the default size is used, which means that for small allocations the same buffer can be reused. A call to <a class="index-entry-id" id="index-R_005fFreeStringBufferL"></a> <a class="index-entry-id" id="index-R_005fFreeStringBuffer"></a> <code class="code">R_FreeStringBufferL</code> releases memory if more than the default has been allocated whereas a call to <code class="code">R_FreeStringBuffer</code> frees any memory allocated. </p> <p>The <code class="code">R_StringBuffer</code> structure needs to be initialized, for example by </p> <div class="example"> <pre class="example-preformatted">static R_StringBuffer ex_buff = {NULL, 0, MAXELTSIZE}; </pre></div> <p>which uses a default size of <code class="code">MAXELTSIZE = 8192</code> bytes. Most current uses have a static <code class="code">R_StringBuffer</code> structure, which allows the (default-sized) buffer to be shared between calls to e.g. <code class="code">grep</code> and even between functions: this will need to be changed if R ever allows concurrent evaluation threads. So the idiom is </p> <div class="example"> <pre class="example-preformatted">static R_StringBuffer ex_buff = {NULL, 0, MAXELTSIZE}; ... char *buf; for(i = 0; i < n; i++) { compute len buf = R_AllocStringBuffer(len, &ex_buff); use buf } /* free allocation if larger than the default, but leave default allocated for future use */ R_FreeStringBufferL(&ex_buff); </pre></div> <ul class="mini-toc"> <li><a href="#Internals-of-R_005falloc" accesskey="1">Internals of <code class="code">R_alloc</code></a></li> </ul> <hr> <div class="subsection-level-extent" id="Internals-of-R_005falloc"> <div class="nav-panel"> <p> Previous: <a href="#Memory-allocators" accesskey="p" rel="prev">Memory allocators</a>, Up: <a href="#Memory-allocators" accesskey="u" rel="up">Memory allocators</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-variable-index" title="Index" rel="index">Index</a>]</p> </div> <h4 class="subsection" id="Internals-of-R_005falloc-1"><span>1.13.1 Internals of <code class="code">R_alloc</code><a class="copiable-link" href="#Internals-of-R_005falloc-1"> ¶</a></span></h4> <p>The memory used by <code class="code">R_alloc</code> is allocated as R vectors, of type <code class="code">RAWSXP</code>. Thus the allocation is in units of 8 bytes, and is rounded up. A request for zero bytes currently returns <code class="code">NULL</code> (but this should not be relied on). For historical reasons, in all other cases 1 byte is added before rounding up so the allocation is always 1–8 bytes more than was asked for: again this should not be relied on. </p> <p>The vectors allocated are protected via the setting of <code class="code">R_VStack</code>, as the garbage collector marks everything that can be reached from that location. When a vector is <code class="code">R_alloc</code>ated, its <code class="code">ATTRIB</code> pointer is set to the current <code class="code">R_VStack</code>, and <code class="code">R_VStack</code> is set to the latest allocation. Thus <code class="code">R_VStack</code> is a single-linked chain of the vectors currently allocated via <code class="code">R_alloc</code>. Function <code class="code">vmaxset</code> resets the location <code class="code">R_VStack</code>, and should be to a value that has previously be obtained <em class="emph">via</em> <code class="code">vmaxget</code>: allocations after the value was obtained will no longer be protected and hence available for garbage collection. </p> <hr> </div> </div> <div class="section-level-extent" id="Internal-use-of-global-and-base-environments"> <div class="nav-panel"> <p> Next: <a href="#Modules" accesskey="n" rel="next">Modules</a>, Previous: <a href="#Memory-allocators" accesskey="p" rel="prev">Memory allocators</a>, Up: <a href="#R-Internal-Structures" accesskey="u" rel="up">R Internal Structures</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-variable-index" title="Index" rel="index">Index</a>]</p> </div> <h3 class="section" id="Internal-use-of-global-and-base-environments-1"><span>1.14 Internal use of global and base environments<a class="copiable-link" href="#Internal-use-of-global-and-base-environments-1"> ¶</a></span></h3> <p>This section notes known use by the system of these environments: the intention is to minimize or eliminate such uses. </p> <ul class="mini-toc"> <li><a href="#Base-environment" accesskey="1">Base environment</a></li> <li><a href="#Global-environment" accesskey="2">Global environment</a></li> </ul> <hr> <div class="subsection-level-extent" id="Base-environment"> <div class="nav-panel"> <p> Next: <a href="#Global-environment" accesskey="n" rel="next">Global environment</a>, Previous: <a href="#Internal-use-of-global-and-base-environments" accesskey="p" rel="prev">Internal use of global and base environments</a>, Up: <a href="#Internal-use-of-global-and-base-environments" accesskey="u" rel="up">Internal use of global and base environments</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-variable-index" title="Index" rel="index">Index</a>]</p> </div> <h4 class="subsection" id="Base-environment-1"><span>1.14.1 Base environment<a class="copiable-link" href="#Base-environment-1"> ¶</a></span></h4> <a class="index-entry-id" id="index-base-environment-1"></a> <a class="index-entry-id" id="index-environment_002c-base-1"></a> <a class="index-entry-id" id="index-_002eDevice"></a> <a class="index-entry-id" id="index-_002eDevices"></a> <p>The graphics devices system maintains two variables <code class="code">.Device</code> and <code class="code">.Devices</code> in the base environment: both are always set. The variable <code class="code">.Devices</code> gives a list of character vectors of the names of open devices, and <code class="code">.Device</code> is the element corresponding to the currently active device. The null device will always be open. </p> <a class="index-entry-id" id="index-_002eOptions"></a> <p>There appears to be a variable <code class="code">.Options</code>, a pairlist giving the current options settings. But in fact this is just a symbol with a value assigned, and so shows up as a base variable. </p> <a class="index-entry-id" id="index-_002eLast_002evalue"></a> <p>Similarly, the evaluator creates a symbol <code class="code">.Last.value</code> which appears as a variable in the base environment. </p> <a class="index-entry-id" id="index-_002eTraceback"></a> <a class="index-entry-id" id="index-last_002ewarning"></a> <p>Errors can give rise to objects <code class="code">.Traceback</code> and <code class="code">last.warning</code> in the base environment. </p> <hr> </div> <div class="subsection-level-extent" id="Global-environment"> <div class="nav-panel"> <p> Previous: <a href="#Base-environment" accesskey="p" rel="prev">Base environment</a>, Up: <a href="#Internal-use-of-global-and-base-environments" accesskey="u" rel="up">Internal use of global and base environments</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-variable-index" title="Index" rel="index">Index</a>]</p> </div> <h4 class="subsection" id="Global-environment-1"><span>1.14.2 Global environment<a class="copiable-link" href="#Global-environment-1"> ¶</a></span></h4> <a class="index-entry-id" id="index-global-environment"></a> <a class="index-entry-id" id="index-environment_002c-global"></a> <a class="index-entry-id" id="index-_002eRandom_002eseed"></a> <p>The seed for the random number generator is stored in object <code class="code">.Random.seed</code> in the global environment. </p> <a class="index-entry-id" id="index-dump_002eframes"></a> <p>Some error handlers may give rise to objects in the global environment: for example <code class="code">dump.frames</code> by default produces <code class="code">last.dump</code>. </p> <a class="index-entry-id" id="index-_002eSavedPlots"></a> <p>The <code class="code">windows()</code> device makes use of a variable <code class="code">.SavedPlots</code> to store display lists of saved plots for later display. This is regarded as a variable created by the user. </p> <hr> </div> </div> <div class="section-level-extent" id="Modules"> <div class="nav-panel"> <p> Next: <a href="#Visibility" accesskey="n" rel="next">Visibility</a>, Previous: <a href="#Internal-use-of-global-and-base-environments" accesskey="p" rel="prev">Internal use of global and base environments</a>, Up: <a href="#R-Internal-Structures" accesskey="u" rel="up">R Internal Structures</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-variable-index" title="Index" rel="index">Index</a>]</p> </div> <h3 class="section" id="Modules-1"><span>1.15 Modules<a class="copiable-link" href="#Modules-1"> ¶</a></span></h3> <a class="index-entry-id" id="index-modules"></a> <p>R makes use of a number of shared objects/DLLs stored in the <samp class="file">modules</samp> directory. These are parts of the code which have been chosen to be loaded ‘on demand’ rather than linked as dynamic libraries or incorporated into the main executable/dynamic library. </p> <p>For the remaining modules the motivation has been the amount of (often optional) code they will bring in <em class="emph">via</em> libraries to which they are linked. </p> <dl class="table"> <dt><code class="code">internet</code></dt> <dd><p>The internal HTTP and FTP clients and socket support, which link to system-specific support libraries. This may load <code class="code">libcurl</code> and on Windows will load <samp class="file">wininet.dll</samp> and <samp class="file">ws2_32.dll</samp>. </p> </dd> <dt><code class="code">lapack</code></dt> <dd><p>The code which makes use of the LAPACK library, and is linked to <samp class="file">libRlapack</samp> or an external LAPACK library. </p> </dd> <dt><code class="code">X11</code></dt> <dd><p>(Unix-alikes only.) The <code class="code">X11()</code>, <code class="code">jpeg()</code>, <code class="code">png()</code> and <code class="code">tiff()</code> devices. These are optional, and links to some or all of the <code class="code">X11</code>, <code class="code">pango</code>, <code class="code">cairo</code>, <code class="code">jpeg</code>, <code class="code">libpng</code> and <code class="code">libtiff</code> libraries. </p></dd> </dl> <hr> </div> <div class="section-level-extent" id="Visibility"> <div class="nav-panel"> <p> Next: <a href="#Lazy-loading" accesskey="n" rel="next">Lazy loading</a>, Previous: <a href="#Modules" accesskey="p" rel="prev">Modules</a>, Up: <a href="#R-Internal-Structures" accesskey="u" rel="up">R Internal Structures</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-variable-index" title="Index" rel="index">Index</a>]</p> </div> <h3 class="section" id="Visibility-1"><span>1.16 Visibility<a class="copiable-link" href="#Visibility-1"> ¶</a></span></h3> <a class="index-entry-id" id="index-visibility"></a> <ul class="mini-toc"> <li><a href="#Hiding-C-entry-points" accesskey="1">Hiding C entry points</a></li> <li><a href="#Variables-in-Windows-DLLs" accesskey="2">Variables in Windows DLLs</a></li> </ul> <hr> <div class="subsection-level-extent" id="Hiding-C-entry-points"> <div class="nav-panel"> <p> Next: <a href="#Variables-in-Windows-DLLs" accesskey="n" rel="next">Variables in Windows DLLs</a>, Previous: <a href="#Visibility" accesskey="p" rel="prev">Visibility</a>, Up: <a href="#Visibility" accesskey="u" rel="up">Visibility</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-variable-index" title="Index" rel="index">Index</a>]</p> </div> <h4 class="subsection" id="Hiding-C-entry-points-1"><span>1.16.1 Hiding C entry points<a class="copiable-link" href="#Hiding-C-entry-points-1"> ¶</a></span></h4> <p>We make use of the visibility mechanisms discussed in <a data-manual="R-exts" href="https://cran.r-project.org/doc/manuals/R-exts.html#Controlling-visibility">Controlling visibility</a> in <cite class="cite">Writing R Extensions</cite>, C entry points not needed outside the main R executable/dynamic library (and in particular in no package nor module) should be prefixed by <code class="code">attribute_hidden</code>. <a class="index-entry-id" id="index-attribute_005fhidden"></a> Minimizing the visibility of symbols in the R dynamic library will speed up linking to it (which packages will do) and reduce the possibility of linking to the wrong entry points of the same name. In addition, on some platforms reducing the number of entry points allows more efficient versions of PIC to be used: somewhat over half the entry points are hidden. A convenient way to hide variables (as distinct from functions) is to declare them <code class="code">extern0</code> in header file <samp class="file">Defn.h</samp>. </p> <p>The visibility mechanism used is only available with some compilers and platforms, and in particular not on Windows, where an alternative mechanism is used. Entry points will not be made available in <samp class="file">R.dll</samp> if they are listed in the file <samp class="file">src/gnuwin32/Rdll.hide</samp>. <a class="index-entry-id" id="index-Rdll_002ehide"></a> Entries in that file start with a space and must be strictly in alphabetic order in the C locale (use <code class="command">sort</code> on the file to ensure this if you change it). It is possible to hide Fortran as well as C entry points via this file: the former are lower-cased and have an underline as suffix, and the suffixed name should be included in the file. Some entry points exist only on Windows or need to be visible only on Windows, and some notes on these are provided in file <samp class="file">src/gnuwin32/Maintainters.notes</samp>. </p> <p>Because of the advantages of reducing the number of visible entry points, they should be declared <code class="code">attribute_hidden</code> where possible. Note that this only has an effect on a shared-R-library build, and so care is needed not to hide entry points that are legitimately used by packages. So it is best if the decision on visibility is made when a new entry point is created, including the decision if it should be included in header file <samp class="file">Rinternals.h</samp>. A list of the visible entry points on shared-R-library build on a reasonably standard Unix-alike can be made by something like </p> <div class="example"> <pre class="example-preformatted">nm -g libR.so | grep ‘ [BCDT] ’ | cut -b20- </pre></div> <hr> </div> <div class="subsection-level-extent" id="Variables-in-Windows-DLLs"> <div class="nav-panel"> <p> Previous: <a href="#Hiding-C-entry-points" accesskey="p" rel="prev">Hiding C entry points</a>, Up: <a href="#Visibility" accesskey="u" rel="up">Visibility</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-variable-index" title="Index" rel="index">Index</a>]</p> </div> <h4 class="subsection" id="Variables-in-Windows-DLLs-1"><span>1.16.2 Variables in Windows DLLs<a class="copiable-link" href="#Variables-in-Windows-DLLs-1"> ¶</a></span></h4> <p>Windows is unique in that it conventionally treats importing variables differently from functions: variables that are imported from a DLL need to be specified by a prefix (often ‘<samp class="samp">_imp_</samp>’) when being linked to (‘imported’) but not when being linked from (‘exported’). The details depend on the compiler system, and have changed for MinGW during the lifetime of that port. They are in the main hidden behind some macros defined in header file <samp class="file">R_ext/libextern.h</samp>. </p> <p>A (non-function) variable in the main R sources that needs to be referred to outside <samp class="file">R.dll</samp> (in a package, module or another DLL such as <samp class="file">Rgraphapp.dll</samp>) should be declared with prefix <code class="code">LibExtern</code>. The main use is in <samp class="file">Rinternals.h</samp>, but it needs to be considered for any public header and also <samp class="file">Defn.h</samp>. </p> <p>It would nowadays be possible to make use of the ‘auto-import’ feature of the MinGW port of <code class="command">ld</code> to fix up imports from DLLs (and if R is built for the Cygwin platform this is what happens). However, this was not possible when the MinGW build of R was first constructed in ca 1998, allows less control of visibility and would not work for other Windows compiler suites. </p> <p>It is only possible to check if this has been handled correctly by compiling the R sources on Windows. </p> <hr> </div> </div> <div class="section-level-extent" id="Lazy-loading"> <div class="nav-panel"> <p> Previous: <a href="#Visibility" accesskey="p" rel="prev">Visibility</a>, Up: <a href="#R-Internal-Structures" accesskey="u" rel="up">R Internal Structures</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-variable-index" title="Index" rel="index">Index</a>]</p> </div> <h3 class="section" id="Lazy-loading-1"><span>1.17 Lazy loading<a class="copiable-link" href="#Lazy-loading-1"> ¶</a></span></h3> <p>Lazy loading is always used for code in packages but is optional (selected by the package maintainer) for datasets in packages. When a package/namespace which uses it is loaded, the package/namespace environment is populated with promises for all the named objects: when these promises are evaluated they load the actual code from a database. </p> <p>There are separate databases for code and data, stored in the <samp class="file">R</samp> and <samp class="file">data</samp> subdirectories. The database consists of two files, <samp class="file"><var class="var">name</var>.rdb</samp> and <samp class="file"><var class="var">name</var>.rdx</samp>. The <samp class="file">.rdb</samp> file is a concatenation of serialized objects, and the <samp class="file">.rdx</samp> file contains an index. The objects are stored in (usually) a <code class="command">gzip</code>-compressed format with a 4-byte header giving the uncompressed serialized length (in <abbr class="abbr">XDR</abbr>, that is big-endian, byte order) and read by a call to the primitive <code class="code">lazyLoadDBfetch</code>. (Note that this makes lazy-loading unsuitable for really large objects: the unserialized length of an R object can exceed 4GB.) </p> <p>The index or ‘map’ file <samp class="file"><var class="var">name</var>.rdx</samp> is a compressed serialized R object to be read by <code class="code">readRDS</code>. It is a list with three elements <code class="code">variables</code>, <code class="code">references</code> and <code class="code">compressed</code>. The first two are named lists of integer vectors of length 2 giving the offset and length of the serialized object in the <samp class="file"><var class="var">name</var>.rdb</samp> file. Element <code class="code">variables</code> has an entry for each named object: <code class="code">references</code> serializes a temporary environment used when named environments are added to the database. <code class="code">compressed</code> is a logical indicating if the serialized objects were compressed: compression is always used nowadays. We later added the values <code class="code">compressed = 2</code> and <code class="code">3</code> for <code class="command">bzip2</code> and <code class="command">xz</code> compression (with the possibility of future expansion to other methods): these formats add a fifth byte to the header for the type of compression, and store serialized objects uncompressed if compression expands them. </p> <p>Source references are treated specially for performance reasons: bindings <code class="code">lines</code> and <code class="code">parseData</code> from <code class="code">srcfile</code> environments are loaded lazily. This uses a mechanism that allows loading selected bindings from an environment lazily. The key for such environment is a list with two elements: <code class="code">eagerKey</code> gives the length-two integer key for the bindings loaded eagerly and <code class="code">lazyKeys</code> gives a vector of length-two integer keys, one for each lazily loaded binding. </p> <p>The loader for a lazy-load database of code or data is function <code class="code">lazyLoad</code> in the <strong class="strong">base</strong> package, but note that there is a separate copy to load <strong class="strong">base</strong> itself in file <samp class="file">R_HOME/base/R/base</samp>. </p> <p>Lazy-load databases are created by the code in <samp class="file">src/library/tools/R/makeLazyLoad.R</samp>: the main tool is the unexported function <code class="code">makeLazyLoadDB</code> and the insertion of database entries is done by calls to <code class="code">.Call("R_lazyLoadDBinsertValue", ...)</code>. </p> <p>Lazy-load databases of less than 10MB are cached in memory at first use: this was found necessary when using file systems with high latency (removable devices and network-mounted file systems on Windows). </p> <p>Lazy-load databases are loaded into the exports for a package, but not into the namespace environment itself. Thus they are visible when the package is <em class="emph">attached</em>, and also <em class="emph">via</em> the <code class="code">::</code> operator. This was a deliberate design decision, as packages mostly make datasets available for use by the end user (or other packages), and they should not be found preferentially from functions in the package, surprising users who expected the normal search path to be used. (There is an alternative mechanism, <samp class="file">sysdata.rda</samp>, for ‘system datasets’ that are intended primarily to be used within the package.) </p> <p>The same database mechanism is used to store parsed <samp class="file">Rd</samp> files. One or all of the parsed objects is fetched by a call to <code class="code">tools:::fetchRdDB</code>. </p> <hr> </div> </div> <div class="chapter-level-extent" id="g_t_002eInternal-vs-_002ePrimitive"> <div class="nav-panel"> <p> Next: <a href="#Internationalization-in-the-R-sources" accesskey="n" rel="next">Internationalization in the R sources</a>, Previous: <a href="#R-Internal-Structures" accesskey="p" rel="prev">R Internal Structures</a>, Up: <a href="#Top" accesskey="u" rel="up">R Internals</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-variable-index" title="Index" rel="index">Index</a>]</p> </div> <h2 class="chapter" id="g_t_002eInternal-vs-_002ePrimitive-1"><span>2 <code class="code">.Internal</code> vs <code class="code">.Primitive</code><a class="copiable-link" href="#g_t_002eInternal-vs-_002ePrimitive-1"> ¶</a></span></h2> <a class="index-entry-id" id="index-_002eInternal"></a> <a class="index-entry-id" id="index-_002ePrimitive"></a> <p>C code compiled into R at build time can be called directly in what are termed <em class="emph">primitives</em> or via the <code class="code">.Internal</code> interface, which is very similar to the <code class="code">.External</code> interface except in syntax. More precisely, R maintains a table of R function names and corresponding C functions to call, which by convention all start with ‘<samp class="samp">do_</samp>’ and return a <code class="code">SEXP</code>. This table (<code class="code">R_FunTab</code> in file <samp class="file">src/main/names.c</samp>) also specifies how many arguments to a function are required or allowed, whether or not the arguments are to be evaluated before calling, and whether the function is ‘internal’ in the sense that it must be accessed via the <code class="code">.Internal</code> interface, or directly accessible in which case it is printed in R as <code class="code">.Primitive</code>. </p> <p>Functions using <code class="code">.Internal()</code> wrapped in a closure are in general preferred as this ensures standard handling of named and default arguments. For example, <code class="code">grep</code> is defined as </p> <div class="example"> <div class="group"><pre class="example-preformatted">grep <- function (pattern, x, ignore.case = FALSE, perl = FALSE, value = FALSE, fixed = FALSE, useBytes = FALSE, invert = FALSE) { if (!is.character(x)) x <- structure(as.character(x), names = names(x)) .Internal(grep(as.character(pattern), x, ignore.case, value, perl, fixed, useBytes, invert)) } </pre></div></div> <p>and the use of <code class="code">as.character</code> allows methods to be dispatched (for example, for factors). </p> <p>However, for reasons of convenience and also efficiency (as there is some overhead in using the <code class="code">.Internal</code> interface wrapped in a function closure), the primitive functions are exceptions that can be accessed directly. And of course, primitive functions are needed for basic operations—for example <code class="code">.Internal</code> is itself a primitive. Note that primitive functions make no use of R code, and hence are very different from the usual interpreted functions. In particular, <code class="code">formals</code> and <code class="code">body</code> return <code class="code">NULL</code> for such objects, and argument matching can be handled differently. For some primitives (including <code class="code">call</code>, <code class="code">switch</code>, <code class="code">.C</code> and <code class="code">.subset</code>) positional matching is important to avoid partial matching of the first argument. </p> <p>The list of primitive functions is subject to change; currently, it includes the following. </p> <ol class="enumerate"> <li> “Special functions” which really are <em class="emph">language</em> elements, but implemented as primitive functions: <div class="example"> <div class="group"><pre class="example-preformatted">{ ( if for while repeat break next return function quote switch </pre></div></div> </li><li> Language elements and basic <em class="emph">operator</em>s (i.e., functions usually <em class="emph">not</em> called as <code class="code">foo(a, b, ...)</code>) for subsetting, assignment, arithmetic, comparison and logic: <div class="example"> <div class="group"><pre class="example-preformatted"> [ [[ $ @ <- <<- = [<- [[<- $<- @<- + - * / ^ %% %*% %/% < <= == != >= > | || & && ! </pre></div></div> <p>When the arithmetic, comparison and logical operators are called as functions, any argument names are discarded so positional matching is used. </p> </li><li> “Low level” 0– and 1–argument functions which belong to one of the following groups of functions: <ol class="enumerate" type="a" start="1"> <li> Basic mathematical functions with a single argument, i.e., <div class="example"> <div class="group"><pre class="example-preformatted">abs sign sqrt floor ceiling </pre></div><pre class="example-preformatted"> </pre><div class="group"><pre class="example-preformatted">exp expm1 log2 log10 log1p cos sin tan acos asin atan cosh sinh tanh acosh asinh atanh cospi sinpi tanpi </pre></div><pre class="example-preformatted"> </pre><div class="group"><pre class="example-preformatted">gamma lgamma digamma trigamma </pre></div><pre class="example-preformatted"> </pre><div class="group"><pre class="example-preformatted">cumsum cumprod cummax cummin </pre></div><pre class="example-preformatted"> </pre><div class="group"><pre class="example-preformatted">Im Re Arg Conj Mod </pre></div></div> <p><code class="code">log</code> is a primitive function of one or two arguments with named argument matching. </p> <p><code class="code">trunc</code> is a difficult case: it is a primitive that can have one or more arguments: the default method handled in the primitive has only one. </p> </li><li> Functions rarely used outside of “programming” (i.e., mostly used inside other functions), such as <div class="example"> <div class="group"><pre class="example-preformatted">nargs missing on.exit interactive as.call as.character as.complex as.double as.environment as.integer as.logical as.raw is.array is.atomic is.call is.character is.complex is.double is.environment is.expression is.finite is.function is.infinite is.integer is.language is.list is.logical is.matrix is.na is.name is.nan is.null is.numeric is.object is.pairlist is.raw is.real is.recursive is.single is.symbol baseenv emptyenv globalenv pos.to.env unclass invisible seq_along seq_len </pre></div></div> </li><li> The programming and session management utilities <div class="example"> <div class="group"><pre class="example-preformatted">browser proc.time gc.time tracemem retracemem untracemem </pre></div></div> </li></ol> </li><li> The following basic replacement and extractor functions <div class="example"> <div class="group"><pre class="example-preformatted">length length<- class class<- oldClass oldClass<- attr attr<- attributes attributes<- names names<- dim dim<- dimnames dimnames<- environment<- levels<- storage.mode<- </pre></div></div> <a class="index-entry-id" id="index-NAMED-2"></a> <p>Note that optimizing <code class="code">NAMED = 1</code> is only effective within a primitive (as the closure wrapper of a <code class="code">.Internal</code> will set <code class="code">NAMED = NAMEDMAX</code> when the promise to the argument is evaluated) and hence replacement functions should where possible be primitive to avoid copying (at least in their default methods). [The <code class="code">NAMED</code> mechanism has been replaced by reference counting.] </p> </li><li> The following functions are primitive for efficiency reasons: <div class="example"> <div class="group"><pre class="example-preformatted">: ~ c list call expression substitute UseMethod standardGeneric .C .Fortran .Call .External round signif rep seq.int </pre></div></div> <p>as well as the following internal-use-only functions </p> <div class="example"> <div class="group"><pre class="example-preformatted">.Primitive .Internal .Call.graphics .External.graphics .subset .subset2 .primTrace .primUntrace lazyLoadDBfetch </pre></div></div> </li></ol> <p>The multi-argument primitives </p><div class="example"> <div class="group"><pre class="example-preformatted">call switch .C .Fortran .Call .External </pre></div></div> <p>intentionally use positional matching, and need to do so to avoid partial matching to their first argument. They do check that the first argument is unnamed or for the first two, partially matches the formal argument name. On the other hand, </p> <div class="example"> <div class="group"><pre class="example-preformatted">attr attr<- browser rememtrace substitute UseMethod log round signif rep seq.int </pre></div></div> <p>manage their own argument matching and do work in the standard way. </p> <p>All the one-argument primitives check that if they are called with a named argument that this (partially) matches the name given in the documentation: this is also done for replacement functions with one argument plus <code class="code">value</code>. </p> <p>The net effect is that argument matching for primitives intended for end-user use <em class="emph">as functions</em> is done in the same way as for interpreted functions except for the six exceptions where positional matching is required. </p> <ul class="mini-toc"> <li><a href="#Special-primitives" accesskey="1">Special primitives</a></li> <li><a href="#Special-internals" accesskey="2">Special internals</a></li> <li><a href="#Prototypes-for-primitives" accesskey="3">Prototypes for primitives</a></li> <li><a href="#Adding-a-primitive" accesskey="4">Adding a primitive</a></li> </ul> <hr> <div class="section-level-extent" id="Special-primitives"> <div class="nav-panel"> <p> Next: <a href="#Special-internals" accesskey="n" rel="next">Special internals</a>, Previous: <a href="#g_t_002eInternal-vs-_002ePrimitive" accesskey="p" rel="prev"><code class="code">.Internal</code> vs <code class="code">.Primitive</code></a>, Up: <a href="#g_t_002eInternal-vs-_002ePrimitive" accesskey="u" rel="up"><code class="code">.Internal</code> vs <code class="code">.Primitive</code></a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-variable-index" title="Index" rel="index">Index</a>]</p> </div> <h3 class="section" id="Special-primitives-1"><span>2.1 Special primitives<a class="copiable-link" href="#Special-primitives-1"> ¶</a></span></h3> <p>A small number of primitives are <em class="emph">specials</em> rather than <em class="emph">builtins</em>, that is they are entered with unevaluated arguments. This is clearly necessary for the language constructs and the assignment operators, as well as for <code class="code">&&</code> and <code class="code">||</code> which conditionally evaluate their second argument, and <code class="code">~</code>, <code class="code">.Internal</code>, <code class="code">call</code>, <code class="code">expression</code>, <code class="code">missing</code>, <code class="code">on.exit</code>, <code class="code">quote</code> and <code class="code">substitute</code> which do not evaluate some of their arguments. </p> <p><code class="code">rep</code> and <code class="code">seq.int</code> are special as they evaluate some of their arguments conditional on which are non-missing. </p> <p><code class="code">log</code>, <code class="code">round</code> and <code class="code">signif</code> are special to allow default values to be given to missing arguments. </p> <p>The subsetting, subassignment and <code class="code">@</code> operators are all special. (For both extraction and replacement forms, <code class="code">$</code> and <code class="code">@</code> take a symbol argument, and <code class="code">[</code> and <code class="code">[[</code> allow missing arguments.) </p> <p><code class="code">UseMethod</code> is special to avoid the additional contexts added to calls to builtins. </p> <hr> </div> <div class="section-level-extent" id="Special-internals"> <div class="nav-panel"> <p> Next: <a href="#Prototypes-for-primitives" accesskey="n" rel="next">Prototypes for primitives</a>, Previous: <a href="#Special-primitives" accesskey="p" rel="prev">Special primitives</a>, Up: <a href="#g_t_002eInternal-vs-_002ePrimitive" accesskey="u" rel="up"><code class="code">.Internal</code> vs <code class="code">.Primitive</code></a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-variable-index" title="Index" rel="index">Index</a>]</p> </div> <h3 class="section" id="Special-internals-1"><span>2.2 Special internals<a class="copiable-link" href="#Special-internals-1"> ¶</a></span></h3> <p>There are also special <code class="code">.Internal</code> functions: <code class="code">NextMethod</code>, <code class="code">Recall</code>, <code class="code">withVisible</code>, <code class="code">cbind</code>, <code class="code">rbind</code> (to allow for the <code class="code">deparse.level</code> argument), <code class="code">eapply</code>, <code class="code">lapply</code> and <code class="code">vapply</code>. </p> <hr> </div> <div class="section-level-extent" id="Prototypes-for-primitives"> <div class="nav-panel"> <p> Next: <a href="#Adding-a-primitive" accesskey="n" rel="next">Adding a primitive</a>, Previous: <a href="#Special-internals" accesskey="p" rel="prev">Special internals</a>, Up: <a href="#g_t_002eInternal-vs-_002ePrimitive" accesskey="u" rel="up"><code class="code">.Internal</code> vs <code class="code">.Primitive</code></a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-variable-index" title="Index" rel="index">Index</a>]</p> </div> <h3 class="section" id="Prototypes-for-primitives-1"><span>2.3 Prototypes for primitives<a class="copiable-link" href="#Prototypes-for-primitives-1"> ¶</a></span></h3> <p>Prototypes are available for the primitive functions and operators, and these are used for printing, <code class="code">args</code> and package checking (e.g. by <code class="code">tools::checkS3methods</code> and by package <a class="url" href="https://CRAN.R-project.org/package=codetools"><strong class="strong">codetools</strong></a>). There are two environments in the <strong class="strong">base</strong> package (and namespace), ‘<samp class="samp">.GenericArgsEnv</samp>’ for those primitives which are internal S3 generics, and ‘<samp class="samp">.ArgsEnv</samp>’ for the rest. Those environments contain closures with the same names as the primitives, formal arguments derived (manually) from the help pages, a body which is a suitable call to <code class="code">UseMethod</code> or <code class="code">NULL</code> and environment the base namespace. </p> <p>The C code for <code class="code">print.default</code> and <code class="code">args</code> uses the closures in these environments in preference to the definitions in base (as primitives). </p> <p>The QC function <code class="code">undoc</code> checks that all the functions prototyped in these environments are currently primitive, and that the primitives not included are better thought of as language elements (at the time of writing </p> <div class="example"> <pre class="example-preformatted">$ $<- && ( : @ @<- [ [[ [[<- [<- { || ~ <- <<- = break for function if next repeat return while </pre></div> <p>). One could argue about <code class="code">~</code>, but it is known to the parser and has semantics quite unlike a normal function. And <code class="code">:</code> is documented with different argument names in its two meanings. </p> <p>The QC functions <code class="code">codoc</code> and <code class="code">checkS3methods</code> also make use of these environments (effectively placing them in front of base in the search path), and hence the formals of the functions they contain are checked against the help pages by <code class="code">codoc</code>. However, there are two problems with the generic primitives. The first is that many of the operators are part of the S3 group generic <code class="code">Ops</code> and that defines their arguments to be <code class="code">e1</code> and <code class="code">e2</code>: although it would be very unusual, an operator could be called as e.g. <code class="code">"+"(e1=a, e2=b)</code> and if method dispatch occurred to a closure, there would be an argument name mismatch. So the definitions in environment <code class="code">.GenericArgsEnv</code> have to use argument names <code class="code">e1</code> and <code class="code">e2</code> even though the traditional documentation is in terms of <code class="code">x</code> and <code class="code">y</code>: <code class="code">codoc</code> makes the appropriate adjustment via <code class="code">tools:::.make_S3_primitive_generic_env</code>. The second discrepancy is with the <code class="code">Math</code> group generics, where the group generic is defined with argument list <code class="code">(x, ...)</code>, but most of the members only allow one argument when used as the default method (and <code class="code">round</code> and <code class="code">signif</code> allow two as default methods): again fix-ups are used. </p> <p>Those primitives which are in <code class="code">.GenericArgsEnv</code> are checked (via <samp class="file">tests/primitives.R</samp>) to be generic <em class="emph">via</em> defining methods for them, and a check is made that the remaining primitives are probably not generic, by setting a method and checking it is not dispatched to (but this can fail for other reasons). However, there is no certain way to know that if other <code class="code">.Internal</code> or primitive functions are not internally generic except by reading the source code. </p> <hr> </div> <div class="section-level-extent" id="Adding-a-primitive"> <div class="nav-panel"> <p> Previous: <a href="#Prototypes-for-primitives" accesskey="p" rel="prev">Prototypes for primitives</a>, Up: <a href="#g_t_002eInternal-vs-_002ePrimitive" accesskey="u" rel="up"><code class="code">.Internal</code> vs <code class="code">.Primitive</code></a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-variable-index" title="Index" rel="index">Index</a>]</p> </div> <h3 class="section" id="Adding-a-primitive-1"><span>2.4 Adding a primitive<a class="copiable-link" href="#Adding-a-primitive-1"> ¶</a></span></h3> <p>[For R-core use: reverse this procedure to remove a primitive. Most commonly this is done by changing a <code class="code">.Internal</code> to a primitive or <em class="emph">vice versa</em>.] </p> <p>Primitives are listed in the table <code class="code">R_FunTab</code> in <samp class="file">src/main/names.c</samp>: primitives have ‘<samp class="samp">Y = 0</samp>’ in the ‘<samp class="samp">eval</samp>’ field. </p> <p>There needs to be an ‘<samp class="samp">\alias</samp>’ entry in a help file in the <strong class="strong">base</strong> package, and the primitive needs to be added to one of the lists at the start of this section. </p> <p>Some primitives are regarded as language elements (the current ones are listed above). These need to be added to two lists of exceptions, <code class="code">langElts</code> in <code class="code">undoc()</code> (in file <samp class="file">src/library/tools/R/QC.R</samp>) and <code class="code">lang_elements</code> in <samp class="file">tests/primitives.R</samp>. </p> <p>All other primitives are regarded as functions and should be listed in one of the environments defined in <samp class="file">src/library/base/R/zzz.R</samp>, either <code class="code">.ArgsEnv</code> or <code class="code">.GenericArgsEnv</code>: internal generics also need to be listed in the character vector <code class="code">.S3PrimitiveGenerics</code>. Note too the discussion about argument matching above: if you add a primitive function with more than one argument by converting a <code class="code">.Internal</code> you need to add argument matching to the C code, and for those with a single argument, add argument-name checking. </p> <p>Do ensure that <code class="command">make check-devel</code> has been run: that tests most of these requirements. </p> <hr> </div> </div> <div class="chapter-level-extent" id="Internationalization-in-the-R-sources"> <div class="nav-panel"> <p> Next: <a href="#Package-Structure" accesskey="n" rel="next">Structure of an Installed Package</a>, Previous: <a href="#g_t_002eInternal-vs-_002ePrimitive" accesskey="p" rel="prev"><code class="code">.Internal</code> vs <code class="code">.Primitive</code></a>, Up: <a href="#Top" accesskey="u" rel="up">R Internals</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-variable-index" title="Index" rel="index">Index</a>]</p> </div> <h2 class="chapter" id="Internationalization-in-the-R-sources-1"><span>3 Internationalization in the R sources<a class="copiable-link" href="#Internationalization-in-the-R-sources-1"> ¶</a></span></h2> <p>The process of marking messages (errors, warnings etc) for translation in an R package is described in <a data-manual="R-exts" href="https://cran.r-project.org/doc/manuals/R-exts.html#Internationalization">Internationalization</a> in <cite class="cite">Writing R Extensions</cite>, and the standard packages included with R have (with an exception in <strong class="strong">grDevices</strong> for the menus of the <code class="code">windows()</code> device) been internationalized in the same way as other packages. </p> <ul class="mini-toc"> <li><a href="#R-code" accesskey="1">R code</a></li> <li><a href="#Main-C-code" accesskey="2">Main C code</a></li> <li><a href="#Windows_002dGUI_002dspecific-code" accesskey="3">Windows-GUI-specific code</a></li> <li><a href="#macOS-GUI" accesskey="4">macOS GUI</a></li> <li><a href="#Updating" accesskey="5">Updating</a></li> </ul> <hr> <div class="section-level-extent" id="R-code"> <div class="nav-panel"> <p> Next: <a href="#Main-C-code" accesskey="n" rel="next">Main C code</a>, Previous: <a href="#Internationalization-in-the-R-sources" accesskey="p" rel="prev">Internationalization in the R sources</a>, Up: <a href="#Internationalization-in-the-R-sources" accesskey="u" rel="up">Internationalization in the R sources</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-variable-index" title="Index" rel="index">Index</a>]</p> </div> <h3 class="section" id="R-code-1"><span>3.1 R code<a class="copiable-link" href="#R-code-1"> ¶</a></span></h3> <p>Internationalization for R code is done in exactly the same way as for extension packages. As all standard packages which have R code also have a namespace, it is never necessary to specify <code class="code">domain</code>, but for efficiency calls to <code class="code">message</code>, <code class="code">warning</code> and <code class="code">stop</code> should include <code class="code">domain = NA</code> when the message is constructed <em class="emph">via</em> <code class="code">gettextf</code>, <code class="code">gettext</code> or <code class="code">ngettext</code>. </p> <p>For each package, the extracted messages and translation sources are stored under package directory <samp class="file">po</samp> in the source package, and compiled translations under <samp class="file">inst/po</samp> for installation to package directory <samp class="file">po</samp> in the installed package. This also applies to C code in packages. </p> <hr> </div> <div class="section-level-extent" id="Main-C-code"> <div class="nav-panel"> <p> Next: <a href="#Windows_002dGUI_002dspecific-code" accesskey="n" rel="next">Windows-GUI-specific code</a>, Previous: <a href="#R-code" accesskey="p" rel="prev">R code</a>, Up: <a href="#Internationalization-in-the-R-sources" accesskey="u" rel="up">Internationalization in the R sources</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-variable-index" title="Index" rel="index">Index</a>]</p> </div> <h3 class="section" id="Main-C-code-1"><span>3.2 Main C code<a class="copiable-link" href="#Main-C-code-1"> ¶</a></span></h3> <p>The main C code (e.g. that in files <samp class="file">src/*/*.c</samp> and in the modules) is where R is closest to the sort of application for which ‘<samp class="samp">gettext</samp>’ was written. Messages in the main C code are in domain <code class="code">R</code> and stored in the top-level directory <samp class="file">po</samp> with compiled translations under <samp class="file">share/locale</samp>. </p> <p>The list of files covered by the R domain is specified in file <samp class="file">po/POTFILES.in</samp>. </p> <p>The normal way to mark messages for translation is via <code class="code">_("msg")</code> just as for packages. However, sometimes one needs to mark passages for translation without wanting them translated at the time, for example when declaring string constants. This is the purpose of the <code class="code">N_</code> macro, for example </p> <div class="example"> <pre class="example-preformatted">{ ERROR_ARGTYPE, N_("invalid argument type")}, </pre></div> <p>from file <samp class="file">src/main/errors.c</samp>. </p> <p>The <code class="code">P_</code> macro </p> <div class="example"> <pre class="example-preformatted">#ifdef ENABLE_NLS #define P_(StringS, StringP, N) ngettext (StringS, StringP, N) #else #define P_(StringS, StringP, N) (N > 1 ? StringP: StringS) #endif </pre></div> <p>may be used as a wrapper for <code class="code">ngettext</code>: however in some cases the preferred approach has been to conditionalize (on <code class="code">ENABLE_NLS</code>) code using <code class="code">ngettext</code>. </p> <p>The macro <code class="code">_("msg")</code> can safely be used in directory <samp class="file">src/appl</samp>; the header for standalone ‘<samp class="samp">nmath</samp>’ skips possible translation. (This does not apply to <code class="code">N_</code> or <code class="code">P_</code>). </p> <hr> </div> <div class="section-level-extent" id="Windows_002dGUI_002dspecific-code"> <div class="nav-panel"> <p> Next: <a href="#macOS-GUI" accesskey="n" rel="next">macOS GUI</a>, Previous: <a href="#Main-C-code" accesskey="p" rel="prev">Main C code</a>, Up: <a href="#Internationalization-in-the-R-sources" accesskey="u" rel="up">Internationalization in the R sources</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-variable-index" title="Index" rel="index">Index</a>]</p> </div> <h3 class="section" id="Windows_002dGUI_002dspecific-code-1"><span>3.3 Windows-GUI-specific code<a class="copiable-link" href="#Windows_002dGUI_002dspecific-code-1"> ¶</a></span></h3> <p>Messages for the Windows GUI are in a separate domain ‘<samp class="samp">RGui</samp>’. This was done for two reasons: </p> <ul class="itemize mark-bullet"> <li>The translators for the Windows version of R might be separate from those for the rest of R (familiarity with the GUI helps), and </li><li>Messages for Windows are most naturally handled in the native charset for the language, and in the case of CJK languages the charset is Windows-specific. (It transpires that as the <code class="code">iconv</code> we ported works well under Windows, this is less important than anticipated.) </li></ul> <p>Messages for the ‘<samp class="samp">RGui</samp>’ domain are marked by <code class="code">G_("msg")</code>, a macro that is defined in header file <samp class="file">src/gnuwin32/win-nls.h</samp>. The list of files that are considered is hardcoded in function <code class="code">update_RGui_po</code> in file <samp class="file">src/library/tools/R/translations.R</samp>, which is invoked via the <code class="code">update-RGui</code> target of file <samp class="file">po/Makefile.win</samp>: note that this includes <samp class="file">devWindows.c</samp> as the menus on the <code class="code">windows</code> device are considered to be part of the GUI. (There is also <code class="code">GN_("msg")</code>, the analogue of <code class="code">N_("msg")</code>.) </p> <p>The template and message catalogs for the ‘<samp class="samp">RGui</samp>’ domain are in the top-level <samp class="file">po</samp> directory of package <strong class="strong">base</strong>. </p> <hr> </div> <div class="section-level-extent" id="macOS-GUI"> <div class="nav-panel"> <p> Next: <a href="#Updating" accesskey="n" rel="next">Updating</a>, Previous: <a href="#Windows_002dGUI_002dspecific-code" accesskey="p" rel="prev">Windows-GUI-specific code</a>, Up: <a href="#Internationalization-in-the-R-sources" accesskey="u" rel="up">Internationalization in the R sources</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-variable-index" title="Index" rel="index">Index</a>]</p> </div> <h3 class="section" id="macOS-GUI-1"><span>3.4 macOS GUI<a class="copiable-link" href="#macOS-GUI-1"> ¶</a></span></h3> <p>This is handled separately: see <a class="uref" href="https://developer.r-project.org/Translations30.html">https://developer.r-project.org/Translations30.html</a>. </p> <hr> </div> <div class="section-level-extent" id="Updating"> <div class="nav-panel"> <p> Previous: <a href="#macOS-GUI" accesskey="p" rel="prev">macOS GUI</a>, Up: <a href="#Internationalization-in-the-R-sources" accesskey="u" rel="up">Internationalization in the R sources</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-variable-index" title="Index" rel="index">Index</a>]</p> </div> <h3 class="section" id="Updating-1"><span>3.5 Updating<a class="copiable-link" href="#Updating-1"> ¶</a></span></h3> <p>See file <samp class="file">po/README</samp> for how to update the message templates and catalogs. </p> <hr> </div> </div> <div class="chapter-level-extent" id="Package-Structure"> <div class="nav-panel"> <p> Next: <a href="#Files" accesskey="n" rel="next">Files</a>, Previous: <a href="#Internationalization-in-the-R-sources" accesskey="p" rel="prev">Internationalization in the R sources</a>, Up: <a href="#Top" accesskey="u" rel="up">R Internals</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-variable-index" title="Index" rel="index">Index</a>]</p> </div> <h2 class="chapter" id="Structure-of-an-Installed-Package"><span>4 Structure of an Installed Package<a class="copiable-link" href="#Structure-of-an-Installed-Package"> ¶</a></span></h2> <p>The structure of a <em class="emph">source</em> packages is described in <a data-manual="R-exts" href="https://cran.r-project.org/doc/manuals/R-exts.html#Creating-R-packages">Creating R packages</a> in <cite class="cite">Writing R Extensions</cite>: this chapter is concerned with the structure of <em class="emph">installed</em> packages. </p> <p>An installed package has a top-level file <samp class="file">DESCRIPTION</samp>, a copy of the file of that name in the package sources with a ‘<samp class="samp">Built</samp>’ field appended, and file <samp class="file">INDEX</samp>, usually describing the objects on which help is available, a file <samp class="file">NAMESPACE</samp> if the package has a name space, optional files such as <samp class="file">CITATION</samp>, <samp class="file">LICENCE</samp> and <samp class="file">NEWS</samp>, and any other files copied in from <samp class="file">inst</samp>. It will have directories <samp class="file">Meta</samp>, <samp class="file">help</samp> and <samp class="file">html</samp> (even if the package has no help pages), almost always has a directory <samp class="file">R</samp> and often has a directory <samp class="file">libs</samp> to contain compiled code. Other directories with known meaning to R are <samp class="file">data</samp>, <samp class="file">demo</samp>, <samp class="file">doc</samp> and <samp class="file">po</samp>. </p> <p>Function <code class="code">library</code> looks for a namespace and if one is found passes control to <code class="code">loadNamespace</code>. Then <code class="code">library</code> or <code class="code">loadNamespace</code> looks for file <samp class="file">R/<var class="var">pkgname</var></samp>, warns if it is not found and otherwise sources the code (using <code class="code">sys.source</code>) into the package’s environment, then lazy-loads a database <samp class="file">R/sysdata</samp> if present. So how R code gets loaded depends on the contents of <samp class="file">R/<var class="var">pkgname</var></samp>: a standard template to load lazy-load databases are provided in <samp class="file">share/R/nspackloader.R</samp>. </p> <p>Compiled code is usually loaded when the package’s namespace is loaded by a <code class="code">useDynlib</code> directive in a <samp class="file">NAMESPACE</samp> file or by the package’s <code class="code">.onLoad</code> function. Conventionally compiled code is loaded by a call to <code class="code">library.dynam</code> and this looks in directory <samp class="file">libs</samp> (and in an appropriate sub-directory if sub-architectures are in use) for a shared object (Unix-alike) or DLL (Windows). </p> <p>Subdirectory <samp class="file">data</samp> serves two purposes. In a package using lazy-loading of data, it contains a lazy-load database <samp class="file">Rdata</samp>, plus a file <samp class="file">Rdata.rds</samp> which contain a named character vector used by <code class="code">data()</code> in the (unusual) event that it is used for such a package. Otherwise it is a copy of the <samp class="file">data</samp> directory in the sources, with saved images re-compressed if <code class="command">R CMD INSTALL --resave-data</code> was used. </p> <p>Subdirectory <samp class="file">demo</samp> supports the <code class="code">demo</code> function, and is copied from the sources. </p> <p>Subdirectory <samp class="file">po</samp> contains (in subdirectories) compiled message catalogs. </p> <ul class="mini-toc"> <li><a href="#Metadata" accesskey="1">Metadata</a></li> <li><a href="#Help" accesskey="2">Help</a></li> </ul> <hr> <div class="section-level-extent" id="Metadata"> <div class="nav-panel"> <p> Next: <a href="#Help" accesskey="n" rel="next">Help</a>, Previous: <a href="#Package-Structure" accesskey="p" rel="prev">Structure of an Installed Package</a>, Up: <a href="#Package-Structure" accesskey="u" rel="up">Structure of an Installed Package</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-variable-index" title="Index" rel="index">Index</a>]</p> </div> <h3 class="section" id="Metadata-1"><span>4.1 Metadata<a class="copiable-link" href="#Metadata-1"> ¶</a></span></h3> <p>Directory <samp class="file">Meta</samp> contains several files in <code class="code">.rds</code> format, that is serialized R objects written by <code class="code">saveRDS</code>. All packages have files <samp class="file">Rd.rds</samp>, <samp class="file">hsearch.rds</samp>, <samp class="file">links.rds</samp>, <samp class="file">features.rds</samp>, and <samp class="file">package.rds</samp>. Packages with namespaces have a file <samp class="file">nsInfo.rds</samp>, and those with data, demos or vignettes have <samp class="file">data.rds</samp>, <samp class="file">demo.rds</samp> or <samp class="file">vignette.rds</samp> files. </p> <p>The structure of these files (and their existence and names) is private to R, so the description here is for those trying to follow the R sources: there should be no reference to these files in non-base packages. </p> <p>File <samp class="file">package.rds</samp> is a dump of information extracted from the <samp class="file">DESCRIPTION</samp> file. It is a list of several components. The first, ‘<samp class="samp">DESCRIPTION</samp>’, is a character vector, the <samp class="file">DESCRIPTION</samp> file as read by <code class="code">read.dcf</code>. Further elements ‘<samp class="samp">Depends</samp>’, ‘<samp class="samp">Suggests</samp>’, ‘<samp class="samp">Imports</samp>’, ‘<samp class="samp">Rdepends</samp>’ and ‘<samp class="samp">Rdepends2</samp>’ record the ‘<samp class="samp">Depends</samp>’, ‘<samp class="samp">Suggests</samp>’ and ‘<samp class="samp">Imports</samp>’ fields. These are all lists, and can be empty. The first three have an entry for each package named, each entry being a list of length 1 or 3, which element ‘<samp class="samp">name</samp>’ (the package name) and optional elements ‘<samp class="samp">op</samp>’ (a character string) and ‘<samp class="samp">version</samp>’ (an object of class ‘<samp class="samp">"package_version"</samp>’). Element ‘<samp class="samp">Rdepends</samp>’ is used for the first version dependency on R, and ‘<samp class="samp">Rdepends2</samp>’ is a list of zero or more R version dependencies—each is a three-element list of the form described for packages. Element ‘<samp class="samp">Rdepends</samp>’ is no longer used, but it is still potentially needed so R < 2.7.0 can detect that the package was not installed for it. </p> <p>File <samp class="file">nsInfo.rds</samp> records a list, a parsed version of the <samp class="file">NAMESPACE</samp> file. </p> <p>File <samp class="file">Rd.rds</samp> records a data frame with one row for each help file. The columns are ‘<samp class="samp">File</samp>’ (the file name with extension), ‘<samp class="samp">Name</samp>’ (the ‘<samp class="samp">\name</samp>’ section), ‘<samp class="samp">Type</samp>’ (from the optional ‘<samp class="samp">\docType</samp>’ section), ‘<samp class="samp">Title</samp>’, ‘<samp class="samp">Encoding</samp>’, ‘<samp class="samp">Aliases</samp>’, ‘<samp class="samp">Concepts</samp>’ and ‘<samp class="samp">Keywords</samp>’. All columns are character vectors apart from the last three, which are lists of character vectors. </p> <p>File <samp class="file">hsearch.rds</samp> records the information to be used by ‘<samp class="samp">help.search</samp>’. This is a list of four unnamed elements which are character matrices for help files, aliases, keywords and concepts. All the matrices have columns ‘<samp class="samp">ID</samp>’ and ‘<samp class="samp">Package</samp>’ which are used to tie the aliases, keywords and concepts (the remaining column of the last three elements) to a particular help file. The first element has further columns ‘<samp class="samp">LibPath</samp>’ (stored as <code class="code">""</code> and filled in what the file is loaded), ‘<samp class="samp">name</samp>’, ‘<samp class="samp">title</samp>’, ‘<samp class="samp">topic</samp>’ (the first alias, used when presenting the results as ‘<samp class="samp"><var class="var">pkgname</var>::<var class="var">topic</var></samp>’) and ‘<samp class="samp">Encoding</samp>’. </p> <p>File <samp class="file">links.rds</samp> records a named character vector, the names being aliases and the values character strings of the form </p><div class="example"> <pre class="example-preformatted">"../../<var class="var">pkgname</var>/html/<var class="var">filename</var>.html" </pre></div> <p>File <samp class="file">data.rds</samp> records a two-column character matrix with columns of dataset names and titles from the corresponding help file. File <samp class="file">demo.rds</samp> has the same structure for package demos. </p> <p>File <samp class="file">vignette.rds</samp> records a data frame with one row for each ‘vignette’ (<samp class="file">.[RS]nw</samp> file in <samp class="file">inst/doc</samp>) and with columns ‘<samp class="samp">File</samp>’ (the full file path in the sources), ‘<samp class="samp">Title</samp>’, ‘<samp class="samp">PDF</samp>’ (the pathless file name of the installed PDF version, if present), ‘<samp class="samp">Depends</samp>’, ‘<samp class="samp">Keywords</samp>’ and ‘<samp class="samp">R</samp>’ (the pathless file name of the installed R code, if present). </p> <hr> </div> <div class="section-level-extent" id="Help"> <div class="nav-panel"> <p> Previous: <a href="#Metadata" accesskey="p" rel="prev">Metadata</a>, Up: <a href="#Package-Structure" accesskey="u" rel="up">Structure of an Installed Package</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-variable-index" title="Index" rel="index">Index</a>]</p> </div> <h3 class="section" id="Help-1"><span>4.2 Help<a class="copiable-link" href="#Help-1"> ¶</a></span></h3> <p>All installed packages, whether they had any <samp class="file">.Rd</samp> files or not, have <samp class="file">help</samp> and <samp class="file">html</samp> directories. The latter normally only contains the single file <samp class="file">00Index.html</samp>, the package index which has hyperlinks to the help topics (if any). </p> <p>Directory <samp class="file">help</samp> contains files <samp class="file">AnIndex</samp>, <samp class="file">paths.rds</samp> and <samp class="file"><var class="var">pkgname</var>.rd[bx]</samp>. The latter two files are a lazy-load database of parsed <samp class="file">.Rd</samp> files, accessed by <code class="code">tools:::fetchRdDB</code>. File <samp class="file">paths.rds</samp> is a saved character vector of the original path names of the <samp class="file">.Rd</samp> files, used when updating the database. </p> <p>File <samp class="file">AnIndex</samp> is a two-column tab-delimited file: the first column contains the aliases defined in the help files and the second the basename (without the <samp class="file">.Rd</samp> or <samp class="file">.rd</samp> extension) of the file containing that alias. It is read by <code class="code">utils:::index.search</code> to search for files matching a topic (alias), and read by <code class="code">scan</code> in <code class="code">utils:::matchAvailableTopics</code>, part of the completion system. </p> <p>File <samp class="file">aliases.rds</samp> is the same information as <samp class="file">AnIndex</samp> as a named character vector (names the topics, values the file basename), for faster access. </p> <hr> </div> </div> <div class="chapter-level-extent" id="Files"> <div class="nav-panel"> <p> Next: <a href="#Graphics-Devices" accesskey="n" rel="next">Graphics</a>, Previous: <a href="#Package-Structure" accesskey="p" rel="prev">Structure of an Installed Package</a>, Up: <a href="#Top" accesskey="u" rel="up">R Internals</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-variable-index" title="Index" rel="index">Index</a>]</p> </div> <h2 class="chapter" id="Files-1"><span>5 Files<a class="copiable-link" href="#Files-1"> ¶</a></span></h2> <p>R provides many functions to work with files and directories: many of these have been added relatively recently to facilitate scripting in R and in particular the replacement of Perl scripts by R scripts in the management of R itself. </p> <p>These functions are implemented by standard C/POSIX library calls, except on Windows. That means that filenames must be encoded in the current locale as the OS provides no other means to access the file system: increasingly filenames are stored in UTF-8 and the OS will translate filenames to UTF-8 in other locales. So using a UTF-8 locale gives transparent access to the whole file system. </p> <p>Windows is another story. There the internal view of filenames is in UTF-16LE (so-called ‘Unicode’), and standard C library calls can only access files whose names can be expressed in the current codepage. To circumvent that restriction, there is a parallel set of Windows-specific calls which take wide-character arguments for filepaths. Much of the file-handling in R has been moved over to using these functions, so filenames can be manipulated in R as UTF-8 encoded character strings, converted to wide characters (which on Windows are UTF-16LE) and passed to the OS. The utilities <code class="code">RC_fopen</code> and <code class="code">filenameToWchar</code> help this process. Currently <code class="code">file.copy</code> to a directory, <code class="code">list.files</code>, <code class="code">list.dirs</code> and <code class="code">path.expand</code> work only with filepaths encoded in the current codepage. </p> <p>All these functions do tilde expansion, in the same way as <code class="code">path.expand</code>, with the deliberate exception of <code class="code">Sys.glob</code>. </p> <p>File names may be case sensitive or not: the latter is the norm on Windows and macOS, the former on other Unix-alikes. Note that this is a property of both the OS and the file system: it is often possible to map names to upper or lower case when mounting the file system. This can affect the matching of patterns in <code class="code">list.files</code> and <code class="code">Sys.glob</code>. </p> <p>File names commonly contain spaces on Windows and macOS but not elsewhere. As file names are handled as character strings by R, spaces are not usually a concern unless file names are passed to other process, e.g. by a <code class="code">system</code> call. </p> <p>Windows has another couple of peculiarities. Whereas a POSIX file system has a single root directory (and other physical file systems are mounted onto logical directories under that root), Windows has separate roots for each physical or logical file system (‘volume’), organized under <em class="emph">drives</em> (with file paths starting <code class="code">D:</code> for an <abbr class="acronym">ASCII</abbr> letter, case-insensitively) and <em class="emph">network shares</em> (with paths like <code class="code">\netname\topdir\myfiles\a file</code>). There is a current drive, and path names without a drive part are relative to the current drive. Further, each drive has a current directory, and relative paths are relative to that current directory, on a particular drive if one is specified. So <samp class="file">D:dir\file</samp> and <samp class="file">D:</samp> are valid path specifications (the last being the current directory on drive <samp class="file">D:</samp>). </p> <hr> </div> <div class="chapter-level-extent" id="Graphics-Devices"> <div class="nav-panel"> <p> Next: <a href="#GUI-consoles" accesskey="n" rel="next">GUI consoles</a>, Previous: <a href="#Files" accesskey="p" rel="prev">Files</a>, Up: <a href="#Top" accesskey="u" rel="up">R Internals</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-variable-index" title="Index" rel="index">Index</a>]</p> </div> <h2 class="chapter" id="Graphics"><span>6 Graphics<a class="copiable-link" href="#Graphics"> ¶</a></span></h2> <p>R’s graphics internals were re-designed to enable multiple graphics systems to be installed on top on the graphics ‘engine’ – currently there are two such systems, one supporting ‘base’ graphics (based on that in S and whose R code<a class="footnote" id="DOCF15" href="#FOOT15"><sup>15</sup></a> is in package <strong class="strong">graphics</strong>) and one implemented in package <strong class="strong">grid</strong>. </p> <p>Some notes on the historical changes can be found at <a class="uref" href="https://www.stat.auckland.ac.nz/~paul/R/basegraph.html">https://www.stat.auckland.ac.nz/~paul/R/basegraph.html</a> and <a class="uref" href="https://www.stat.auckland.ac.nz/~paul/R/graphicsChanges.html">https://www.stat.auckland.ac.nz/~paul/R/graphicsChanges.html</a>. </p> <p>At the lowest level is a graphics device, which manages a plotting surface (a screen window or a representation to be written to a file). This implements a set of graphics primitives, to ‘draw’ </p> <ul class="itemize mark-bullet"> <li>a circle, optionally filled </li><li>a rectangle, optionally filled </li><li>a line </li><li>a set of connected lines </li><li>a polygon, optionally filled </li><li>a paths, optionally filled using a winding rule </li><li>text </li><li>a raster image (optional) </li><li>and to set a clipping rectangle </li></ul> <p>as well as requests for information such as </p> <ul class="itemize mark-bullet"> <li>the width of a string if plotted </li><li>the metrics (width, ascent, descent) of a single character </li><li>the current size of the plotting surface </li></ul> <p>and requests/opportunities to take action such as </p> <ul class="itemize mark-bullet"> <li>start a new ‘page’, possibly after responding to a request to ask the user for confirmation. </li><li>return the position of the device pointer (if any). </li><li>when a device become the current device or stops being the current device (this is usually used to change the window title on a screen device). </li><li>when drawing starts or finishes (e.g. used to flush graphics to the screen when drawing stops). </li><li>wait for an event, for example a mouse click or keypress. </li><li>an ‘onexit’ action, to clean up if plotting is interrupted (by an error or by the user). </li><li>capture the current contents of the device as a raster image. </li><li>close the device. </li></ul> <p>The device also sets a number of variables, mainly Boolean flags indicating its capabilities. Devices work entirely in ‘device units’ which are up to its developer: they can be in pixels, big points (1/72 inch), twips, …, and can differ<a class="footnote" id="DOCF16" href="#FOOT16"><sup>16</sup></a> in the ‘<samp class="samp">x</samp>’ and ‘<samp class="samp">y</samp>’ directions. </p> <p>The next layer up is the graphics ‘engine’ that is the main interface to the device (although the graphics subsystems do talk directly to devices). This is responsible for clipping lines, rectangles and polygons, converting the <code class="code">pch</code> values <code class="code">0...26</code> to sets of lines/circles, centring (and otherwise adjusting) text, rendering mathematical expressions (‘plotmath’) and mapping colour descriptions such as names to the internal representation. </p> <p>Another function of the engine is to manage display lists and snapshots. Some but not all instances of graphics devices maintain display lists, a ‘list’ of operations that have been performed on the device to produce the current plot (since the device was opened or the plot was last cleared, e.g. by <code class="code">plot.new</code>). Screen devices generally maintain a display list to handle repaint and resize events whereas file-based formats do not—display lists are also used to implement <code class="code">dev.copy()</code> and friends. The display list is a pairlist of <code class="code">.Internal</code> (base graphics) or <code class="code">.Call.graphics</code> (grid graphics) calls, which means that the C code implementing a graphics operation will be re-called when the display list is replayed: apart from the part which records the operation if successful. </p> <p>Snapshots of the current graphics state are taken by <code class="code">GEcreateSnapshot</code> and replayed later in the session by <code class="code">GEplaySnapshot</code>. These are used by <code class="code">recordPlot()</code>, <code class="code">replayPlot()</code> and the GUI menus of the <code class="code">windows()</code> device. The ‘state’ includes the display list. </p> <p>The top layer comprises the graphics subsystems. Although there is provision for 24 subsystems since about 2001, currently still only two exist, ‘base’ and ‘grid’. The base subsystem is registered with the engine when R is initialized, and unregistered (via <code class="code">KillAllDevices</code>) when an R session is shut down. The grid subsystem is registered in its <code class="code">.onLoad</code> function and unregistered in the <code class="code">.onUnload</code> function. The graphics subsystem may also have ‘state’ information saved in a snapshot (currently base does and grid does not). </p> <p>Package <strong class="strong">grDevices</strong> was originally created to contain the basic graphics devices (although <code class="code">X11</code> is in a separate load-on-demand module because of the volume of external libraries it brings in). Since then it has been used for other functionality that was thought desirable for use with <strong class="strong">grid</strong>, and hence has been transferred from package <strong class="strong">graphics</strong> to <strong class="strong">grDevices</strong>. This is principally concerned with the handling of colours and recording and replaying plots. </p> <ul class="mini-toc"> <li><a href="#Graphics-devices" accesskey="1">Graphics Devices</a></li> <li><a href="#Colours" accesskey="2">Colours</a></li> <li><a href="#Base-graphics" accesskey="3">Base graphics</a></li> <li><a href="#Grid-graphics" accesskey="4">Grid graphics</a></li> </ul> <hr> <div class="section-level-extent" id="Graphics-devices"> <div class="nav-panel"> <p> Next: <a href="#Colours" accesskey="n" rel="next">Colours</a>, Previous: <a href="#Graphics-Devices" accesskey="p" rel="prev">Graphics</a>, Up: <a href="#Graphics-Devices" accesskey="u" rel="up">Graphics</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-variable-index" title="Index" rel="index">Index</a>]</p> </div> <h3 class="section" id="Graphics-Devices-1"><span>6.1 Graphics Devices<a class="copiable-link" href="#Graphics-Devices-1"> ¶</a></span></h3> <p>R ships with several graphics devices, and there is support for third-party packages to provide additional devices—several packages now do. This section describes the device internals from the viewpoint of a would-be writer of a graphics device. </p> <ul class="mini-toc"> <li><a href="#Device-structures" accesskey="1">Device structures</a></li> <li><a href="#Device-capabilities" accesskey="2">Device capabilities</a></li> <li><a href="#Handling-text" accesskey="3">Handling text</a></li> <li><a href="#Conventions" accesskey="4">Conventions</a></li> <li><a href="#g_t_0027Mode_0027" accesskey="5">‘Mode’</a></li> <li><a href="#Graphics-events" accesskey="6">Graphics events</a></li> <li><a href="#Specific-devices" accesskey="7">Specific devices</a></li> </ul> <hr> <div class="subsection-level-extent" id="Device-structures"> <div class="nav-panel"> <p> Next: <a href="#Device-capabilities" accesskey="n" rel="next">Device capabilities</a>, Previous: <a href="#Graphics-devices" accesskey="p" rel="prev">Graphics Devices</a>, Up: <a href="#Graphics-devices" accesskey="u" rel="up">Graphics Devices</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-variable-index" title="Index" rel="index">Index</a>]</p> </div> <h4 class="subsection" id="Device-structures-1"><span>6.1.1 Device structures<a class="copiable-link" href="#Device-structures-1"> ¶</a></span></h4> <p>There are two types used internally which are pointers to structures related to graphics devices. </p> <p>The <code class="code">DevDesc</code> type is a structure defined in the header file <samp class="file">R_ext/GraphicsDevice.h</samp> (which is included by <samp class="file">R_ext/GraphicsEngine.h</samp>). This describes the physical characteristics of a device, the capabilities of the device driver and contains a set of callback functions that will be used by the graphics engine to obtain information about the device and initiate actions (e.g. a new page, plotting a line or some text). Type <code class="code">pDevDesc</code> is a pointer to this type. </p> <p>The following callbacks can be omitted (or set to the null pointer, their default value) when appropriate default behaviour will be taken by the graphics engine: <code class="code">activate</code>, <code class="code">cap</code>, <code class="code">deactivate</code>, <code class="code">locator</code>, <code class="code">holdflush</code> (API version 9), <code class="code">mode</code>, <code class="code">newFrameConfirm</code>, <code class="code">path</code>, <code class="code">raster</code> and <code class="code">size</code>. </p> <p>The relationship of device units to physical dimensions is set by the element <code class="code">ipr</code> of the <code class="code">DevDesc</code> structure: a ‘<samp class="samp">double</samp>’ array of length 2. </p> <p>The <code class="code">GEDevDesc</code> type is a structure defined in <samp class="file">R_ext/GraphicsEngine.h</samp> (with comments in the file) as </p> <div class="example"> <pre class="example-preformatted">typedef struct _GEDevDesc GEDevDesc; struct _GEDevDesc { pDevDesc dev; Rboolean displayListOn; SEXP displayList; SEXP DLlastElt; SEXP savedSnapshot; Rboolean dirty; Rboolean recordGraphics; GESystemDesc *gesd[MAX_GRAPHICS_SYSTEMS]; Rboolean ask; } </pre></div> <p>So this is essentially a device structure plus information about the device maintained by the graphics engine and normally<a class="footnote" id="DOCF17" href="#FOOT17"><sup>17</sup></a> visible to the engine and not to the device. Type <code class="code">pGEDevDesc</code> is a pointer to this type. </p> <p>The graphics engine maintains an array of devices, as pointers to <code class="code">GEDevDesc</code> structures. The array is of size 64 but the first element is always occupied by the <code class="code">"null device"</code> and the final element is kept as NULL as a sentinel.<a class="footnote" id="DOCF18" href="#FOOT18"><sup>18</sup></a> This array is reflected in the R variable ‘<samp class="samp">.Devices</samp>’. Once a device is killed its element becomes available for reallocation (and its name will appear as <code class="code">""</code> in ‘<samp class="samp">.Devices</samp>’). Exactly one of the devices is ‘active’: this is the the null device if no other device has been opened and not killed. </p> <p>Each instance of a graphics device needs to set up a <code class="code">GEDevDesc</code> structure by code very similar to </p> <div class="example"> <pre class="example-preformatted"> pGEDevDesc gdd; R_GE_checkVersionOrDie(R_GE_version); R_CheckDeviceAvailable(); BEGIN_SUSPEND_INTERRUPTS { pDevDesc dev; /* Allocate and initialize the device driver data */ if (!(dev = (pDevDesc) calloc(1, sizeof(DevDesc)))) return 0; /* or error() */ /* set up device driver or free ‘dev’ and error() */ gdd = GEcreateDevDesc(dev); GEaddDevice2(gdd, "dev_name"); } END_SUSPEND_INTERRUPTS; </pre></div> <p>The <code class="code">DevDesc</code> structure contains a <code class="code">void *</code> pointer ‘<samp class="samp">deviceSpecific</samp>’ which is used to store data specific to the device. Setting up the device driver includes initializing all the non-zero elements of the <code class="code">DevDesc</code> structure. </p> <p>Note that the device structure is zeroed when allocated: this provides some protection against future expansion of the structure since the graphics engine can add elements that need to be non-NULL/non-zero to be ‘on’ (and the structure ends with 64 reserved bytes which will be zeroed and allow for future expansion). </p> <p>Rather more protection is provided by the version number of the engine/device API, <code class="code">R_GE_version</code> defined in <samp class="file">R_ext/GraphicsEngine.h</samp> together with access functions </p> <div class="example"> <pre class="example-preformatted">int R_GE_getVersion(void); void R_GE_checkVersionOrDie(int version); </pre></div> <p>If a graphics device calls <code class="code">R_GE_checkVersionOrDie(R_GE_version)</code> it can ensure it will only be used in versions of R which provide the API it was designed for and compiled against. </p> <p>The <code class="code">DevDesc</code> structure also contains an <code class="code">int</code> ‘<samp class="samp">deviceVersion</samp>’ to indicate which version of the engine/device API that the device supports. If the device driver sets this correctly, there is no need for a device driver to use <code class="code">R_GE_checkVersionOrDie(R_GE_version)</code> because the graphics engine will not make use of callbacks from an API version above the version that is supported by the device. </p> <hr> </div> <div class="subsection-level-extent" id="Device-capabilities"> <div class="nav-panel"> <p> Next: <a href="#Handling-text" accesskey="n" rel="next">Handling text</a>, Previous: <a href="#Device-structures" accesskey="p" rel="prev">Device structures</a>, Up: <a href="#Graphics-devices" accesskey="u" rel="up">Graphics Devices</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-variable-index" title="Index" rel="index">Index</a>]</p> </div> <h4 class="subsection" id="Device-capabilities-1"><span>6.1.2 Device capabilities<a class="copiable-link" href="#Device-capabilities-1"> ¶</a></span></h4> <p>The following ‘capabilities’ can be defined for the device’s <code class="code">DevDesc</code> structure. </p> <ul class="itemize mark-bullet"> <li><code class="code">canChangeGamma</code> – <code class="code">Rboolean</code>: can the display gamma be adjusted? This is now ignored, as gamma support has been removed. </li><li><code class="code">canHadj</code> – <code class="code">integer</code>: can the device do horizontal adjustment of text <em class="emph">via</em> the <code class="code">text</code> callback, and if so, how precisely? 0 = no adjustment, 1 = {0, 0.5, 1} (left, centre, right justification) or 2 = continuously variable (in [0,1]) between left and right justification. </li><li><code class="code">canGenMouseDown</code> – <code class="code">Rboolean</code>: can the device handle mouse down events? This flag and the next three are not currently used by R, but are maintained for back compatibility. </li><li><code class="code">canGenMouseMove</code> – <code class="code">Rboolean</code>: ditto for mouse move events. </li><li><code class="code">canGenMouseUp</code> – <code class="code">Rboolean</code>: ditto for mouse up events. </li><li><code class="code">canGenKeybd</code> – <code class="code">Rboolean</code>: ditto for keyboard events. </li><li><code class="code">hasTextUTF8</code> – <code class="code">Rboolean</code>: should non-symbol text be sent (in UTF-8) to the <code class="code">textUTF8</code> and <code class="code">strWidthUTF8</code> callbacks, and sent as Unicode points (negative values) to the <code class="code">metricInfo</code> callback? </li><li><code class="code">wantSymbolUTF8</code> – <code class="code">Rboolean</code>: should symbol text be handled in UTF-8 in the same way as other text? Requires <code class="code">textUTF8 = TRUE</code>. </li><li><code class="code">haveTransparency</code>: does the device support semi-transparent colours? </li><li><code class="code">haveTransparentBg</code>: can the background be fully or semi-transparent? </li><li><code class="code">haveRaster</code>: is there support for rendering raster images? </li><li><code class="code">haveCapture</code>: is there support for <code class="code">grid::grid.cap</code>? </li><li><code class="code">haveLocator</code>: is there an interactive locator? </li><li><code class="code">deviceClip</code>: should the engine leave <em class="emph">all</em> clipping to the device? </li></ul> <p><code class="code">haveRaster</code>, <code class="code">haveCapture</code>, and <code class="code">haveLocator</code> can often be deduced to be false from the presence of <code class="code">NULL</code> entries instead of the corresponding functions. </p> <p>In addition, the <code class="code">capabilities</code> callback allows the device driver to provide more detailed information, especially related to callbacks in the engine/device API version 13 or higher. </p> <p>The <code class="code">capabilities</code> callback is called with a list of integer vectors that represent the best guess that the graphics engine can make, based on the flags in the <code class="code">DevDesc</code> structure and the ‘<samp class="samp">deviceVersion</samp>’. For some capabilities, the integer vector is length 1 with <code class="code">0</code> for no support, <code class="code">1</code> for support, or <code class="code">NA</code> for unknown support. For capabilities where support can be more nuanced, the integer vector may either take higher values or it may have length greater than 1, though length 1 and <code class="code">0</code> still means no support and <code class="code">NA</code> still means unknown support. </p> <p>The following components of this list are likely to need modifying (for these, the graphics engine can only guess <code class="code">0</code> if ‘<samp class="samp">deviceVersion</samp>’ is too low or <code class="code">NA</code> otherwise): </p> <ul class="itemize mark-bullet"> <li>The <code class="code">patterns</code> component reports what sort of pattern fills are supported. If the device supports one or more pattern types, this component should be replaced with an integer vector containing a value for each supported pattern type; the graphics engine provides constants <code class="code">R_GE_linearGradientPattern</code>, <code class="code">R_GE_radialGradientPattern</code>, and <code class="code">R_GE_tilingPattern</code>. If the device does not provide support, this component should be set to 0. </li><li>The <code class="code">clippingPaths</code> component reports whether arbitrary clipping paths are supported. If the device supports clipping paths, this component should be set to 1. If the device does not provide support, this component should be set to 0. </li><li>The <code class="code">masks</code> component reports what sort of masks are supported. If the device supports one or more mask types, this component should be replaced with an integer vector containing a value for each supported mask type; the graphics engine provides constants <code class="code">R_GE_alphaMask</code> and <code class="code">R_GE_luminanceMask</code>. If the device does not provide support, this component should be set to 0. </li><li>The <code class="code">compositing</code> component reports which compositing operators are supported. If the device supports one or more compositing operators, this component should be replaced with an integer vector containing a value for each supported operator; The list of possible operators is long, encompassing Porter-Duff operators and Adobe PDF Blend Modes; the graphics engine provides constants <code class="code">R_GE_compositeClear</code>, etc. If the device does not provide support, this component should be set to 0. </li><li>The <code class="code">transformations</code> component reports whether affine transformations are supported. If the device supports transformations, this component should be set to 1. If the device does not provide support, this component should be set to 0. </li><li>The <code class="code">paths</code> component reports whether stroking and filling of paths composed of multiple shapes is supported. If the device supports stroking and filling paths, this component should be set to 1. If the device does not provide support, this component should be set to 0. </li><li>The <code class="code">glyphs</code> component reports whether rendering glyphs (e.g., via <code class="code">grid::grid.glyph()</code>) is supported. If the device supports rendering glyphs, this component should be set to 1. If the device does not provide support, this component should be set to 0. </li></ul> <p>The graphics engine provides constants like <code class="code">R_GE_capability_patterns</code> for selecting the appropriate component of the list of capabilities. </p> <p>It is valid (if unhelpful) for the device driver to return the list of capabilities unaltered. </p> <hr> </div> <div class="subsection-level-extent" id="Handling-text"> <div class="nav-panel"> <p> Next: <a href="#Conventions" accesskey="n" rel="next">Conventions</a>, Previous: <a href="#Device-capabilities" accesskey="p" rel="prev">Device capabilities</a>, Up: <a href="#Graphics-devices" accesskey="u" rel="up">Graphics Devices</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-variable-index" title="Index" rel="index">Index</a>]</p> </div> <h4 class="subsection" id="Handling-text-1"><span>6.1.3 Handling text<a class="copiable-link" href="#Handling-text-1"> ¶</a></span></h4> <p>Handling text is probably the hardest task for a graphics device, and the design allows for the device to optionally indicate that it has additional capabilities. (If the device does not, these will if possible be handled in the graphics engine.) </p> <p>The three callbacks for handling text that must be in all graphics devices are <code class="code">text</code>, <code class="code">strWidth</code> and <code class="code">metricInfo</code> with declarations </p> <div class="example"> <pre class="example-preformatted">void text(double x, double y, const char *str, double rot, double hadj, pGgcontext gc, pDevDesc dd); double strWidth(const char *str, pGEcontext gc, pDevDesc dd); void metricInfo(int c, pGEcontext gc, double* ascent, double* descent, double* width, pDevDesc dd); </pre></div> <p>The ‘<samp class="samp">gc</samp>’ parameter provides the graphics context, most importantly the current font and font size, and ‘<samp class="samp">dd</samp>’ is a pointer to the active device’s structure. </p> <p>The <code class="code">text</code> callback should plot ‘<samp class="samp">str</samp>’ at ‘<samp class="samp">(x, y)</samp>’<a class="footnote" id="DOCF19" href="#FOOT19"><sup>19</sup></a> with an anti-clockwise rotation of ‘<samp class="samp">rot</samp>’ degrees. (For ‘<samp class="samp">hadj</samp>’ see below.) The interpretation for horizontal text is that the baseline is at <code class="code">y</code> and the start is a <code class="code">x</code>, so any left bearing for the first character will start at <code class="code">x</code>. </p> <p>The <code class="code">strWidth</code> callback computes the width of the string which it would occupy if plotted horizontally in the current font. (Width here is expected to include both (preferably) or neither of left and right bearings.) </p> <p>The <code class="code">metricInfo</code> callback computes the size of a single character: <code class="code">ascent</code> is the distance it extends above the baseline and <code class="code">descent</code> how far it extends below the baseline. <code class="code">width</code> is the amount by which the cursor should be advanced when the character is placed. For <code class="code">ascent</code> and <code class="code">descent</code> this is intended to be the bounding box of the ‘ink’ put down by the glyph and not the box which might be used when assembling a line of conventional text (it needs to be for e.g. <code class="code">hat(beta)</code> to work correctly). However, the <code class="code">width</code> is used in plotmath to advance to the next character, and so needs to include left and right bearings. </p> <p>The <em class="emph">interpretation</em> of ‘<samp class="samp">c</samp>’ depends on the locale. In a single-byte locale values <code class="code">32...255</code> indicate the corresponding character in the locale (if present). For the symbol font (as used by ‘<samp class="samp">graphics::par(font=5)</samp>’, ‘<samp class="samp">grid::gpar(fontface=5</samp>’) and by ‘plotmath’), values <code class="code">32...126, 161...239, 241...254</code> indicate glyphs in the Adobe Symbol encoding. In a multibyte locale, <code class="code">c</code> represents a Unicode point (except in the symbol font). So the function needs to include code like </p> <div class="example"> <pre class="example-preformatted"> Rboolean Unicode = mbcslocale && (gc->fontface != 5); if (c < 0) { Unicode = TRUE; c = -c; } if(Unicode) UniCharMetric(c, ...); else CharMetric(c, ...); </pre></div> <p>In addition, if device capability <code class="code">hasTextUTF8</code> (see below) is true, Unicode points will be passed as negative values: the code snippet above shows how to handle this. (This applies to the symbol font only if device capability <code class="code">wantSymbolUTF8</code> is true.) </p> <p>If possible, the graphics device should handle clipping of text. It indicates this by the structure element <code class="code">canClip</code> which if true will result in calls to the callback <code class="code">clip</code> to set the clipping region. If this is not done, the engine will clip very crudely (by omitting any text that does not appear to be wholly inside the clipping region). </p> <p>The device structure has an integer element <code class="code">canHadj</code>, which indicates if the device can do horizontal alignment of text. If this is one, argument ‘<samp class="samp">hadj</samp>’ to <code class="code">text</code> will be called as <code class="code">0 ,0.5, 1</code> to indicate left-, centre- and right-alignment at the indicated position. If it is two, continuous values in the range <code class="code">[0, 1]</code> are assumed to be supported. </p> <p>Capability <code class="code">hasTextUTF8</code> if true, it has two consequences. First, there are callbacks <code class="code">textUTF8</code> and <code class="code">strWidthUTF8</code> that should behave identically to <code class="code">text</code> and <code class="code">strWidth</code> except that ‘<samp class="samp">str</samp>’ is assumed to be in UTF-8 rather than the current locale’s encoding. The graphics engine will call these for all text except in the symbol font. Second, Unicode points will be passed to the <code class="code">metricInfo</code> callback as negative integers. If your device would prefer to have UTF-8-encoded symbols, define <code class="code">wantSymbolUTF8</code> as well as <code class="code">hasTextUTF8</code>. In that case text in the symbol font is sent to <code class="code">textUTF8</code> and <code class="code">strWidthUTF8</code>. </p> <p>Some devices can produce high-quality rotated text, but those based on bitmaps often cannot. Those which can should set <code class="code">useRotatedTextInContour</code> to be true from graphics API version 4. </p> <p>Several other elements relate to the precise placement of text by the graphics engine: </p> <div class="example"> <pre class="example-preformatted">double xCharOffset; double yCharOffset; double yLineBias; double cra[2]; </pre></div> <p>These are more than a little mysterious. Element <code class="code">cra</code> provides an indication of the character size, <code class="code">par("cra")</code> in base graphics, in device units. The mystery is what is meant by ‘character size’: which character, which font at which size? Some help can be obtained by looking at what this is used for. The first element, ‘width’, is not used by R except to set the graphical parameters. The second, ‘height’, is use to set the line spacing, that is the relationship between <code class="code">par("mar")</code> and <code class="code">par("mai")</code> and so on. It is suggested that a good choice is </p> <div class="example"> <pre class="example-preformatted">dd->cra[0] = 0.9 * fnsize; dd->cra[1] = 1.2 * fnsize; </pre></div> <p>where ‘<samp class="samp">fnsize</samp>’ is the ‘size’ of the standard font (<code class="code">cex=1</code>) on the device, in device units. So for a 12-point font (the usual default for graphics devices), ‘<samp class="samp">fnsize</samp>’ should be 12 points in device units. </p> <p>The remaining elements are yet more mysterious. The <code class="code">postscript()</code> device says </p> <div class="example"> <pre class="example-preformatted"> /* Character Addressing Offsets */ /* These offsets should center a single */ /* plotting character over the plotting point. */ /* Pure guesswork and eyeballing ... */ dd->xCharOffset = 0.4900; dd->yCharOffset = 0.3333; dd->yLineBias = 0.2; </pre></div> <p>It seems that <code class="code">xCharOffset</code> is not currently used, and <code class="code">yCharOffset</code> is used by the base graphics system to set vertical alignment in <code class="code">text()</code> when <code class="code">pos</code> is specified, and in <code class="code">identify()</code>. It is occasionally used by the graphic engine when attempting exact centring of text, such as character string values of <code class="code">pch</code> in <code class="code">points()</code> or <code class="code">grid.points()</code>—however, it is only used when precise character metric information is not available or for multi-line strings. </p> <p><code class="code">yLineBias</code> is used in the base graphics system in <code class="code">axis()</code> and <code class="code">mtext()</code> to provide a default for their ‘<samp class="samp">padj</samp>’ argument. </p> <p>From <code class="code">R_GE_version</code> 16 (<code class="code">R_GE_glyphs</code>), there is also a <code class="code">glyph</code> callback. </p> <div class="example"> <pre class="example-preformatted"> void glyph(int n, int *glyphs, double *x, double *y, SEXP font, double size, int colour, double rot, pDevDesc dd); </pre></div> <p>This instructs the device to draw a specific glyph within a given font, where the font is specified by filename (and index), with font family, weight, and style also provided as fallbacks. </p> <hr> </div> <div class="subsection-level-extent" id="Conventions"> <div class="nav-panel"> <p> Next: <a href="#g_t_0027Mode_0027" accesskey="n" rel="next">‘Mode’</a>, Previous: <a href="#Handling-text" accesskey="p" rel="prev">Handling text</a>, Up: <a href="#Graphics-devices" accesskey="u" rel="up">Graphics Devices</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-variable-index" title="Index" rel="index">Index</a>]</p> </div> <h4 class="subsection" id="Conventions-1"><span>6.1.4 Conventions<a class="copiable-link" href="#Conventions-1"> ¶</a></span></h4> <p>The aim is to make the (default) output from graphics devices as similar as possible. Generally people follow the model of the <code class="code">postscript</code> and <code class="code">pdf</code> devices (which share most of their internal code). </p> <p>The following conventions have become established: </p> <ul class="itemize mark-bullet"> <li>The default size of a device should be 7 inches square. </li><li>There should be a ‘<samp class="samp">pointsize</samp>’ argument which defaults to 12, and it should give the pointsize in big points (1/72 inch). How exactly this is interpreted is font-specific, but it should use a font which works with lines packed 1/6 inch apart, and looks good with lines 1/5 inch apart (that is with 2pt leading). </li><li>The default font family should be a sans serif font, e.g Helvetica or similar (e.g. Arial on Windows). </li><li><code class="code">lwd = 1</code> should correspond to a line width of 1/96 inch. This will be a problem with pixel-based devices, and generally there is a minimum line width of 1 pixel (although this may not be appropriate where anti-aliasing of lines is used, and <code class="code">cairo</code> prefers a minimum of 2 pixels). </li><li>Even very small circles should be visible, e.g. by using a minimum radius of 1 pixel or replacing very small circles by a single filled pixel. </li><li>How RGB colour values will be interpreted should be documented, and preferably be <abbr class="abbr">sRGB</abbr>. </li><li>The help page should describe its policy on these conventions. </li></ul> <p>These conventions are less clear-cut for bitmap devices, especially where the bitmap format does not have a design resolution. </p> <p>The interpretation of the line texture (<code class="code">par("lty"</code>) is described in the header <samp class="file">GraphicsEngine.h</samp> and in the help for <code class="code">par</code>: note that the ‘scale’ of the pattern should be proportional to the line width (at least for widths above the default). </p> <hr> </div> <div class="subsection-level-extent" id="g_t_0027Mode_0027"> <div class="nav-panel"> <p> Next: <a href="#Graphics-events" accesskey="n" rel="next">Graphics events</a>, Previous: <a href="#Conventions" accesskey="p" rel="prev">Conventions</a>, Up: <a href="#Graphics-devices" accesskey="u" rel="up">Graphics Devices</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-variable-index" title="Index" rel="index">Index</a>]</p> </div> <h4 class="subsection" id="g_t_0060Mode_0027"><span>6.1.5 ‘Mode’<a class="copiable-link" href="#g_t_0060Mode_0027"> ¶</a></span></h4> <p>One of the device callbacks is a function <code class="code">mode</code>, documented in the header as </p> <div class="example"> <pre class="example-preformatted"> * device_Mode is called whenever the graphics engine * starts drawing (mode=1) or stops drawing (mode=0) * GMode (in graphics.c) also says that * mode = 2 (graphical input on) exists. * The device is not required to do anything </pre></div> <p>Since <code class="code">mode = 2</code> has only recently been documented at device level. It could be used to change the graphics cursor, but devices currently do that in the <code class="code">locator</code> callback. (In base graphics the mode is set for the duration of a <code class="code">locator</code> call, but if <code class="code">type != "n"</code> is switched back for each point whilst annotation is being done.) </p> <p>Many devices do indeed do nothing on this call, but some screen devices ensure that drawing is flushed to the screen when called with <code class="code">mode = 0</code>. It is tempting to use it for some sort of buffering, but note that ‘drawing’ is interpreted at quite a low level and a typical single figure will stop and start drawing many times. The buffering introduced in the <code class="code">X11()</code> device makes use of <code class="code">mode = 0</code> to indicate activity: it updates the screen after <em class="emph">ca</em> 100ms of inactivity. </p> <p>This callback need not be supplied if it does nothing. </p> <hr> </div> <div class="subsection-level-extent" id="Graphics-events"> <div class="nav-panel"> <p> Next: <a href="#Specific-devices" accesskey="n" rel="next">Specific devices</a>, Previous: <a href="#g_t_0027Mode_0027" accesskey="p" rel="prev">‘Mode’</a>, Up: <a href="#Graphics-devices" accesskey="u" rel="up">Graphics Devices</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-variable-index" title="Index" rel="index">Index</a>]</p> </div> <h4 class="subsection" id="Graphics-events-1"><span>6.1.6 Graphics events<a class="copiable-link" href="#Graphics-events-1"> ¶</a></span></h4> <p>Graphics devices may be designed to handle user interaction: not all are. </p> <p>Users may use <code class="code">grDevices::setGraphicsEventEnv</code> to set the <code class="code">eventEnv</code> environment in the device driver to hold event handlers. When the user calls <code class="code">grDevices::getGraphicsEvent</code>, R will take three steps. First, it sets the device driver member <code class="code">gettingEvent</code> to <code class="code">true</code> for each device with a non-<code class="code">NULL</code> <code class="code">eventEnv</code> entry, and calls <code class="code">initEvent(dd, true)</code> if the callback is defined. It then enters an event loop. Each time through the loop R will process events once, then check whether any device has set the <code class="code">result</code> member of <code class="code">eventEnv</code> to a non-<code class="code">NULL</code> value, and will save the first such value found to be returned. C functions <code class="code">doMouseEvent</code> and <code class="code">doKeybd</code> are provided to call the R event handlers <code class="code">onMouseDown</code>, <code class="code">onMouseMove</code>, <code class="code">onMouseUp</code>, and <code class="code">onKeybd</code> and set <code class="code">eventEnv$result</code> during this step. Finally, <code class="code">initEvent</code> is called again with <code class="code">init=false</code> to inform the devices that the loop is done, and the result is returned to the user. </p> <hr> </div> <div class="subsection-level-extent" id="Specific-devices"> <div class="nav-panel"> <p> Previous: <a href="#Graphics-events" accesskey="p" rel="prev">Graphics events</a>, Up: <a href="#Graphics-devices" accesskey="u" rel="up">Graphics Devices</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-variable-index" title="Index" rel="index">Index</a>]</p> </div> <h4 class="subsection" id="Specific-devices-1"><span>6.1.7 Specific devices<a class="copiable-link" href="#Specific-devices-1"> ¶</a></span></h4> <p>Specific devices are mostly documented by comments in their sources, although for devices of many years’ standing those comments can be in need of updating. This subsection is a repository of notes on design decisions. </p> <ul class="mini-toc"> <li><a href="#X11_0028_0029" accesskey="1">X11()</a></li> <li><a href="#windows_0028_0029" accesskey="2">windows()</a></li> </ul> <hr> <div class="subsubsection-level-extent" id="X11_0028_0029"> <div class="nav-panel"> <p> Next: <a href="#windows_0028_0029" accesskey="n" rel="next">windows()</a>, Previous: <a href="#Specific-devices" accesskey="p" rel="prev">Specific devices</a>, Up: <a href="#Specific-devices" accesskey="u" rel="up">Specific devices</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-variable-index" title="Index" rel="index">Index</a>]</p> </div> <h4 class="subsubsection" id="X11_0028_0029-1"><span>6.1.7.1 X11()<a class="copiable-link" href="#X11_0028_0029-1"> ¶</a></span></h4> <p>The <code class="code">X11(type="Xlib")</code> device dates back to the mid 1990’s and was written then in <code class="code">Xlib</code>, the most basic X11 toolkit. It has since optionally made use of a few features from other toolkits: <code class="code">libXt</code> is used to read X11 resources, and <code class="code">libXmu</code> is used in the handling of clipboard selections. </p> <p>Using basic <code class="code">Xlib</code> code makes drawing fast, but is limiting. There is no support of translucent colours (that came in the <code class="code">Xrender</code> toolkit of 2000) nor for rotated text (which R implements by rendering text to a bitmap and rotating the latter). </p> <p>The hinting for the X11 window asks for backing store to be used, and some windows managers may use it to handle repaints, but it seems that most repainting is done by replaying the display list (and here the fast drawing is very helpful). </p> <p>There are perennial problems with finding fonts. Many users fail to realize that fonts are a function of the X server and not of the machine that R is running on. After many difficulties, R tries first to find the nearest size match in the sizes provided for Adobe fonts in the standard 75dpi and 100dpi X11 font packages—even that will fail to work when users of near-100dpi screens have only the 75dpi set installed. The 75dpi set allows sizes down to 6 points on a 100dpi screen, but some users do try to use smaller sizes and even 6 and 8 point bitmapped fonts do not look good. </p> <p>Introduction of UTF-8 locales has caused another wave of difficulties. X11 has very few genuine UTF-8 fonts, and produces composite fontsets for the <code class="code">iso10646-1</code> encoding. Unfortunately these seem to have low coverage apart from a few monospaced fonts in a few sizes (which are not suitable for graph annotation), and where glyphs are missing what is plotted is often quite unsatisfactory. </p> <p>The current approach is to make use of more modern toolkits, namely <code class="code">cairo</code> for rendering and <code class="code">Pango</code> for font management—because these are associated with <code class="code">Gtk+2</code> they are widely available. Cairo supports translucent colours and alpha-blending (<em class="emph">via</em> <code class="code">Xrender</code>), and anti-aliasing for the display of lines and text. Pango’s font management is based on <code class="code">fontconfig</code> and somewhat mysterious, but it seems mainly to use Type 1 and TrueType fonts on the machine running R and send grayscale bitmaps to cairo. </p> <hr> </div> <div class="subsubsection-level-extent" id="windows_0028_0029"> <div class="nav-panel"> <p> Previous: <a href="#X11_0028_0029" accesskey="p" rel="prev">X11()</a>, Up: <a href="#Specific-devices" accesskey="u" rel="up">Specific devices</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-variable-index" title="Index" rel="index">Index</a>]</p> </div> <h4 class="subsubsection" id="windows_0028_0029-1"><span>6.1.7.2 windows()<a class="copiable-link" href="#windows_0028_0029-1"> ¶</a></span></h4> <p>The <code class="code">windows()</code> device is a family of devices: it supports plotting to Windows (enhanced) metafiles, BMP, JPEG, PNG and TIFF files as well as to Windows printers. </p> <p>In most of these cases the primary plotting is to a bitmap: this is used for the (default) buffering of the screen device, which also enables the current plot to be saved to BMP, JPEG, PNG or TIFF (it is the internal bitmap which is copied to the file in the appropriate format). </p> <p>The device units are pixels (logical ones on a metafile device). </p> <p>The code was originally written by Guido Masarotto with extensive use of macros, which can make it hard to disentangle. </p> <p>For a screen device, <code class="code">xd->gawin</code> is the canvas of the screen, and <code class="code">xd->bm</code> is the off-screen bitmap. So macro <code class="code">DRAW</code> arranges to plot to <code class="code">xd->bm</code>, and if buffering is off, also to <code class="code">xd->gawin</code>. For all other device, <code class="code">xd->gawin</code> is the canvas, a bitmap for the <code class="code">jpeg()</code> and <code class="code">png()</code> device, and an internal representation of a Windows metafile for the <code class="code">win.metafile()</code> and <code class="code">win.print</code> device. Since ‘plotting’ is done by Windows <abbr class="abbr">GDI</abbr> calls to the appropriate canvas, its precise nature is hidden by the <abbr class="abbr">GDI</abbr> system. </p> <p>Buffering on the screen device is achieved by running a timer, which when it fires copies the internal bitmap to the screen. This is set to fire every 500ms (by default) and is reset to 100ms after plotting activity. </p> <p>Repaint events are handled by copying the internal bitmap to the screen canvas (and then reinitializing the timer), unless there has been a resize. Resizes are handled by replaying the display list: this might not be necessary if a fixed canvas with scrollbars is being used, but that is the least popular of the three forms of resizing. </p> <p>Text on the device has moved to ‘Unicode’ (UCS-2) in recent years. UTF-8 is requested (<code class="code">hasTextUTF8 = TRUE</code>) for standard text, and converted to UCS-2 in the plotting functions in file <samp class="file">src/extra/graphapp/gdraw.c</samp>. However, <abbr class="abbr">GDI</abbr> has no support for Unicode symbol fonts, and symbols are handled in Adobe Symbol encoding. </p> <p>There is support for translucent colours (with alpha channel between 0 and 255) was introduced on the screen device and bitmap devices.<a class="footnote" id="DOCF20" href="#FOOT20"><sup>20</sup></a> This is done by drawing on a further internal bitmap, <code class="code">xd->bm2</code>, in the opaque version of the colour then alpha-blending that bitmap to <code class="code">xd->bm</code>. The alpha-blending routine is in a separate DLL, <samp class="file">msimg32.dll</samp>, which is loaded on first use. As small a rectangular region as reasonably possible is alpha-blended (this is rectangle <code class="code">r</code> in the code), but things like mitre joins make estimation of a tight bounding box too much work for lines and polygonal boundaries. Translucent-coloured lines are not common, and the performance seems acceptable. </p> <p>The support for a transparent background in <code class="code">png()</code> predates full alpha-channel support in <code class="code">libpng</code> (let alone in PNG viewers), so makes use of the limited transparency support in earlier versions of PNG. Where 24-bit colour is used, this is done by marking a single colour to be rendered as transparent. R chose ‘<samp class="samp">#fdfefd</samp>’, and uses this as the background colour (in <code class="code">GA_NewPage</code> if the specified background colour is transparent (and all non-opaque background colours are treated as transparent). So this works by marking that colour in the PNG file, and viewers without transparency support see a slightly-off-white background, as if there were a near-white canvas. Where a palette is used in the PNG file (if less than 256 colours were used) then this colour is recorded with full transparency and the remaining colours as opaque. If 32-bit colour were available then we could add a full alpha channel, but this is dependent on the graphics hardware and undocumented properties of <abbr class="abbr">GDI</abbr>. </p> <hr> </div> </div> </div> <div class="section-level-extent" id="Colours"> <div class="nav-panel"> <p> Next: <a href="#Base-graphics" accesskey="n" rel="next">Base graphics</a>, Previous: <a href="#Graphics-devices" accesskey="p" rel="prev">Graphics Devices</a>, Up: <a href="#Graphics-Devices" accesskey="u" rel="up">Graphics</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-variable-index" title="Index" rel="index">Index</a>]</p> </div> <h3 class="section" id="Colours-1"><span>6.2 Colours<a class="copiable-link" href="#Colours-1"> ¶</a></span></h3> <p>Devices receive colours as a <code class="code">typedef</code> <code class="code">rcolor</code> (an <code class="code">unsigned int</code>) defined in the header <samp class="file">R_ext/GraphicsEngine.h</samp>). The 4 bytes are <em class="emph">R</em> ,<em class="emph">G</em>, <em class="emph">B</em> and <em class="emph">alpha</em> from least to most significant. So each of RGB has 256 levels of luminosity from 0 to 255. The alpha byte represents opacity, so value 255 is fully opaque and 0 fully transparent: many but not all devices handle semi-transparent colours. </p> <p>Colors can be created in C via the macro <code class="code">R_RGBA</code>, and a set of macros are defined in <samp class="file">R_ext/GraphicsDevice.h</samp> to extract the various components. </p> <p>Colours in the base graphics system were originally adopted from S (and before that the GRZ library from Bell Labs), with the concept of a (variable-sized) palette of colours referenced by numbers ‘<samp class="samp">1...<var class="var">N</var></samp>’ plus ‘<samp class="samp">0</samp>’ (the background colour of the current device). R introduced the idea of referring to colours by character strings, either in the forms ‘<samp class="samp">#RRGGBB</samp>’ or ‘<samp class="samp">#RRGGBBAA</samp>’ (representing the bytes in hex) as given by function <code class="code">rgb()</code> or via names: the 657 known names are given in the character vector <code class="code">colors</code> and in a table in file <samp class="file">colors.c</samp> in package <strong class="strong">grDevices</strong>. Note that semi-transparent colours are not ‘premultiplied’, so 50% transparent white is ‘<samp class="samp">#ffffff80</samp>’. </p> <p>Integer or character <code class="code">NA</code> colours are mapped internally to transparent white, as is the character string <code class="code">"NA"</code>. </p> <p>Negative colour numbers are an error. Colours greater than ‘<samp class="samp"><var class="var">N</var></samp>’ are wrapped around, so that for example with the default palette of size 8, colour ‘<samp class="samp">10</samp>’ is colour ‘<samp class="samp">2</samp>’ in the palette. </p> <p>Integer colours have been used more widely than the base graphics sub-system, as they are supported by package <strong class="strong">grid</strong> and hence by <a class="url" href="https://CRAN.R-project.org/package=lattice"><strong class="strong">lattice</strong></a> and <a class="url" href="https://CRAN.R-project.org/package=ggplot2"><strong class="strong">ggplot2</strong></a>. (They are also used by package <a class="url" href="https://CRAN.R-project.org/package=rgl"><strong class="strong">rgl</strong></a>.) <strong class="strong">grid</strong> did re-define colour ‘<samp class="samp">0</samp>’ to be transparent white, but <a class="url" href="https://CRAN.R-project.org/package=rgl"><strong class="strong">rgl</strong></a> used <code class="code">col2rgb</code> and hence the background colour of base graphics. </p> <p>Note that positive integer colours refer to the current palette and colour ‘<samp class="samp">0</samp>’ to the current device (and a device is opened if needs be). These are mapped to type <code class="code">rcolor</code> at the time of use: this matters when re-playing the display list, e.g. when a device is resized or <code class="code">dev.copy</code> is used. The palette should be thought of as per-session: it is stored in package <strong class="strong">grDevices</strong>. </p> <p>The convention is that devices use the colorspace ‘<abbr class="abbr">sRGB</abbr>’. This is an industry standard: it is used by Web browsers and <abbr class="abbr">JPEG</abbr>s from all but high-end digital cameras. The interpretation is a matter for graphics devices and for code that manipulates colours, but not for the graphics engine or subsystems. </p> <p>R uses a painting model similar to PostScript and PDF. This means that where shapes (circles, rectangles and polygons) can both be filled and have a stroked border, the fill should be painted first and then the border (or otherwise only half the border will be visible). Where both the fill and the border are semi-transparent there is some room for interpretation of the intention. Most devices first paint the fill and then the border, alpha-blending at each step. However, PDF does some automatic grouping of objects, and <em class="emph">when the fill and the border have the same alpha</em>, they are painted onto the same layer and then alpha-blended in one step. (See p. 569 of the PDF Reference Sixth Edition, version 1.7. Unfortunately, although this is what the PDF standard says should happen, it is not correctly implemented by some viewers.) </p> <p>The mapping from colour numbers to type <code class="code">rcolor</code> is primarily done by function <code class="code">RGBpar3</code>: this is exported from the R binary but linked to code in package <strong class="strong">grDevices</strong>. The first argument is a <code class="code">SEXP</code> pointing to a character, integer or double vector, and the second is the <code class="code">rcolor</code> value for colour <code class="code">0</code> (or <code class="code">"0"</code>). C entry point <code class="code">RGBpar</code> is a wrapper that takes <code class="code">0</code> to be transparent white: it is often used to set colour defaults for devices. The R-level wrapper is <code class="code">col2rgb</code>. </p> <p>There is also <code class="code">R_GE_str2col</code> which takes a C string and converts to type <code class="code">rcolor</code>: <code class="code">"0'</code> is converted to transparent white. </p> <p>There is a R-level conversion of colours to ‘<samp class="samp">##RRGGBBAA</samp>’ by <code class="code">image.default(useRaster = TRUE)</code>. </p> <p>The other color-conversion entry point in the API is <code class="code">name2col</code> which takes a colour name (a C string) and returns a value of type <code class="code">rcolor</code>. This handles <code class="code">"NA"</code>, <code class="code">"transparent"</code> and the 657 colours known to the R function <code class="code">colors()</code>. </p> <hr> </div> <div class="section-level-extent" id="Base-graphics"> <div class="nav-panel"> <p> Next: <a href="#Grid-graphics" accesskey="n" rel="next">Grid graphics</a>, Previous: <a href="#Colours" accesskey="p" rel="prev">Colours</a>, Up: <a href="#Graphics-Devices" accesskey="u" rel="up">Graphics</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-variable-index" title="Index" rel="index">Index</a>]</p> </div> <h3 class="section" id="Base-graphics-1"><span>6.3 Base graphics<a class="copiable-link" href="#Base-graphics-1"> ¶</a></span></h3> <p>The base graphics system was migrated to package <strong class="strong">graphics</strong> in R 3.0.0: it was previously implemented in files in <samp class="file">src/main</samp>. </p> <p>For historical reasons it is largely implemented in two layers. Files <samp class="file">plot.c</samp>, <samp class="file">plot3d.c</samp> and <samp class="file">par.c</samp> contain the code for the around 30 <code class="code">.External</code> calls that implement the basic graphics operations. This code then calls functions with names starting with <code class="code">G</code> and declared in header <samp class="file">Rgraphics.h</samp> in file <samp class="file">graphics.c</samp>, which in turn call the graphics engine (whose functions almost all have names starting with <code class="code">GE</code>). </p> <p>A large part of the infrastructure of the base graphics subsystem are the graphics parameters (as set/read by <code class="code">par()</code>). These are stored in a <code class="code">GPar</code> structure declared in the private header <samp class="file">Graphics.h</samp>. This structure has two variables (<code class="code">state</code> and <code class="code">valid</code>) tracking the state of the base subsystem on the device, and many variables recording the graphics parameters and functions of them. </p> <p>The base system state is contained in <code class="code">baseSystemState</code> structure defined in the private header <samp class="file">GraphicsBase.h</samp>. This contains three <code class="code">GPar</code> structures and a Boolean variable used to record if <code class="code">plot.new()</code> (or <code class="code">persp</code>) has been used successfully on the device. </p> <p>The three copies of the <code class="code">GPar</code> structure are used to store the current parameters (accessed via <code class="code">gpptr</code>), the ‘device copy’ (accessed via <code class="code">dpptr</code>) and space for a saved copy of the ‘device copy’ parameters. The current parameters are, clearly, those currently in use and are copied from the ‘device copy’ whenever <code class="code">plot.new()</code> is called (whether or not that advances to the next ‘page’). The saved copy keeps the state when the device was last completely cleared (e.g. when <code class="code">plot.new()</code> was called with <code class="code">par(new=TRUE)</code>), and is used to replay the display list. </p> <p>The separation is not completely clean: the ‘device copy’ is altered if a plot with log scale(s) is set up via <code class="code">plot.window()</code>. </p> <p>There is yet another copy of most of the graphics parameters in <code class="code">static</code> variables in <samp class="file">graphics.c</samp> which are used to preserve the current parameters across the processing of inline parameters in high-level graphics calls (handled by <code class="code">ProcessInlinePars</code>). </p> <p>Snapshots of the base subsystem record the ‘saved device copy’ of the <code class="code">GPar</code> structure. </p> <ul class="mini-toc"> <li><a href="#Arguments-and-parameters" accesskey="1">Arguments and parameters</a></li> </ul> <hr> <div class="subsection-level-extent" id="Arguments-and-parameters"> <div class="nav-panel"> <p> Previous: <a href="#Base-graphics" accesskey="p" rel="prev">Base graphics</a>, Up: <a href="#Base-graphics" accesskey="u" rel="up">Base graphics</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-variable-index" title="Index" rel="index">Index</a>]</p> </div> <h4 class="subsection" id="Arguments-and-parameters-1"><span>6.3.1 Arguments and parameters<a class="copiable-link" href="#Arguments-and-parameters-1"> ¶</a></span></h4> <p>There is an unfortunate confusion between some of the graphical parameters (as set by <code class="code">par</code>) and arguments to base graphic functions of the same name. This description may help set the record straight. </p> <p>Most of the high-level plotting functions accept graphical parameters as additional arguments, which are then often passed to lower-level functions if not already named arguments (which is the main source of confusion). </p> <p>Graphical parameter <code class="code">bg</code> is the background colour of the plot. Argument <code class="code">bg</code> refers to the fill colour for the filled symbols <code class="code">21</code> to <code class="code">25</code>. It is an argument to the function <code class="code">plot.xy</code>, but normally passed by the default method of <code class="code">points</code>, often from a <code class="code">plot</code> method. </p> <p>Graphics parameters <code class="code">cex</code>, <code class="code">col</code>, <code class="code">lty</code>, <code class="code">lwd</code> and <code class="code">pch</code> also appear as arguments of <code class="code">plot.xy</code> and so are often passed as arguments from higher-level plot functions such as <code class="code">lines</code>, <code class="code">points</code> and <code class="code">plot</code> methods. They appear as arguments of <code class="code">legend</code>, <code class="code">col</code>, <code class="code">lty</code> and <code class="code">lwd</code> are arguments of <code class="code">arrows</code> and <code class="code">segments</code>. When used as arguments they can be vectors, recycled to control the various lines, points and segments. When set a graphical parameters they set the default rendering: in addition <code class="code">par(cex=)</code> sets the overall character expansion which subsequent calls (as arguments or on-line graphical parameters) multiply. </p> <p>The handling of missing values differs in the two classes of uses. Generally these are errors when used in <code class="code">par</code> but cause the corresponding element of the plot to be omitted when used as an element of a vector argument. Originally the interpretation of arguments was mainly left to the device, but nowadays some of this is pre-empted in the graphics engine (but for example the handling of <code class="code">lwd = 0</code> remains device-specific, with some interpreting it as a ‘thinnest possible’ line). </p> <hr> </div> </div> <div class="section-level-extent" id="Grid-graphics"> <div class="nav-panel"> <p> Previous: <a href="#Base-graphics" accesskey="p" rel="prev">Base graphics</a>, Up: <a href="#Graphics-Devices" accesskey="u" rel="up">Graphics</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-variable-index" title="Index" rel="index">Index</a>]</p> </div> <h3 class="section" id="Grid-graphics-1"><span>6.4 Grid graphics<a class="copiable-link" href="#Grid-graphics-1"> ¶</a></span></h3> <p>[At least pointers to documentation.] </p> <hr> </div> </div> <div class="chapter-level-extent" id="GUI-consoles"> <div class="nav-panel"> <p> Next: <a href="#Tools" accesskey="n" rel="next">Tools</a>, Previous: <a href="#Graphics-Devices" accesskey="p" rel="prev">Graphics</a>, Up: <a href="#Top" accesskey="u" rel="up">R Internals</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-variable-index" title="Index" rel="index">Index</a>]</p> </div> <h2 class="chapter" id="GUI-consoles-1"><span>7 GUI consoles<a class="copiable-link" href="#GUI-consoles-1"> ¶</a></span></h2> <p>The standard R front-ends are programs which run in a terminal, but there are several ways to provide a GUI console. </p> <p>This can be done by a package which is loaded from terminal-based R and launches a console as part of its startup code or by the user running a specific function: package <a class="url" href="https://CRAN.R-project.org/package=Rcmdr"><strong class="strong">Rcmdr</strong></a> is a well-known example with a Tk-based GUI. </p> <p>There used to be a GTK-based console invoked by <code class="command">R --gui=GNOME</code>: this relied on special-casing in the front-end shell script to launch a different executable. There still is <code class="command">R --gui=Tk</code>, which starts terminal-based R and runs <code class="code">tcltk::tkStartGui()</code> as part of the modified startup sequence. </p> <p>However, the main way to run a GUI console is to launch a separate program which runs embedded R: this is done by <code class="command">Rgui.exe</code> on Windows and <code class="command">R.app</code> on macOS. The first is an integral part of R and the code for the console is currently in <samp class="file">R.dll</samp>. </p> <ul class="mini-toc"> <li><a href="#R_002eapp" accesskey="1">R.app</a></li> </ul> <hr> <div class="section-level-extent" id="R_002eapp"> <div class="nav-panel"> <p> Previous: <a href="#GUI-consoles" accesskey="p" rel="prev">GUI consoles</a>, Up: <a href="#GUI-consoles" accesskey="u" rel="up">GUI consoles</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-variable-index" title="Index" rel="index">Index</a>]</p> </div> <h3 class="section" id="R_002eapp-1"><span>7.1 R.app<a class="copiable-link" href="#R_002eapp-1"> ¶</a></span></h3> <p><code class="command">R.app</code> is a macOS application which provides a console. Its sources are a separate project<a class="footnote" id="DOCF21" href="#FOOT21"><sup>21</sup></a>, and its binaries link to an R installation which it runs as a dynamic library <samp class="file">libR.dylib</samp>. The standard <abbr class="acronym">CRAN</abbr> distribution of R for macOS bundles the GUI and R itself, but installing the GUI is optional and either component can be updated separately. </p> <p><code class="command">R.app</code> relies on <samp class="file">libR.dylib</samp> being in a specific place, and hence on R having been built and installed as a Mac macOS ‘framework’. Specifically, it uses <samp class="file">/Library/Frameworks/R.framework/R</samp>. This is a symbolic link, as frameworks can contain multiple versions of R. It eventually resolves to <samp class="file">/Library/Frameworks/R.framework/Versions/Current/Resources/lib/libR.dylib</samp>, which is (in the <abbr class="acronym">CRAN</abbr> distribution) a ‘fat’ binary containing multiple sub-architectures. </p> <p>macOS applications are directory trees: each <code class="command">R.app</code> contains a front-end written in Objective-C for one sub-architecture: in the standard distribution there are separate applications for 32- and 64-bit Intel architectures. </p> <p>Originally the R sources contained quite a lot of code used only by the macOS GUI, but this was migrated to the <code class="command">R.app</code> sources. </p> <p><code class="command">R.app</code> starts R as an embedded application with a command-line which includes <samp class="option">--gui=aqua</samp> (see below). It uses most of the interface pointers defined in the header <samp class="file">Rinterface.h</samp>, plus a private interface pointer in file <samp class="file">src/main/sysutils.c</samp>. It adds an environment it names <code class="code">tools:RGUI</code> to the second position in the search path. This contains a number of utility functions used to support the menu items, for example <code class="code">package.manager()</code>, plus functions <code class="code">q()</code> and <code class="code">quit()</code> which mask those in package <strong class="strong">base</strong>—the custom versions save the history in a way specific to <code class="code">R.app</code>. </p> <p>There is a <code class="command">configure</code> option <samp class="option">--with-aqua</samp> for R which customizes the way R is built: this is distinct from the <samp class="option">--enable-R-framework</samp> option which causes <code class="command">make install</code> to install R as the framework needed for use with <code class="code">R.app</code>. (The option <samp class="option">--with-aqua</samp> is the default on macOS.) It sets the macro <code class="code">HAVE_AQUA</code> in <samp class="file">config.h</samp> and the make variable <code class="code">BUILD_AQUA_TRUE</code>. These have several consequences: </p> <ul class="itemize mark-bullet"> <li>The <code class="code">quartz()</code> device is built (other than as a stub) in package <strong class="strong">grDevices</strong>: this needs an Objective-C compiler. Then <code class="code">quartz()</code> can be used with terminal R provided the latter has access to the macOS screen. </li><li>File <samp class="file">src/unix/aqua.c</samp> is compiled. This now only contains an interface pointer for the <code class="code">quartz()</code> device(s). </li><li><code class="code">capabilities("aqua")</code> is set to <code class="code">TRUE</code>. </li><li>The default path for a personal library directory is set as <samp class="file">~/Library/R/arch/x.y/library</samp>. </li><li>There is support for setting a ‘busy’ indicator whilst waiting for <code class="code">system()</code> to return. </li><li><code class="code">R_ProcessEvents</code> is inhibited in a forked child from package <strong class="strong">parallel</strong>. The associated callback in <code class="code">R.app</code> does things which should not be done in a child, and forking forks the whole process including the console. </li><li>There is support for starting the embedded R with the option <samp class="option">--gui=aqua</samp>: when this is done the global C variable <code class="code">useaqua</code> is set to a true value. This has consequences: <ul class="itemize mark-bullet"> <li>The R session is asserted to be interactive <em class="emph">via</em> <code class="code">R_Interactive</code>. </li><li><code class="code">.Platform$GUI</code> is set to <code class="code">"AQUA"</code>. That has consequences: <ul class="itemize mark-bullet"> <li>The environment variable <code class="env">DISPLAY</code> is set to ‘<samp class="samp">:0</samp>’ if not already set. </li><li><samp class="file">/usr/local/bin</samp> is appended to <code class="env">PATH</code> since that is where <code class="command">gfortran</code> is installed. </li><li>The default <abbr class="acronym">HTML</abbr> browser is switched to the one in <code class="command">R.app</code>. </li><li>Various widgets are switched to the versions provided in <code class="command">R.app</code>: these include graphical menus, the data editor (but not the data viewer used by <code class="code">View()</code>) and the workspace browser invoked by <code class="code">browseEnv()</code>. </li><li>The <strong class="strong">grDevices</strong> package when loaded knows that it is being run under <code class="command">R.app</code> and so informs any <code class="code">quartz</code> devices that a Quartz event loop is already running. </li></ul> </li><li>The use of the OS’s <code class="code">system</code> function (including by <code class="code">system()</code> and <code class="code">system2()</code>, and to launch editors and pagers) is replaced by a version in <code class="code">R.app</code> (which by default just calls the OS’s <code class="code">system</code> with various signal handlers reset). </li></ul> </li><li>If either R was started by <samp class="option">--gui=aqua</samp> or R is running in a terminal which is not of type ‘<samp class="samp">dumb</samp>’, the standard output to files <samp class="file">stdout</samp> and <samp class="file">stderr</samp> is directed through the C function <code class="code">Rstd_WriteConsoleEx</code>. This uses ANSI terminal escapes to render lines sent to <code class="code">stderr</code> as bold on <code class="code">stdout</code>. </li><li>For historical reasons the startup option <code class="code">-psn</code> is allowed but ignored. (It seems that in 2003, ‘<samp class="samp">r27492</samp>’, this was added by Finder.) </li></ul> <hr> </div> </div> <div class="chapter-level-extent" id="Tools"> <div class="nav-panel"> <p> Next: <a href="#R-coding-standards" accesskey="n" rel="next">R coding standards</a>, Previous: <a href="#GUI-consoles" accesskey="p" rel="prev">GUI consoles</a>, Up: <a href="#Top" accesskey="u" rel="up">R Internals</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-variable-index" title="Index" rel="index">Index</a>]</p> </div> <h2 class="chapter" id="Tools-1"><span>8 Tools<a class="copiable-link" href="#Tools-1"> ¶</a></span></h2> <p>The behavior of <code class="command">R CMD check</code> can be controlled through a variety of command line arguments and environment variables. </p> <p>There is an internal <samp class="option">--install=<var class="var">value</var></samp> command line argument not shown by <code class="command">R CMD check --help</code>, with possible values </p> <dl class="table"> <dt><code class="code">check:<var class="var">file</var></code></dt> <dd><p>Assume that installation was already performed with stdout/stderr to <var class="var">file</var>, the contents of which need to be checked (without repeating the installation). This is useful for checks applied by repository maintainers: it reduces the check time by the installation time given that the package has already been installed. In this case, one also needs to specify <em class="emph">where</em> the package was installed to using command line option <samp class="option">--library</samp>. </p></dd> <dt><code class="code">fake</code></dt> <dd><p>Fake installation, and turn off the run-time tests. </p></dd> <dt><code class="code">skip</code></dt> <dd><p>Skip installation, e.g., when testing recommended packages bundled with R. </p></dd> <dt><code class="code">no</code></dt> <dd><p>The same as <samp class="option">--no-install</samp> : turns off installation and the tests which require the package to be installed. </p></dd> </dl> <p>The following environment variables can be used to customize the operation of <code class="command">check</code>: a convenient place to set these is the check environment file (default, <samp class="file">~/.R/check.Renviron</samp>). </p> <dl class="vtable"> <dt><a id="index-_005fR_005fCHECK_005fALL_005fNON_005fISO_005fC_005f"></a><span><code class="code">_R_CHECK_ALL_NON_ISO_C_</code><a class="copiable-link" href="#index-_005fR_005fCHECK_005fALL_005fNON_005fISO_005fC_005f"> ¶</a></span></dt> <dd><p>If true, do not ignore compiler (typically GCC) warnings about non ISO C code in <em class="emph">system</em> headers. Note that this may also show additional ISO C++ warnings. Default: false. </p></dd> <dt><a id="index-_005fR_005fCHECK_005fFORCE_005fSUGGESTS_005f"></a><span><code class="code">_R_CHECK_FORCE_SUGGESTS_</code><a class="copiable-link" href="#index-_005fR_005fCHECK_005fFORCE_005fSUGGESTS_005f"> ¶</a></span></dt> <dd><p>If true, give an error if suggested packages are not available. Default: true (but false for CRAN submission checks). </p></dd> <dt><a id="index-_005fR_005fCHECK_005fRD_005fCONTENTS_005f"></a><span><code class="code">_R_CHECK_RD_CONTENTS_</code><a class="copiable-link" href="#index-_005fR_005fCHECK_005fRD_005fCONTENTS_005f"> ¶</a></span></dt> <dd><p>If true, check <samp class="file">Rd</samp> files for auto-generated content which needs editing, and missing argument documentation. Default: true. </p></dd> <dt><a id="index-_005fR_005fCHECK_005fRD_005fLINE_005fWIDTHS_005f"></a><span><code class="code">_R_CHECK_RD_LINE_WIDTHS_</code><a class="copiable-link" href="#index-_005fR_005fCHECK_005fRD_005fLINE_005fWIDTHS_005f"> ¶</a></span></dt> <dd><p>If true, check <samp class="file">Rd</samp> line widths in usage and examples sections. Default: false (but true for CRAN submission checks). </p></dd> <dt><a id="index-_005fR_005fCHECK_005fRD_005fSTYLE_005f"></a><span><code class="code">_R_CHECK_RD_STYLE_</code><a class="copiable-link" href="#index-_005fR_005fCHECK_005fRD_005fSTYLE_005f"> ¶</a></span></dt> <dd><p>If true, check whether <samp class="file">Rd</samp> usage entries for S3 methods use the full function name rather than the appropriate <code class="code">\method</code> markup. Default: true. </p></dd> <dt><a id="index-_005fR_005fCHECK_005fRD_005fXREFS_005f"></a><span><code class="code">_R_CHECK_RD_XREFS_</code><a class="copiable-link" href="#index-_005fR_005fCHECK_005fRD_005fXREFS_005f"> ¶</a></span></dt> <dd><p>If true, check the cross-references in <samp class="file">.Rd</samp> files. Default: true. </p></dd> <dt><a id="index-_005fR_005fCHECK_005fSUBDIRS_005fNOCASE_005f"></a><span><code class="code">_R_CHECK_SUBDIRS_NOCASE_</code><a class="copiable-link" href="#index-_005fR_005fCHECK_005fSUBDIRS_005fNOCASE_005f"> ¶</a></span></dt> <dd><p>If true, check the case of directories such as <samp class="file">R</samp> and <samp class="file">man</samp>. Default: true. </p></dd> <dt><a id="index-_005fR_005fCHECK_005fSUBDIRS_005fSTRICT_005f"></a><span><code class="code">_R_CHECK_SUBDIRS_STRICT_</code><a class="copiable-link" href="#index-_005fR_005fCHECK_005fSUBDIRS_005fSTRICT_005f"> ¶</a></span></dt> <dd><p>Initial setting for <samp class="option">--check-subdirs</samp>. Default: ‘<samp class="samp">default</samp>’ (which checks only tarballs, and checks in the <samp class="file">src</samp> only if there is no <samp class="file">configure</samp> file). </p></dd> <dt><a id="index-_005fR_005fCHECK_005fUSE_005fCODETOOLS_005f"></a><span><code class="code">_R_CHECK_USE_CODETOOLS_</code><a class="copiable-link" href="#index-_005fR_005fCHECK_005fUSE_005fCODETOOLS_005f"> ¶</a></span></dt> <dd><p>If true, make use of the <a class="url" href="https://CRAN.R-project.org/package=codetools"><strong class="strong">codetools</strong></a> package, which provides a detailed analysis of visibility of objects (but may give false positives). Default: true (if recommended packages are installed). </p></dd> <dt><a id="index-_005fR_005fCHECK_005fUSE_005fINSTALL_005fLOG_005f"></a><span><code class="code">_R_CHECK_USE_INSTALL_LOG_</code><a class="copiable-link" href="#index-_005fR_005fCHECK_005fUSE_005fINSTALL_005fLOG_005f"> ¶</a></span></dt> <dd><p>If true, record the output from installing a package as part of its check to a log file (<samp class="file">00install.out</samp> by default), even when running interactively. Default: true. </p></dd> <dt><a id="index-_005fR_005fCHECK_005fVIGNETTES_005fNLINES_005f"></a><span><code class="code">_R_CHECK_VIGNETTES_NLINES_</code><a class="copiable-link" href="#index-_005fR_005fCHECK_005fVIGNETTES_005fNLINES_005f"> ¶</a></span></dt> <dd><p>Maximum number of lines to show from the bottom of the output when reporting errors in running or re-building vignettes. ( Value <code class="code">0</code> means all lines will be shown.) Default: 10 for running, 25 for re-building. </p></dd> <dt><a id="index-_005fR_005fCHECK_005fCODOC_005fS4_005fMETHODS_005f"></a><span><code class="code">_R_CHECK_CODOC_S4_METHODS_</code><a class="copiable-link" href="#index-_005fR_005fCHECK_005fCODOC_005fS4_005fMETHODS_005f"> ¶</a></span></dt> <dd><p>Control whether <code class="code">codoc()</code> testing is also performed on S4 methods. Default: true. </p></dd> <dt><a id="index-_005fR_005fCHECK_005fDOT_005fINTERNAL_005f"></a><span><code class="code">_R_CHECK_DOT_INTERNAL_</code><a class="copiable-link" href="#index-_005fR_005fCHECK_005fDOT_005fINTERNAL_005f"> ¶</a></span></dt> <dd><p>Control whether the package code is scanned for <code class="code">.Internal</code> calls, which should only be used by base (and occasionally by recommended) packages. Default: true. </p></dd> <dt><a id="index-_005fR_005fCHECK_005fEXECUTABLES_005f"></a><span><code class="code">_R_CHECK_EXECUTABLES_</code><a class="copiable-link" href="#index-_005fR_005fCHECK_005fEXECUTABLES_005f"> ¶</a></span></dt> <dd><p>Control checking for executable (binary) files. Default: true. </p></dd> <dt><a id="index-_005fR_005fCHECK_005fEXECUTABLES_005fEXCLUSIONS_005f"></a><span><code class="code">_R_CHECK_EXECUTABLES_EXCLUSIONS_</code><a class="copiable-link" href="#index-_005fR_005fCHECK_005fEXECUTABLES_005fEXCLUSIONS_005f"> ¶</a></span></dt> <dd><p>Control whether checking for executable (binary) files ignores files listed in the package’s <samp class="file">BinaryFiles</samp> file. Default: true (but false for CRAN submission checks). However, most likely this package-level override mechanism will be removed eventually. </p></dd> <dt><a id="index-_005fR_005fCHECK_005fPERMISSIONS_005f"></a><span><code class="code">_R_CHECK_PERMISSIONS_</code><a class="copiable-link" href="#index-_005fR_005fCHECK_005fPERMISSIONS_005f"> ¶</a></span></dt> <dd><p>Control whether permissions of files should be checked. Default: true iff <code class="code">.Platform$OS.type == "unix"</code>. </p></dd> <dt><a id="index-_005fR_005fCHECK_005fFF_005fCALLS_005f"></a><span><code class="code">_R_CHECK_FF_CALLS_</code><a class="copiable-link" href="#index-_005fR_005fCHECK_005fFF_005fCALLS_005f"> ¶</a></span></dt> <dd><p>Allows turning off <code class="code">checkFF()</code> testing. If set to ‘<samp class="samp">registration</samp>’, checks the registration information (number of arguments, correct choice of <code class="code">.C/.Fortran/.Call/.External</code>) for such calls provided the package is installed. Default: true. </p></dd> <dt><a id="index-_005fR_005fCHECK_005fFF_005fDUP_005f"></a><span><code class="code">_R_CHECK_FF_DUP_</code><a class="copiable-link" href="#index-_005fR_005fCHECK_005fFF_005fDUP_005f"> ¶</a></span></dt> <dd><p>Controls <code class="code">checkFF(check_DUP)</code> Default: true (and forced to be true for CRAN submission checks). </p></dd> <dt><a id="index-_005fR_005fCHECK_005fLICENSE_005f"></a><span><code class="code">_R_CHECK_LICENSE_</code><a class="copiable-link" href="#index-_005fR_005fCHECK_005fLICENSE_005f"> ¶</a></span></dt> <dd><p>Control whether/how license checks are performed. A possible value is ‘<samp class="samp">maybe</samp>’ (warn in case of problems, but not about standardizable non-standard license specs). Default: true. </p></dd> <dt><a id="index-_005fR_005fCHECK_005fRD_005fEXAMPLES_005fT_005fAND_005fF_005f"></a><span><code class="code">_R_CHECK_RD_EXAMPLES_T_AND_F_</code><a class="copiable-link" href="#index-_005fR_005fCHECK_005fRD_005fEXAMPLES_005fT_005fAND_005fF_005f"> ¶</a></span></dt> <dd><p>Control whether <code class="code">check_T_and_F()</code> also looks for “bad” (global) ‘<samp class="samp">T</samp>’/‘<samp class="samp">F</samp>’ uses in examples. Off by default because this can result in false positives. </p></dd> <dt><a id="index-_005fR_005fCHECK_005fRD_005fCHECKRD_005fMINLEVEL_005f"></a><span><code class="code">_R_CHECK_RD_CHECKRD_MINLEVEL_</code><a class="copiable-link" href="#index-_005fR_005fCHECK_005fRD_005fCHECKRD_005fMINLEVEL_005f"> ¶</a></span></dt> <dd><p>Controls the minimum level for reporting warnings from <code class="code">checkRd()</code>. Default: -1. </p></dd> <dt><a id="index-_005fR_005fCHECK_005fRD_005fNOTE_005fLOST_005fBRACES_005f"></a><span><code class="code">_R_CHECK_RD_NOTE_LOST_BRACES_</code><a class="copiable-link" href="#index-_005fR_005fCHECK_005fRD_005fNOTE_005fLOST_005fBRACES_005f"> ¶</a></span></dt> <dd><p>Control whether some of the “lost braces” that <code class="code">checkRd()</code> finds in LaTeX-like Rd contexts are reported (by raising their warning level to -1). This will often detect missing initial backslashes for Rd macros, unescaped in-text set braces, and <code class="code">\describe</code>-style <code class="code">\item{label}{desc}</code> entries within <code class="code">\itemize</code>. Default: true. </p></dd> <dt><a id="index-_005fR_005fCHECK_005fRD_005fALLOW_005fEMPTY_005fITEM_005fIN_005fDESCRIBE_005f"></a><span><code class="code">_R_CHECK_RD_ALLOW_EMPTY_ITEM_IN_DESCRIBE_</code><a class="copiable-link" href="#index-_005fR_005fCHECK_005fRD_005fALLOW_005fEMPTY_005fITEM_005fIN_005fDESCRIBE_005f"> ¶</a></span></dt> <dd><p>Control whether empty items inside <code class="code">\describe</code> are allowed without a warning. This is a temporary stop gap measure meant to support legacy packages, and is likely to be removed in future versions of R. Default: false. </p></dd> <dt><a id="index-_005fR_005fCHECK_005fXREFS_005fREPOSITORIES_005f"></a><span><code class="code">_R_CHECK_XREFS_REPOSITORIES_</code><a class="copiable-link" href="#index-_005fR_005fCHECK_005fXREFS_005fREPOSITORIES_005f"> ¶</a></span></dt> <dd><p>If set to a non-empty value, a space-separated list of repositories to use to determine known packages. Default: empty, when the CRAN and Bioconductor repositories known to R is used. </p></dd> <dt><a id="index-_005fR_005fCHECK_005fSRC_005fMINUS_005fW_005fIMPLICIT_005f"></a><span><code class="code">_R_CHECK_SRC_MINUS_W_IMPLICIT_</code><a class="copiable-link" href="#index-_005fR_005fCHECK_005fSRC_005fMINUS_005fW_005fIMPLICIT_005f"> ¶</a></span></dt> <dd><p>Control whether installation output is checked for compilation warnings about implicit function declarations (as spotted by GCC with command line option <samp class="option">-Wimplicit-function-declaration</samp>, which is implied by <samp class="option">-Wall</samp>). NB: implicit function declarations are errors in some recent C compilers, including Apple <code class="command">clang</code>. Default: true from R 4.2.0, previously false. </p></dd> <dt><a id="index-_005fR_005fCHECK_005fSRC_005fMINUS_005fW_005fUNUSED_005f"></a><span><code class="code">_R_CHECK_SRC_MINUS_W_UNUSED_</code><a class="copiable-link" href="#index-_005fR_005fCHECK_005fSRC_005fMINUS_005fW_005fUNUSED_005f"> ¶</a></span></dt> <dd><p>Control whether installation output is checked for compilation warnings about unused code constituents (as spotted by GCC with command line option <samp class="option">-Wunused</samp>, which is implied by <samp class="option">-Wall</samp>). Default: true. </p></dd> <dt><a id="index-_005fR_005fCHECK_005fWALL_005fFORTRAN_005f"></a><span><code class="code">_R_CHECK_WALL_FORTRAN_</code><a class="copiable-link" href="#index-_005fR_005fCHECK_005fWALL_005fFORTRAN_005f"> ¶</a></span></dt> <dd><p>Control whether GFortran 4.0 or later <samp class="option">-Wall</samp> warnings are used in the analysis of installation output. Default: false, even though the warnings are justifiable. </p></dd> <dt><a id="index-_005fR_005fCHECK_005fASCII_005fCODE_005f"></a><span><code class="code">_R_CHECK_ASCII_CODE_</code><a class="copiable-link" href="#index-_005fR_005fCHECK_005fASCII_005fCODE_005f"> ¶</a></span></dt> <dd><p>If true, check R code for non-ascii characters. Default: true. </p></dd> <dt><a id="index-_005fR_005fCHECK_005fASCII_005fDATA_005f"></a><span><code class="code">_R_CHECK_ASCII_DATA_</code><a class="copiable-link" href="#index-_005fR_005fCHECK_005fASCII_005fDATA_005f"> ¶</a></span></dt> <dd><p>If true, check data for non-ascii characters. <em class="emph">En route</em>, checks that all the datasets can be loaded and that their components can be accessed. Default: true. </p></dd> <dt><a id="index-_005fR_005fCHECK_005fCOMPACT_005fDATA_005f"></a><span><code class="code">_R_CHECK_COMPACT_DATA_</code><a class="copiable-link" href="#index-_005fR_005fCHECK_005fCOMPACT_005fDATA_005f"> ¶</a></span></dt> <dd><p>If true, check data for ascii and uncompressed saves, and also check if using <code class="command">bzip2</code> or <code class="code">xz</code> compression would be significantly better. Default: true. </p></dd> <dt><a id="index-_005fR_005fCHECK_005fSKIP_005fARCH_005f"></a><span><code class="code">_R_CHECK_SKIP_ARCH_</code><a class="copiable-link" href="#index-_005fR_005fCHECK_005fSKIP_005fARCH_005f"> ¶</a></span></dt> <dd><p>Comma-separated list of architectures that will be omitted from checking in a multi-arch setup. Default: none. </p></dd> <dt><a id="index-_005fR_005fCHECK_005fSKIP_005fTESTS_005fARCH_005f"></a><span><code class="code">_R_CHECK_SKIP_TESTS_ARCH_</code><a class="copiable-link" href="#index-_005fR_005fCHECK_005fSKIP_005fTESTS_005fARCH_005f"> ¶</a></span></dt> <dd><p>Comma-separated list of architectures that will be omitted from running tests in a multi-arch setup. Default: none. </p></dd> <dt><a id="index-_005fR_005fCHECK_005fSKIP_005fEXAMPLES_005fARCH_005f"></a><span><code class="code">_R_CHECK_SKIP_EXAMPLES_ARCH_</code><a class="copiable-link" href="#index-_005fR_005fCHECK_005fSKIP_005fEXAMPLES_005fARCH_005f"> ¶</a></span></dt> <dd><p>Comma-separated list of architectures that will be omitted from running examples in a multi-arch setup. Default: none. </p></dd> <dt><a id="index-_005fR_005fCHECK_005fVC_005fDIRS_005f"></a><span><code class="code">_R_CHECK_VC_DIRS_</code><a class="copiable-link" href="#index-_005fR_005fCHECK_005fVC_005fDIRS_005f"> ¶</a></span></dt> <dd><p>Should the unpacked package directory be checked for version-control directories (<samp class="file">CVS</samp>, <samp class="file">.svn</samp> …)? Default: true for tarballs. </p></dd> <dt><a id="index-_005fR_005fCHECK_005fPKG_005fSIZES_005f"></a><span><code class="code">_R_CHECK_PKG_SIZES_</code><a class="copiable-link" href="#index-_005fR_005fCHECK_005fPKG_005fSIZES_005f"> ¶</a></span></dt> <dd><p>Should <code class="command">du</code> be used to find the installed sizes of packages? <code class="command">R CMD check</code> does check for the availability of <code class="command">du</code>. but this option allows the check to be overruled if an unsuitable command is found (including one that does not respect the <samp class="option">-k</samp> flag to report in units of 1Kb, or reports in a different format – the GNU, macOS and Solaris <code class="command">du</code> commands have been tested). Default: true if <code class="command">du</code> is found. </p></dd> <dt><a id="index-_005fR_005fCHECK_005fPKG_005fSIZES_005fTHRESHOLD_005f"></a><span><code class="code">_R_CHECK_PKG_SIZES_THRESHOLD_</code><a class="copiable-link" href="#index-_005fR_005fCHECK_005fPKG_005fSIZES_005fTHRESHOLD_005f"> ¶</a></span></dt> <dd><p>Threshold used for <code class="env">_R_CHECK_PKG_SIZES_</code> (in Mb). Default: 5 </p></dd> <dt><a id="index-_005fR_005fCHECK_005fDOC_005fSIZES_005f"></a><span><code class="code">_R_CHECK_DOC_SIZES_</code><a class="copiable-link" href="#index-_005fR_005fCHECK_005fDOC_005fSIZES_005f"> ¶</a></span></dt> <dd><p>Should <code class="command">qpdf</code> be used to check the installed sizes of PDFs? Default: true if <code class="command">qpdf</code> is found. </p></dd> <dt><a id="index-_005fR_005fCHECK_005fDOC_005fSIZES2_005f"></a><span><code class="code">_R_CHECK_DOC_SIZES2_</code><a class="copiable-link" href="#index-_005fR_005fCHECK_005fDOC_005fSIZES2_005f"> ¶</a></span></dt> <dd><p>Should <code class="command">gs</code> be used to check the installed sizes of PDFs? This is slower than (and in addition to) the previous check, but does detect figures with excessive detail (often hidden by over-plotting) or bitmap figures with too high a resolution. Requires that <code class="env">R_GSCMD</code> is set to a valid program, or <code class="command">gs</code> (or on Windows, <code class="command">gswin32.exe</code> or <code class="command">gswin64c.exe</code>) is on the path. Default: false (but true for CRAN submission checks). </p></dd> <dt><a id="index-_005fR_005fCHECK_005fALWAYS_005fLOG_005fVIGNETTE_005fOUTPUT_005f"></a><span><code class="code">_R_CHECK_ALWAYS_LOG_VIGNETTE_OUTPUT_</code><a class="copiable-link" href="#index-_005fR_005fCHECK_005fALWAYS_005fLOG_005fVIGNETTE_005fOUTPUT_005f"> ¶</a></span></dt> <dd><p>By default the output from running the R code in the vignettes is kept only if there is an error. This also applies to the <samp class="file">build_vignettes.log</samp> log from the re-building of vignettes. Default: false. </p></dd> <dt><a id="index-_005fR_005fCHECK_005fCLEAN_005fVIGN_005fTEST_005f"></a><span><code class="code">_R_CHECK_CLEAN_VIGN_TEST_</code><a class="copiable-link" href="#index-_005fR_005fCHECK_005fCLEAN_005fVIGN_005fTEST_005f"> ¶</a></span></dt> <dd><p>Should the <samp class="file">vign_test</samp> directory be removed if the test is successful? Default: true. </p></dd> <dt><a id="index-_005fR_005fCHECK_005fREPLACING_005fIMPORTS_005f"></a><span><code class="code">_R_CHECK_REPLACING_IMPORTS_</code><a class="copiable-link" href="#index-_005fR_005fCHECK_005fREPLACING_005fIMPORTS_005f"> ¶</a></span></dt> <dd><p>Should warnings about replacing imports be reported? These sometimes come from auto-generated <samp class="file">NAMESPACE</samp> files in other packages, but most often from importing the whole of a namespace rather than using <code class="code">importFrom</code>. Default: true. </p></dd> <dt><a id="index-_005fR_005fCHECK_005fUNSAFE_005fCALLS_005f"></a><span><code class="code">_R_CHECK_UNSAFE_CALLS_</code><a class="copiable-link" href="#index-_005fR_005fCHECK_005fUNSAFE_005fCALLS_005f"> ¶</a></span></dt> <dd><p>Check for calls that appear to tamper with (or allow tampering with) already loaded code not from the current package: such calls may well contravene CRAN policies. Default: true. </p></dd> <dt><a id="index-_005fR_005fCHECK_005fTIMINGS_005f"></a><span><code class="code">_R_CHECK_TIMINGS_</code><a class="copiable-link" href="#index-_005fR_005fCHECK_005fTIMINGS_005f"> ¶</a></span></dt> <dd><p>Optionally report timings for installation, examples, tests and running/re-building vignettes as part of the check log. The format is ‘<samp class="samp">[as/bs]</samp>’ for the total CPU time (including child processes) ‘<samp class="samp">a</samp>’ and elapsed time ‘<samp class="samp">b</samp>’, except on Windows, when it is ‘<samp class="samp">[bs]</samp>’. In most cases timings are only given for ‘<samp class="samp">OK</samp>’ checks. Times with an elapsed component over 10 <abbr class="abbr">min</abbr>s are reported in minutes (with abbreviation ‘<samp class="samp">m</samp>’). The value is the smallest numerical value in elapsed seconds that should be reported: non-numerical values indicate that no report is required, a value of ‘<samp class="samp">0</samp>’ that a report is always required. Default: <code class="code">""</code>. (<code class="code">10</code> for CRAN checks unless set in the environment.) </p> </dd> <dt><a id="index-_005fR_005fCHECK_005fEXAMPLE_005fTIMING_005fTHRESHOLD_005f"></a><span><code class="code">_R_CHECK_EXAMPLE_TIMING_THRESHOLD_</code><a class="copiable-link" href="#index-_005fR_005fCHECK_005fEXAMPLE_005fTIMING_005fTHRESHOLD_005f"> ¶</a></span></dt> <dd><p>If timings are being recorded, set the threshold in seconds for reporting long-running examples (either user+system CPU time or elapsed time). Default: <code class="code">"5"</code>. </p> </dd> <dt><a id="index-_005fR_005fCHECK_005fEXAMPLE_005fTIMING_005fCPU_005fTO_005fELAPSED_005fTHRESHOLD_005f"></a><span><code class="code">_R_CHECK_EXAMPLE_TIMING_CPU_TO_ELAPSED_THRESHOLD_</code><a class="copiable-link" href="#index-_005fR_005fCHECK_005fEXAMPLE_005fTIMING_005fCPU_005fTO_005fELAPSED_005fTHRESHOLD_005f"> ¶</a></span></dt> <dd><p>For checks with timings enabled, report examples where the ratio of CPU time to elapsed time exceeds this threshold (and the CPU time is at least one second). This can help detect the simultaneous use of multiple CPU cores. Default: <code class="code">NA</code>. </p> </dd> <dt><a id="index-_005fR_005fCHECK_005fTEST_005fTIMING_005fCPU_005fTO_005fELAPSED_005fTHRESHOLD_005f"></a><span><code class="code">_R_CHECK_TEST_TIMING_CPU_TO_ELAPSED_THRESHOLD_</code><a class="copiable-link" href="#index-_005fR_005fCHECK_005fTEST_005fTIMING_005fCPU_005fTO_005fELAPSED_005fTHRESHOLD_005f"> ¶</a></span></dt> <dd><p>Report for running an individual test if the ratio of CPU time to elapsed time exceeds this threshold (and the CPU time is at least one second). Not supported on Windows. Default: <code class="code">NA</code>. </p> </dd> <dt><a id="index-_005fR_005fCHECK_005fVIGNETTE_005fTIMING_005fCPU_005fTO_005fELAPSED_005fTHRESHOLD_005f"></a><span><code class="code">_R_CHECK_VIGNETTE_TIMING_CPU_TO_ELAPSED_THRESHOLD_</code><a class="copiable-link" href="#index-_005fR_005fCHECK_005fVIGNETTE_005fTIMING_005fCPU_005fTO_005fELAPSED_005fTHRESHOLD_005f"> ¶</a></span></dt> <dd><p>Report if when running/re-building vignettes (individually or in aggregate) the ratio of CPU time to elapsed time exceeds this threshold (and the CPU time is at least one second). Not supported on Windows. Default: <code class="code">NA</code>. </p> </dd> <dt><a id="index-_005fR_005fCHECK_005fINSTALL_005fTIMING_005fCPU_005fTO_005fELAPSED_005fTHRESHOLD_005f"></a><span><code class="code">_R_CHECK_INSTALL_TIMING_CPU_TO_ELAPSED_THRESHOLD_</code><a class="copiable-link" href="#index-_005fR_005fCHECK_005fINSTALL_005fTIMING_005fCPU_005fTO_005fELAPSED_005fTHRESHOLD_005f"> ¶</a></span></dt> <dd><p>Report if for installation the ratio of CPU time to elapsed time exceeds this threshold (and the CPU time is at least one second). Not supported on Windows, only uses if <code class="code">_R_CHECK_TIMINGS_</code> is set Default: <code class="code">NA</code>. </p> </dd> <dt><a id="index-_005fR_005fCHECK_005fCODETOOLS_005fPROFILE_005f"></a><span><code class="code">_R_CHECK_CODETOOLS_PROFILE_</code><a class="copiable-link" href="#index-_005fR_005fCHECK_005fCODETOOLS_005fPROFILE_005f"> ¶</a></span></dt> <dd><p>A string with comma-separated <code class="code"><var class="var">name</var>=<var class="var">value</var></code> pairs (with <var class="var">value</var> a logical constant) giving additional arguments for the <a class="url" href="https://CRAN.R-project.org/package=codetools"><strong class="strong">codetools</strong></a> functions used for analyzing package code. E.g., use <code class="code">_R_CHECK_CODETOOLS_PROFILE_="suppressLocalUnused=FALSE"</code> to turn off suppressing warnings about unused local variables. Default: no additional arguments, corresponding to using <code class="code">skipWith = TRUE</code>, <code class="code">suppressPartialMatchArgs = FALSE</code> and <code class="code">suppressLocalUnused = TRUE</code>. </p> </dd> <dt><a id="index-_005fR_005fCHECK_005fCRAN_005fINCOMING_005f"></a><span><code class="code">_R_CHECK_CRAN_INCOMING_</code><a class="copiable-link" href="#index-_005fR_005fCHECK_005fCRAN_005fINCOMING_005f"> ¶</a></span></dt> <dd><p>Check whether package is suitable for publication on CRAN. Default: false, except for CRAN submission checks. </p> </dd> <dt><a id="index-_005fR_005fCHECK_005fCRAN_005fINCOMING_005fREMOTE_005f"></a><span><code class="code">_R_CHECK_CRAN_INCOMING_REMOTE_</code><a class="copiable-link" href="#index-_005fR_005fCHECK_005fCRAN_005fINCOMING_005fREMOTE_005f"> ¶</a></span></dt> <dd><p>Include checks that require remote access among the above. Default: same as <code class="code">_R_CHECK_CRAN_INCOMING_</code> </p> </dd> <dt><a id="index-_005fR_005fCHECK_005fXREFS_005fUSE_005fALIASES_005fFROM_005fCRAN_005f"></a><span><code class="code">_R_CHECK_XREFS_USE_ALIASES_FROM_CRAN_</code><a class="copiable-link" href="#index-_005fR_005fCHECK_005fXREFS_005fUSE_005fALIASES_005fFROM_005fCRAN_005f"> ¶</a></span></dt> <dd><p>When checking anchored Rd xrefs, use Rd aliases from the CRAN package web areas in addition to those in the packages installed locally. Default: false. </p> </dd> <dt><a id="index-_005fR_005fSHLIB_005fBUILD_005fOBJECTS_005fSYMBOL_005fTABLES_005f"></a><span><code class="code">_R_SHLIB_BUILD_OBJECTS_SYMBOL_TABLES_</code><a class="copiable-link" href="#index-_005fR_005fSHLIB_005fBUILD_005fOBJECTS_005fSYMBOL_005fTABLES_005f"> ¶</a></span></dt> <dd><p>Make the checks of compiled code more accurate by recording the symbol tables for objects (<samp class="file">.o</samp> files) at installation in a file <samp class="file">symbols.rds</samp>. (Only currently supported on Linux, Solaris, macOS, Windows and FreeBSD.) Default: true. </p> </dd> <dt><a id="index-_005fR_005fCHECK_005fCODE_005fASSIGN_005fTO_005fGLOBALENV_005f"></a><span><code class="code">_R_CHECK_CODE_ASSIGN_TO_GLOBALENV_</code><a class="copiable-link" href="#index-_005fR_005fCHECK_005fCODE_005fASSIGN_005fTO_005fGLOBALENV_005f"> ¶</a></span></dt> <dd><p>Should the package code be checked for assignments to the global environment? Default: false (but true for CRAN submission checks). </p> </dd> <dt><a id="index-_005fR_005fCHECK_005fCODE_005fATTACH_005f"></a><span><code class="code">_R_CHECK_CODE_ATTACH_</code><a class="copiable-link" href="#index-_005fR_005fCHECK_005fCODE_005fATTACH_005f"> ¶</a></span></dt> <dd><p>Should the package code be checked for calls to <code class="code">attach()</code>? Default: false (but true for CRAN submission checks). </p> </dd> <dt><a id="index-_005fR_005fCHECK_005fCODE_005fDATA_005fINTO_005fGLOBALENV_005f"></a><span><code class="code">_R_CHECK_CODE_DATA_INTO_GLOBALENV_</code><a class="copiable-link" href="#index-_005fR_005fCHECK_005fCODE_005fDATA_005fINTO_005fGLOBALENV_005f"> ¶</a></span></dt> <dd><p>Should the package code be checked for calls to <code class="code">data()</code> which load into the global environment? Default: false (but true for CRAN submission checks). </p> </dd> <dt><a id="index-_005fR_005fCHECK_005fDOT_005fFIRSTLIB_005f"></a><span><code class="code">_R_CHECK_DOT_FIRSTLIB_</code><a class="copiable-link" href="#index-_005fR_005fCHECK_005fDOT_005fFIRSTLIB_005f"> ¶</a></span></dt> <dd><p>Should the package code be checked for the presence of the obsolete function <code class="code">.First.lib()</code>? Default: false (but true for CRAN submission checks). </p> </dd> <dt><a id="index-_005fR_005fCHECK_005fDEPRECATED_005fDEFUNCT_005f"></a><span><code class="code">_R_CHECK_DEPRECATED_DEFUNCT_</code><a class="copiable-link" href="#index-_005fR_005fCHECK_005fDEPRECATED_005fDEFUNCT_005f"> ¶</a></span></dt> <dd><p>Should the package code be checked for the presence of recently deprecated or defunct functions (including completely removed functions). Also for platform-specific graphics devices. Default: false (but true for CRAN submission checks). </p> </dd> <dt><a id="index-_005fR_005fCHECK_005fSCREEN_005fDEVICE_005f"></a><span><code class="code">_R_CHECK_SCREEN_DEVICE_</code><a class="copiable-link" href="#index-_005fR_005fCHECK_005fSCREEN_005fDEVICE_005f"> ¶</a></span></dt> <dd><p>If set to ‘<samp class="samp">warn</samp>’, give a warning if examples etc open a screen device. If set to ‘<samp class="samp">stop</samp>’, give an error. Default: empty (but ‘<samp class="samp">stop</samp>’ for CRAN submission checks). </p> </dd> <dt><a id="index-_005fR_005fCHECK_005fWINDOWS_005fDEVICE_005f"></a><span><code class="code">_R_CHECK_WINDOWS_DEVICE_</code><a class="copiable-link" href="#index-_005fR_005fCHECK_005fWINDOWS_005fDEVICE_005f"> ¶</a></span></dt> <dd><p>If set to ‘<samp class="samp">stop</samp>’, give an error if a Windows-only device is used in example etc. This is only useful on Windows: the devices do not exist elsewhere. Default: empty (but ‘<samp class="samp">stop</samp>’ for CRAN submission checks on Windows). </p> </dd> <dt><a id="index-_005fR_005fCHECK_005fTOPLEVEL_005fFILES_005f"></a><span><code class="code">_R_CHECK_TOPLEVEL_FILES_</code><a class="copiable-link" href="#index-_005fR_005fCHECK_005fTOPLEVEL_005fFILES_005f"> ¶</a></span></dt> <dd><p>Report on top-level files in the package sources that are not described in ‘Writing R Extensions’ nor are commonly understood (like <samp class="file">ChangeLog</samp>). Variations on standard names (e.g. <samp class="file">COPYRIGHT</samp>) are also reported. Default: false (but true for CRAN submission checks). </p> </dd> <dt><a id="index-_005fR_005fCHECK_005fGCT_005fN_005f"></a><span><code class="code">_R_CHECK_GCT_N_</code><a class="copiable-link" href="#index-_005fR_005fCHECK_005fGCT_005fN_005f"> ¶</a></span></dt> <dd><p>Should the <samp class="option">--use-gct</samp> use <code class="code">gctorture2(<var class="var">n</var>)</code> rather than <code class="code">gctorture(TRUE)</code>? Use a positive integer to enable this. Default: <code class="code">0</code>. </p> </dd> <dt><a id="index-_005fR_005fCHECK_005fLIMIT_005fCORES_005f"></a><span><code class="code">_R_CHECK_LIMIT_CORES_</code><a class="copiable-link" href="#index-_005fR_005fCHECK_005fLIMIT_005fCORES_005f"> ¶</a></span></dt> <dd><p>If set, check the usage of too many cores in package <strong class="strong">parallel</strong>. If set to ‘<samp class="samp">warn</samp>’ gives a warning, to ‘<samp class="samp">false</samp>’ or ‘<samp class="samp">FALSE</samp>’ the check is skipped, and any other non-empty value gives an error when more than 2 children are spawned. Default: unset (but ‘<samp class="samp">TRUE</samp>’ for CRAN submission checks). </p> </dd> <dt><a id="index-_005fR_005fCHECK_005fCODE_005fUSAGE_005fVIA_005fNAMESPACES_005f"></a><span><code class="code">_R_CHECK_CODE_USAGE_VIA_NAMESPACES_</code><a class="copiable-link" href="#index-_005fR_005fCHECK_005fCODE_005fUSAGE_005fVIA_005fNAMESPACES_005f"> ¶</a></span></dt> <dd><p>If set, check code usage (via <a class="url" href="https://CRAN.R-project.org/package=codetools"><strong class="strong">codetools</strong></a>) directly on the package namespace without loading and attaching the package and its suggests and enhances. Default: true (and true for CRAN submission checks). </p> </dd> <dt><a id="index-_005fR_005fCHECK_005fCODE_005fUSAGE_005fWITH_005fONLY_005fBASE_005fATTACHED_005f"></a><span><code class="code">_R_CHECK_CODE_USAGE_WITH_ONLY_BASE_ATTACHED_</code><a class="copiable-link" href="#index-_005fR_005fCHECK_005fCODE_005fUSAGE_005fWITH_005fONLY_005fBASE_005fATTACHED_005f"> ¶</a></span></dt> <dd><p>If set, check code usage (via <a class="url" href="https://CRAN.R-project.org/package=codetools"><strong class="strong">codetools</strong></a>) with only the base package attached. Default: true. </p> </dd> <dt><a id="index-_005fR_005fCHECK_005fEXIT_005fON_005fFIRST_005fERROR_005f"></a><span><code class="code">_R_CHECK_EXIT_ON_FIRST_ERROR_</code><a class="copiable-link" href="#index-_005fR_005fCHECK_005fEXIT_005fON_005fFIRST_005fERROR_005f"> ¶</a></span></dt> <dd><p>If set to a true value, the check will exit on the first error. Default: false. </p> </dd> <dt><a id="index-_005fR_005fCHECK_005fOVERWRITE_005fREGISTERED_005fS3_005fMETHODS_005f"></a><span><code class="code">_R_CHECK_OVERWRITE_REGISTERED_S3_METHODS_</code><a class="copiable-link" href="#index-_005fR_005fCHECK_005fOVERWRITE_005fREGISTERED_005fS3_005fMETHODS_005f"> ¶</a></span></dt> <dd><p>If set to a true value, report already registered S3 methods in base/recommended packages which are overwritten when this package’s namespace is loaded. Default: false (but true for CRAN submission checks). </p> </dd> <dt><a id="index-_005fR_005fCHECK_005fTESTS_005fNLINES_005f"></a><span><code class="code">_R_CHECK_TESTS_NLINES_</code><a class="copiable-link" href="#index-_005fR_005fCHECK_005fTESTS_005fNLINES_005f"> ¶</a></span></dt> <dd><p>Number of trailing lines of test output to reproduce in the log. If <code class="code">0</code> all lines except the R preamble are reproduced. Default: 13. </p> </dd> <dt><a id="index-_005fR_005fCHECK_005fNATIVE_005fROUTINE_005fREGISTRATION_005f"></a><span><code class="code">_R_CHECK_NATIVE_ROUTINE_REGISTRATION_</code><a class="copiable-link" href="#index-_005fR_005fCHECK_005fNATIVE_005fROUTINE_005fREGISTRATION_005f"> ¶</a></span></dt> <dd><p>If set to a true value, report if the entry points to register native routines and to suppress dynamic search are not found in a package’s DLL. (<strong class="strong">NB:</strong> this requires system command <code class="command">nm</code> to be on the <code class="env">PATH</code>. On Windows, <code class="command">objdump.exe</code> is first searched for in compiler toolchain specified via <code class="code">Makeconf</code> (can be customized by environment variable <code class="env">BINPREF</code>). If not found there, it must be on the <code class="env">PATH</code>. On Unix this would be normal when using a package with compiled code (which are the only ones this checks), but Windows’ users should check. Default: false (but true for CRAN submission checks). </p> </dd> <dt><a id="index-_005fR_005fCHECK_005fNO_005fSTOP_005fON_005fTEST_005fERROR_005f"></a><span><code class="code">_R_CHECK_NO_STOP_ON_TEST_ERROR_</code><a class="copiable-link" href="#index-_005fR_005fCHECK_005fNO_005fSTOP_005fON_005fTEST_005fERROR_005f"> ¶</a></span></dt> <dd><p>If set to a true value, do not stop running tests after first error (as if command line option <samp class="option">--no-stop-on-test-error</samp> had been given). Default: false (but true for CRAN submission checks). </p> </dd> <dt><a id="index-_005fR_005fCHECK_005fPRAGMAS_005f"></a><span><code class="code">_R_CHECK_PRAGMAS_</code><a class="copiable-link" href="#index-_005fR_005fCHECK_005fPRAGMAS_005f"> ¶</a></span></dt> <dd><p>Run additional checks on the pragmas in C/C++ source code and headers. Default: false (but true for CRAN submission checks). </p> </dd> <dt><a id="index-_005fR_005fCHECK_005fCOMPILATION_005fFLAGS_005f"></a><span><code class="code">_R_CHECK_COMPILATION_FLAGS_</code><a class="copiable-link" href="#index-_005fR_005fCHECK_005fCOMPILATION_005fFLAGS_005f"> ¶</a></span></dt> <dd><p>If the package is installed and has C/C++/Fortran code, check the install log for non-portable flags (for example those added to <samp class="file">src/Makevars</samp> during configuration). Currently <samp class="option">-W</samp> flags are reported, except <samp class="option">-Wall</samp>, <samp class="option">-Wextra</samp> and <samp class="option">-Weverything</samp>, and flags which appear to be attempts to suppress warnings are highlighted. See <a data-manual="R-exts" href="https://cran.r-project.org/doc/manuals/R-exts.html#Writing-portable-packages">Writing portable packages</a> in <cite class="cite">Writing R Extensions</cite> for the rationale of this check (and why even <samp class="option">-Werror</samp> is unsafe). </p> <p>Environment variable <code class="env">_R_CHECK_COMPILATION_FLAGS_KNOWN_</code> can be set to a space-separated set of flags which come from the R build used for testing (flags such as <samp class="option">-Wall</samp> and <samp class="option">-Wextra</samp> are already known). For example, for CRAN builds of R >= 4.0.0 on macOS one could use </p><div class="example"> <pre class="example-preformatted">_R_CHECK_COMPILATION_FLAGS_KNOWN_="-mmacosx-version-min=10.13" </pre></div> <p>Default: unset. </p> </dd> <dt><a id="index-_005fR_005fCHECK_005fR_005fDEPENDS_005f"></a><span><code class="code">_R_CHECK_R_DEPENDS_</code><a class="copiable-link" href="#index-_005fR_005fCHECK_005fR_005fDEPENDS_005f"> ¶</a></span></dt> <dd><p>Check that any dependence on R is not on a recent patch-level version such as <code class="code">R (>= 3.3.3)</code> since blocking installation of a package will also block its reverse dependencies. Possible values ‘<samp class="samp">"note"</samp>’, ‘<samp class="samp">"warn"</samp>’ and logical values (where currently true values are equivalent to ‘<samp class="samp">"note"</samp>’). Default: false (but ‘<samp class="samp">"warn"</samp>’ for <samp class="option">--as-cran</samp>). </p> </dd> <dt><a id="index-_005fR_005fCHECK_005fSERIALIZATION_005f"></a><span><code class="code">_R_CHECK_SERIALIZATION_</code><a class="copiable-link" href="#index-_005fR_005fCHECK_005fSERIALIZATION_005f"> ¶</a></span></dt> <dd><p>Check that serialized R objects in the package sources were serialized with version 2 and there is no dependence on ‘<samp class="samp">R >= 3.5.0</samp>’. (Version 3 is in use as from R 3.5.0 but should only be used when necessary.) Default: false (but true for CRAN submission checks). </p> </dd> <dt><a id="index-_005fR_005fCHECK_005fR_005fON_005fPATH_005f"></a><span><code class="code">_R_CHECK_R_ON_PATH_</code><a class="copiable-link" href="#index-_005fR_005fCHECK_005fR_005fON_005fPATH_005f"> ¶</a></span></dt> <dd><p>This checks if the package attempts to use <code class="command">R</code> or <code class="command">Rscript</code> from the path rather than that under test. It does so by putting scripts at the head of the path which print a message and fail. Default: false (but true for CRAN submission checks). </p> </dd> <dt><a id="index-_005fR_005fCHECK_005fPACKAGES_005fUSED_005fIN_005fTESTS_005fUSE_005fSUBDIRS_005f"></a><span><code class="code">_R_CHECK_PACKAGES_USED_IN_TESTS_USE_SUBDIRS_</code><a class="copiable-link" href="#index-_005fR_005fCHECK_005fPACKAGES_005fUSED_005fIN_005fTESTS_005fUSE_005fSUBDIRS_005f"> ¶</a></span></dt> <dd><p>If set to a true value, also check the R code in common unit test subdirectories of <samp class="file">tests</samp> for undeclared package dependencies. Default: false (but true for CRAN submission checks). </p> </dd> <dt><a id="index-_005fR_005fCHECK_005fSHLIB_005fOPENMP_005fFLAGS_005f"></a><span><code class="code">_R_CHECK_SHLIB_OPENMP_FLAGS_</code><a class="copiable-link" href="#index-_005fR_005fCHECK_005fSHLIB_005fOPENMP_005fFLAGS_005f"> ¶</a></span></dt> <dd><p>Check correct and portable use of <code class="code">SHLIB_OPENMP_*FLAGS</code> in <samp class="file">src/Makevars</samp> (and similar). Default: false (but true for CRAN submission checks). </p> </dd> <dt><a id="index-_005fR_005fCHECK_005fCONNECTIONS_005fLEFT_005fOPEN_005f"></a><span><code class="code">_R_CHECK_CONNECTIONS_LEFT_OPEN_</code><a class="copiable-link" href="#index-_005fR_005fCHECK_005fCONNECTIONS_005fLEFT_005fOPEN_005f"> ¶</a></span></dt> <dd><p>When checking examples, check for each example if connections are left open: if any are found, this is reported with a fatal error. NB: ‘connections’ includes most use of files and any parallel clusters which have not be stopped by <code class="code">stopCluster()</code>. Default: false (but true for CRAN submission checks). </p> </dd> <dt><a id="index-_005fR_005fCHECK_005fFUTURE_005fFILE_005fTIMESTAMPS_005f"></a><span><code class="code">_R_CHECK_FUTURE_FILE_TIMESTAMPS_</code><a class="copiable-link" href="#index-_005fR_005fCHECK_005fFUTURE_005fFILE_005fTIMESTAMPS_005f"> ¶</a></span></dt> <dd><p>Check if any of the input files has a timestamp in the future (and to do so, checks that the system clock is correct to within 5 minutes). Default: false (but true for CRAN submission checks). </p> </dd> <dt><a id="index-_005fR_005fCHECK_005fLENGTH_005f1_005fCONDITION_005f"></a><span><code class="code">_R_CHECK_LENGTH_1_CONDITION_</code><a class="copiable-link" href="#index-_005fR_005fCHECK_005fLENGTH_005f1_005fCONDITION_005f"> ¶</a></span></dt> <dd><p>No longer in use: conditions of length greater than one in <code class="code">if</code> or <code class="code">while</code> statements are now an error. </p> </dd> <dt><a id="index-_005fR_005fCHECK_005fVIGNETTES_005fSKIP_005fRUN_005fMAYBE_005f"></a><span><code class="code">_R_CHECK_VIGNETTES_SKIP_RUN_MAYBE_</code><a class="copiable-link" href="#index-_005fR_005fCHECK_005fVIGNETTES_005fSKIP_005fRUN_005fMAYBE_005f"> ¶</a></span></dt> <dd><p>Should running the R code in the vignettes be skipped if vignette outputs are to be rebuilt (which will involve running that code). Default: true. </p> </dd> <dt><a id="index-_005fR_005fCHECK_005fBUILD_005fVIGNETTES_005fSEPARATELY_005f"></a><span><code class="code">_R_CHECK_BUILD_VIGNETTES_SEPARATELY_</code><a class="copiable-link" href="#index-_005fR_005fCHECK_005fBUILD_005fVIGNETTES_005fSEPARATELY_005f"> ¶</a></span></dt> <dd><p>Prior to R 3.6.0, re-building the vignette outputs was done in a single R session which allowed accidental reliance of one vignette on another (for example, in the loading of packages). The current default is to use a separate session for each vignette; this option allows testing the older behaviour, Default: true. </p> </dd> <dt><a id="index-_005fR_005fCHECK_005fSYSTEM_005fCLOCK_005f"></a><span><code class="code">_R_CHECK_SYSTEM_CLOCK_</code><a class="copiable-link" href="#index-_005fR_005fCHECK_005fSYSTEM_005fCLOCK_005f"> ¶</a></span></dt> <dd><p>As part of the ‘checking for future file timestamps’ enabled by <samp class="option">--as-cran</samp>, check the system clock against an external clock to catch errors such as the wrong day or even year. Not necessary on systems doing repeated checks. Default: true (but false for CRAN checking). </p> </dd> <dt><a id="index-_005fR_005fCHECK_005fAUTOCONF_005f"></a><span><code class="code">_R_CHECK_AUTOCONF_</code><a class="copiable-link" href="#index-_005fR_005fCHECK_005fAUTOCONF_005f"> ¶</a></span></dt> <dd><p>For packages with a <samp class="file">configure</samp> file generated by GNU <code class="command">autoconf</code> and either <samp class="file">configure.ac</samp> or <samp class="file">configure,.in</samp>, check that <code class="command">autoreconf</code> can, if available, be run in a copy of the sources (this will detect missing source files and report <code class="command">autoconf</code> warnings). Environment variable <code class="env">AUTORECONf</code> controls the command used: it can give the full path to <code class="command">autoreconf</code> (without spaces) and can include flags such as <samp class="option">--warnings=obsolete</samp> (which is added for <code class="command">autoreconf</code> version 2.68 or 2.69 and is the default for later versions). Default: false (but true for CRAN submission checks). </p> </dd> <dt><a id="index-_005fR_005fCHECK_005fDATALIST_005f"></a><span><code class="code">_R_CHECK_DATALIST_</code><a class="copiable-link" href="#index-_005fR_005fCHECK_005fDATALIST_005f"> ¶</a></span></dt> <dd><p>Check whether file <samp class="file">data/datalist</samp> is out-of-date. Default: false (but true for CRAN submission checks). </p> </dd> <dt><a id="index-_005fR_005fCHECK_005fTHINGS_005fIN_005fCHECK_005fDIR_005f"></a><span><code class="code">_R_CHECK_THINGS_IN_CHECK_DIR_</code><a class="copiable-link" href="#index-_005fR_005fCHECK_005fTHINGS_005fIN_005fCHECK_005fDIR_005f"> ¶</a></span></dt> <dd><p>Check and report at the end of the check run if files have been left in the check directory. Default: false (but true for CRAN submission checks). </p> </dd> <dt><a id="index-_005fR_005fCHECK_005fTHINGS_005fIN_005fTEMP_005fDIR_005f"></a><span><code class="code">_R_CHECK_THINGS_IN_TEMP_DIR_</code><a class="copiable-link" href="#index-_005fR_005fCHECK_005fTHINGS_005fIN_005fTEMP_005fDIR_005f"> ¶</a></span></dt> <dd><p>Check and report at the end of the check run if files would have been left in the temporary directory (usually <samp class="file">/tmp</samp> on a Unix-alike). It does this by setting the environment variable <code class="env">TEMPDIR</code> to a subdirectory of the R session directory for the <code class="code">check</code> process: if any files or directories are left there they are removed. Since some of these might be out of the user’s control, environment variable <code class="env">_R_CHECK_THINGS_IN_TEMP_DIR_EXCLUDE_</code> can specify an (extended regex) pattern of file paths not to be reported – CRAN uses ‘<samp class="samp">^ompi.</samp>’ for directories left behind by OpenMPI. There are rare instances where <code class="env">TEMPDIR</code> is not respected and so files are left in <samp class="file">/tmp</samp> (and not reported, but see the next item): one example is <samp class="file">/tmp/boost_interprocess</samp> on some OSes. Default: false (but true for CRAN submission checks). </p> </dd> <dt><a id="index-_005fR_005fCHECK_005fTHINGS_005fIN_005fOTHER_005fDIRS_005f"></a><span><code class="code">_R_CHECK_THINGS_IN_OTHER_DIRS_</code><a class="copiable-link" href="#index-_005fR_005fCHECK_005fTHINGS_005fIN_005fOTHER_005fDIRS_005f"> ¶</a></span></dt> <dd><p>Check and report at the end of the check run if new files or directories are created in a selected set of directories during the check run. (This is confined to files owned by the user running the check process.) Currently the directories monitored are the home directory, <samp class="file">/tmp</samp> (excluding <samp class="file">RtmpXXXXXX</samp> directories), <samp class="file">/dav/shm</samp>, <samp class="file">~/.cache</samp> (recursively) and <samp class="file">~/.local/share</samp> (recursively) or their equivalents on Windows and macOS (the directories in which the default settings for <code class="code">tools::R_user_dir()</code> use a <samp class="file">R</samp> subdirectory). Additional directories can be specified in environment variable <code class="env">_R_CHECK_THINGS_IN_OTHER_DIRS_XTRA_</code>, separated by semicolons. Directories are reported with a trailing ‘<samp class="samp">/</samp>’ on all platforms. </p> <p>Environment variable <code class="env">_R_CHECK_THINGS_IN_OTHER_DIRS_EXCLUDE_</code> can specify an (extended regex) pattern of file paths not to be reported – this should match absolute file paths with home represented by <samp class="file">~</samp>. For example, on a Linux system </p><div class="example"> <pre class="example-preformatted">'^~/.cache/(mozilla/firefox|mesa_shader_cache)/' </pre></div> <p>matches cache directories used by Firefox and OpenGL (and their content). If the value starts with ‘<samp class="samp">@</samp>’ it is considered as a filepath which is read with each line treated as a pattern to be matched. </p> <p>Note that other processes (include check runs in parallel) may create new files in these directories which will get reported. However, this optional check is very useful for narrowing down possible packages which are leaving behind unexpected files. Default: false </p> </dd> <dt><a id="index-_005fR_005fCHECK_005fBASHISMS_005f"></a><span><code class="code">_R_CHECK_BASHISMS_</code><a class="copiable-link" href="#index-_005fR_005fCHECK_005fBASHISMS_005f"> ¶</a></span></dt> <dd><p>Check the top-level scripts <samp class="file">configure</samp> (unless generated by <samp class="file">autoconf</samp>) and <samp class="file">cleanup</samp> for non-Bourne-shell code, using the Perl script <code class="command">checkbashisms</code> if available. This includes reporting scripts using the non-portable <code class="code">#! /bin/bash</code>. (Script <code class="command">checkbashisms</code> is available in most Linux distributions in a package named either ‘<samp class="samp">devscripts</samp>’ or ‘<samp class="samp">devscripts-checkbashisms</samp>’ and from <a class="uref" href="https://sourceforge.net/projects/checkbaskisms/files">https://sourceforge.net/projects/checkbaskisms/files</a>.) Default: false (but true for CRAN submission checks except on Windows). </p> </dd> <dt><a id="index-_005fR_005fCHECK_005fORPHANED_005f"></a><span><code class="code">_R_CHECK_ORPHANED_</code><a class="copiable-link" href="#index-_005fR_005fCHECK_005fORPHANED_005f"> ¶</a></span></dt> <dd><p>Check if dependencies are orphaned packages. As from R 4.1.0 this checks strict dependencies recursively, so will report any orphaned packages which are needed to attach the package by <code class="code">library()</code> as well as any orphaned packages which are suggested. Default: false (but true for CRAN submission checks). </p> </dd> <dt><a id="index-_005fR_005fCHECK_005fEXCESSIVE_005fIMPORTS_005f"></a><span><code class="code">_R_CHECK_EXCESSIVE_IMPORTS_</code><a class="copiable-link" href="#index-_005fR_005fCHECK_005fEXCESSIVE_005fIMPORTS_005f"> ¶</a></span></dt> <dd><p>A positive integer. If set, give a NOTE if the number of imports from non-base packages exceed this threshold. Large numbers of imports make a package vulnerable to any of them becoming unavailable. Default: unset (but 20 for CRAN submission checks) </p> </dd> <dt><a id="index-_005fR_005fCHECK_005fDONTTEST_005fEXAMPLES_005f"></a><span><code class="code">_R_CHECK_DONTTEST_EXAMPLES_</code><a class="copiable-link" href="#index-_005fR_005fCHECK_005fDONTTEST_005fEXAMPLES_005f"> ¶</a></span></dt> <dd><p>If true and examples are found with <code class="code">\donttest</code> sections, the tests are run in one pass with these commented out and then in a second pass including the <code class="code">\donttest</code> sections, (for the main architecture only). Only for the first pass are the results compared to any <samp class="file">.Rout.save</samp> file and timings analysed. Overridden by <samp class="option">--run-donttest</samp>. Default: false unless <samp class="option">--as-cran</samp> is specified (which can be overridden by setting ‘<samp class="samp">_R_CHECK_DONTTEST_EXAMPLES_=false</samp>’). </p> </dd> <dt><a id="index-_005fR_005fCHECK_005fXREFS_005fPKGS_005fARE_005fDECLARED_005f"></a><span><code class="code">_R_CHECK_XREFS_PKGS_ARE_DECLARED_</code><a class="copiable-link" href="#index-_005fR_005fCHECK_005fXREFS_005fPKGS_005fARE_005fDECLARED_005f"> ¶</a></span></dt> <dd><p>Check if packages used in ‘anchored’ cross-references in <samp class="file">.Rd</samp> files (those of the form <code class="code">\link[<var class="var">pkg</var>]{<var class="var">foo</var>}</code> and <code class="code">\link[<var class="var">pkg:bar</var>]{<var class="var">foo</var>}</code>) are declared in the <samp class="file">DESCRIPTION</samp> file and so these links can be checked. Default: false. </p> </dd> <dt><a id="index-_005fR_005fCHECK_005fXREFS_005fMIND_005fSUSPECT_005fANCHORS_005f"></a><span><code class="code">_R_CHECK_XREFS_MIND_SUSPECT_ANCHORS_</code><a class="copiable-link" href="#index-_005fR_005fCHECK_005fXREFS_005fMIND_005fSUSPECT_005fANCHORS_005f"> ¶</a></span></dt> <dd><p>Check if package-anchored Rd cross-references are to <em class="emph">files</em> (and not aliases). Default: false. </p> </dd> <dt><a id="index-_005fR_005fCHECK_005fBOGUS_005fRETURN_005f"></a><span><code class="code">_R_CHECK_BOGUS_RETURN_</code><a class="copiable-link" href="#index-_005fR_005fCHECK_005fBOGUS_005fRETURN_005f"> ¶</a></span></dt> <dd><p>If true and <code class="env">_R_CHECK_USE_CODETOOLS_</code> is also true, functions are scanned for use of <code class="code">return</code> rather than <code class="code">return()</code>. Default: false (but true for CRAN submission checks). </p> </dd> <dt><a id="index-_005fR_005fCHECK_005fMATRIX_005fDATA_005f"></a><span><code class="code">_R_CHECK_MATRIX_DATA_</code><a class="copiable-link" href="#index-_005fR_005fCHECK_005fMATRIX_005fDATA_005f"> ¶</a></span></dt> <dd><p>By default, the check for a mismatch between the data length and the dimensions in a call to <code class="code">matrix</code> gives a warning: setting this to a true value gives an error with a compact traceback. Default: false (but true for CRAN submission checks). </p> </dd> <dt><a id="index-_005fR_005fCHECK_005fCODE_005fCLASS_005fIS_005fSTRING_005f"></a><span><code class="code">_R_CHECK_CODE_CLASS_IS_STRING_</code><a class="copiable-link" href="#index-_005fR_005fCHECK_005fCODE_005fCLASS_005fIS_005fSTRING_005f"> ¶</a></span></dt> <dd><p>Check if package code has <code class="code">if()</code> condition which compare the class of an object to a string. See <a class="uref" href="https://blog.r-project.org/2019/11/09/when-you-think-class.-think-again/">https://blog.r-project.org/2019/11/09/when-you-think-class.-think-again/</a> why this is a bad idea. Default: false (but true for CRAN submission checks). </p> </dd> <dt><a id="index-_005fR_005fCHECK_005fRD_005fVALIDATE_005fRD2HTML_005f"></a><span><code class="code">_R_CHECK_RD_VALIDATE_RD2HTML_</code><a class="copiable-link" href="#index-_005fR_005fCHECK_005fRD_005fVALIDATE_005fRD2HTML_005f"> ¶</a></span></dt> <dd><p>Check the validity of the package HTML help pages using HTML Tidy (<a class="uref" href="https://www.html-tidy.org/">https://www.html-tidy.org/</a>) (if a suitable version is available on the system path for executables or its path is specified by environment variable <code class="env">R_TIDYCMD</code>). macOS users are advised to install 5.8.0 or later from <a class="uref" href="https://binaries.html-tidy.org/">https://binaries.html-tidy.org/</a>. Default: false (but true for CRAN submission checks). <samp class="option">--as-cran</samp> can be overridden by setting this variable to a false value. </p> </dd> <dt><a id="index-_005fR_005fCHECK_005fRD_005fMATH_005fRENDERING_005f"></a><span><code class="code">_R_CHECK_RD_MATH_RENDERING_</code><a class="copiable-link" href="#index-_005fR_005fCHECK_005fRD_005fMATH_005fRENDERING_005f"> ¶</a></span></dt> <dd><p>Check whether HTML math rendering via KaTeX works (if package <a class="url" href="https://CRAN.R-project.org/package=V8"><strong class="strong">V8</strong></a> is available). See <a class="uref" href="https://blog.r-project.org/2022/04/08/enhancements-to-html-documentation/">https://blog.r-project.org/2022/04/08/enhancements-to-html-documentation/</a>. Default: false (but true for CRAN submission checks). </p> </dd> <dt><a id="index-_005fR_005fCHECK_005fNEWS_005fIN_005fPLAIN_005fTEXT_005f"></a><span><code class="code">_R_CHECK_NEWS_IN_PLAIN_TEXT_</code><a class="copiable-link" href="#index-_005fR_005fCHECK_005fNEWS_005fIN_005fPLAIN_005fTEXT_005f"> ¶</a></span></dt> <dd><p>Check whether <code class="code">news()</code> can successfully read package news in plain text (file <samp class="file">NEWS</samp>) format. Default: false (but true for CRAN submission checks). </p> </dd> <dt><a id="index-_005fR_005fWIN_005fCHECK_005fINVALID_005fPARAMETERS_005f"></a><span><code class="code">_R_WIN_CHECK_INVALID_PARAMETERS_</code><a class="copiable-link" href="#index-_005fR_005fWIN_005fCHECK_005fINVALID_005fPARAMETERS_005f"> ¶</a></span></dt> <dd><p>Check whether arguments passed to the Windows C runtime are valid. When enabled and a C runtime function is called with an invalid parameter, R prints diagnostic information and unconditionally terminates. By default, R for Windows following MinGW-W64 default causes <abbr class="abbr">UCRT</abbr> to ignore invalid parameters, but they may cause R to abort e.g. when R is embedded into applications built with a different compiler toolchain. One may set the value to <code class="code">"watson"</code> for interactive debugging on Windows via <code class="code">_invoke_watson</code>. Default: disabled. </p> </dd> <dt><a id="index-_005fR_005fCHECK_005fBROWSER_005fNONINTERACTIVE_005f"></a><span><code class="code">_R_CHECK_BROWSER_NONINTERACTIVE_</code><a class="copiable-link" href="#index-_005fR_005fCHECK_005fBROWSER_005fNONINTERACTIVE_005f"> ¶</a></span></dt> <dd><p>If set to a true value, trap non-interactive debugger invocations. These are most likely caused by leftover <code class="code">browser()</code> statements in package code. Default: unset (but true for CRAN submission checks). </p> </dd> <dt><a id="index-_005fR_005fCHECK_005fURLS_005fSHOW_005f301_005fSTATUS_005f"></a><span><code class="code">_R_CHECK_URLS_SHOW_301_STATUS_</code><a class="copiable-link" href="#index-_005fR_005fCHECK_005fURLS_005fSHOW_005f301_005fSTATUS_005f"> ¶</a></span></dt> <dd><p>If set to a true value, checking URLs show check status 301 for HTTP response status code “301 Moved Permanently”. Default: false (but true for CRAN submission checks). </p> </dd> <dt><a id="index-_005fR_005fCHECK_005fUNDOC_005fUSE_005fALL_005fNAMES_005f"></a><span><code class="code">_R_CHECK_UNDOC_USE_ALL_NAMES_</code><a class="copiable-link" href="#index-_005fR_005fCHECK_005fUNDOC_005fUSE_005fALL_005fNAMES_005f"> ¶</a></span></dt> <dd><p>If set to a true value, checking for undocumented objects does not ignore objects with names starting with a dot (which prior to the advent of namespaces conventionally were considered as “internal”). Default: false (but true for CRAN submission checks). </p> </dd> <dt><a id="index-_005fR_005fCHECK_005fS3_005fMETHODS_005fSHOW_005fPOSSIBLE_005fISSUES_005f"></a><span><code class="code">_R_CHECK_S3_METHODS_SHOW_POSSIBLE_ISSUES_</code><a class="copiable-link" href="#index-_005fR_005fCHECK_005fS3_005fMETHODS_005fSHOW_005fPOSSIBLE_005fISSUES_005f"> ¶</a></span></dt> <dd><p>Default: false (but true for CRAN submission checks). If set to a true value, checking S3 methods also notes “possible issues”, including issues with apparent methods not registered and methods registered for non-generics. Default: false (but true for CRAN submission checks). </p> </dd> <dt><a id="index-_005fR_005fCHECK_005fMBCS_005fCONVERSION_005fFAILURE_005f"></a><span><code class="code">_R_CHECK_MBCS_CONVERSION_FAILURE_</code><a class="copiable-link" href="#index-_005fR_005fCHECK_005fMBCS_005fCONVERSION_005fFAILURE_005f"> ¶</a></span></dt> <dd><p>If set to a non-empty value, makes warnings from <code class="code">pdf()</code> and <code class="code">postscript()</code> about conversion failures from an <abbr class="abbr">MBCS</abbr> (usually UTF-8) into errors. Unless the value is ‘<samp class="samp">silent</samp>’, when the warnings are suppressed. Default: unset (but true for CRAN submission checks). </p> </dd> <dt><a id="index-_005fR_005fCHECK_005fVALIDATE_005fUTF8_005f"></a><span><code class="code">_R_CHECK_VALIDATE_UTF8_</code><a class="copiable-link" href="#index-_005fR_005fCHECK_005fVALIDATE_005fUTF8_005f"> ¶</a></span></dt> <dd><p>If set to a non-empty value, makes installation warnings about non-UTF-8 strings in a package’s code (<samp class="file">R/.*R</samp>) and help (<samp class="file">man/*.Rd</samp>) files into errors. On most platforms invalid bytes in these files get converted to escapes (see <code class="code">iconv(sub = "byte")</code>), but on others these lead to installation failure. Default: unset (but true for CRAN submission checks). </p></dd> </dl> <p>The following variables control checks for undeclared/unconditional use of other packages. They work by setting up a temporary library directory and setting <code class="code">.libPaths()</code> to just that and <code class="code">.Library</code>, so are only effective if additional packages are installed somewhere other than <code class="code">.Library</code>. The temporary library is populated by symbolic links<a class="footnote" id="DOCF22" href="#FOOT22"><sup>22</sup></a> to installed packages not also in <code class="code">.Library</code>. </p> <dl class="vtable"> <dt><a id="index-_005fR_005fCHECK_005fINSTALL_005fDEPENDS_005f"></a><span><code class="code">_R_CHECK_INSTALL_DEPENDS_</code><a class="copiable-link" href="#index-_005fR_005fCHECK_005fINSTALL_005fDEPENDS_005f"> ¶</a></span></dt> <dd><p>If set to a true value and a test installation is to be done, this is done with a temporary library populated by all the Depends/Imports/LinkingTo packages. Default: false (but true for CRAN submission checks). </p> <p>Note that this is actually implemented in <code class="command">R CMD INSTALL</code>, so it is available to those who first install recording to a log, then call <code class="command">R CMD check</code>. </p> </dd> <dt><a id="index-_005fR_005fCHECK_005fSUGGESTS_005fONLY_005f"></a><span><code class="code">_R_CHECK_SUGGESTS_ONLY_</code><a class="copiable-link" href="#index-_005fR_005fCHECK_005fSUGGESTS_005fONLY_005f"> ¶</a></span></dt> <dd><p>If set to a true value, running examples, tests and vignettes is done with a temporary library directory populated by all the Depends/Imports/Suggests packages. (As exceptions, packages in a ‘<samp class="samp">VignetteBuilder</samp>’ field are always made available.) Default: false (but true for CRAN submission checks: some of the regular checks use true and some use false). </p> </dd> <dt><a id="index-_005fR_005fCHECK_005fDEPENDS_005fONLY_005f"></a><span><code class="code">_R_CHECK_DEPENDS_ONLY_</code><a class="copiable-link" href="#index-_005fR_005fCHECK_005fDEPENDS_005fONLY_005f"> ¶</a></span></dt> <dd><p>As for <code class="env">_R_CHECK_SUGGESTS_ONLY_</code> but using only Depends/Imports (and the exceptions, including test-suite managers in ‘<samp class="samp">Suggests</samp>’). Default: false </p> </dd> <dt><a id="index-_005fR_005fCHECK_005fDEPENDS_005fONLY_005fDATA_005f"></a><span><code class="code">_R_CHECK_DEPENDS_ONLY_DATA_</code><a class="copiable-link" href="#index-_005fR_005fCHECK_005fDEPENDS_005fONLY_005fDATA_005f"> ¶</a></span></dt> <dd><p>Apply <code class="env">_R_CHECK_DEPENDS_ONLY_</code> only to the check of loading from the <samp class="file">data</samp> directory, so checks if any dataset depends on packages which are in Suggests or undeclared. Default: false (but true for CRAN submission checks) </p> </dd> <dt><a id="index-_005fR_005fCHECK_005fDEPENDS_005fONLY_005fEXAMPLES_005f"></a><span><code class="code">_R_CHECK_DEPENDS_ONLY_EXAMPLES_</code><a class="copiable-link" href="#index-_005fR_005fCHECK_005fDEPENDS_005fONLY_005fEXAMPLES_005f"> ¶</a></span></dt> <dt><a id="index-_005fR_005fCHECK_005fDEPENDS_005fONLY_005fTESTS_005f"></a><span><code class="code">_R_CHECK_DEPENDS_ONLY_TESTS_</code><a class="copiable-link" href="#index-_005fR_005fCHECK_005fDEPENDS_005fONLY_005fTESTS_005f"> ¶</a></span></dt> <dt><a id="index-_005fR_005fCHECK_005fDEPENDS_005fONLY_005fVIGNETTES_005f"></a><span><code class="code">_R_CHECK_DEPENDS_ONLY_VIGNETTES_</code><a class="copiable-link" href="#index-_005fR_005fCHECK_005fDEPENDS_005fONLY_005fVIGNETTES_005f"> ¶</a></span></dt> <dd><p>Apply <code class="env">_R_CHECK_DEPENDS_ONLY_</code> only to the checking of examples, tests or vignettes. These can be used on their own, or with a false value to override <code class="env">_R_CHECK_DEPENDS_ONLY_</code>. Default: the value of <code class="env">_R_CHECK_DEPENDS_ONLY_</code> or false if that is unset. </p> </dd> <dt><a id="index-_005fR_005fCHECK_005fNO_005fRECOMMENDED_005f"></a><span><code class="code">_R_CHECK_NO_RECOMMENDED_</code><a class="copiable-link" href="#index-_005fR_005fCHECK_005fNO_005fRECOMMENDED_005f"> ¶</a></span></dt> <dd><p>If set to a true value, augment the previous checks to make recommended packages unavailable unless declared (even if installed in <code class="code">.Library</code>). Default: false (but true for CRAN submission checks). </p> <p>This may give false positives on code which uses <code class="code">grDevices::densCols</code> and <code class="code">stats:::.asSparse</code> / <code class="code">stats:::.Diag</code> as these invoke <a class="url" href="https://CRAN.R-project.org/package=KernSmooth"><strong class="strong">KernSmooth</strong></a> and <a class="url" href="https://CRAN.R-project.org/package=Matrix"><strong class="strong">Matrix</strong></a> respectively. (Those in <strong class="strong">stats</strong> are called from various contrasts functions if <code class="code">sparse = TRUE</code> is used.) </p></dd> </dl> <p>The CRAN submission checks use something like </p> <div class="example"> <pre class="example-preformatted">_R_CHECK_CRAN_INCOMING_=TRUE _R_CHECK_CRAN_INCOMING_REMOTE_=TRUE _R_CHECK_VC_DIRS_=TRUE _R_CHECK_TIMINGS_=10 _R_CHECK_INSTALL_DEPENDS_=TRUE _R_CHECK_SUGGESTS_ONLY_=TRUE _R_CHECK_NO_RECOMMENDED_=TRUE _R_CHECK_EXECUTABLES_EXCLUSIONS_=FALSE _R_CHECK_DOC_SIZES2_=TRUE _R_CHECK_CODE_ASSIGN_TO_GLOBALENV_=TRUE _R_CHECK_CODE_ATTACH_=TRUE _R_CHECK_CODE_DATA_INTO_GLOBALENV_=TRUE _R_CHECK_CODE_USAGE_VIA_NAMESPACES_=TRUE _R_CHECK_DOT_FIRSTLIB_=TRUE _R_CHECK_DEPRECATED_DEFUNCT_=TRUE _R_CHECK_REPLACING_IMPORTS_=TRUE _R_CHECK_SCREEN_DEVICE_=stop _R_CHECK_TOPLEVEL_FILES_=TRUE _R_CHECK_OVERWRITE_REGISTERED_S3_METHODS_=TRUE _R_CHECK_PRAGMAS_=TRUE _R_CHECK_COMPILATION_FLAGS_=TRUE _R_CHECK_R_DEPENDS_=warn _R_CHECK_SERIALIZATION_=TRUE _R_CHECK_R_ON_PATH_=TRUE _R_CHECK_PACKAGES_USED_IN_TESTS_USE_SUBDIRS_=TRUE _R_CHECK_SHLIB_OPENMP_FLAGS_=TRUE _R_CHECK_CONNECTIONS_LEFT_OPEN_=TRUE _R_CHECK_FUTURE_FILE_TIMESTAMPS_=TRUE _R_CHECK_AUTOCONF_=true _R_CHECK_DATALIST_=true _R_CHECK_THINGS_IN_CHECK_DIR_=true _R_CHECK_THINGS_IN_TEMP_DIR_=true _R_CHECK_BASHISMS_=true _R_CHECK_ORPHANED_=true _R_CHECK_BOGUS_RETURN_=true _R_CHECK_MATRIX_DATA_=TRUE _R_CHECK_CODE_CLASS_IS_STRING_=true _R_CHECK_RD_VALIDATE_RD2HTML_=true _R_CHECK_RD_MATH_RENDERING_=true _R_CHECK_NEWS_IN_PLAIN_TEXT_=true _R_CHECK_BROWSER_NONINTERACTIVE_=true _R_CHECK_URLS_SHOW_301_STATUS_=true _R_CHECK_UNDOC_USE_ALL_NAMES_=true _R_CHECK_S3_METHODS_SHOW_POSSIBLE_ISSUES_=true _R_CHECK_RD_NOTE_LOST_BRACES_=true </pre></div> <p>These are turned on by <code class="command">R CMD check --as-cran</code>: the incoming checks also use </p><div class="example"> <pre class="example-preformatted">_R_CHECK_FORCE_SUGGESTS_=FALSE </pre></div> <p>since some packages do suggest other packages not available on CRAN or other commonly-used repositories. </p> <p>Several environment variables can be used to set ‘timeouts’: limits for the elapsed time taken by the sub-processes used for parts of the checks. A value of <code class="code">0</code> indicates no limit, and is the default. Character strings ending in ‘<samp class="samp">s</samp>’, ‘<samp class="samp">m</samp>’ or ‘<samp class="samp">h</samp>’ indicate a number of seconds, minutes or hours respectively: other values are interpreted as a whole number of seconds (with invalid inputs being treated as no limit). </p><dl class="vtable"> <dt><a id="index-_005fR_005fCHECK_005fELAPSED_005fTIMEOUT_005f"></a><span><code class="code">_R_CHECK_ELAPSED_TIMEOUT_</code><a class="copiable-link" href="#index-_005fR_005fCHECK_005fELAPSED_005fTIMEOUT_005f"> ¶</a></span></dt> <dd><p>The default timeout for sub-processes not otherwise mentioned, and the default value for all except <code class="env">_R_CHECK_ONE_TEST_ELAPSED_TIMEOUT_</code>. (This is also used by <code class="code">tools::check_packages_in_dir</code>.) </p> </dd> <dt><a id="index-_005fR_005fCHECK_005fINSTALL_005fELAPSED_005fTIMEOUT_005f"></a><span><code class="code">_R_CHECK_INSTALL_ELAPSED_TIMEOUT_</code><a class="copiable-link" href="#index-_005fR_005fCHECK_005fINSTALL_005fELAPSED_005fTIMEOUT_005f"> ¶</a></span></dt> <dd><p>Limit for when <code class="command">R CMD INSTALL</code> is run by <code class="command">check</code>. </p> </dd> <dt><a id="index-_005fR_005fCHECK_005fEXAMPLES_005fELAPSED_005fTIMEOUT_005f"></a><span><code class="code">_R_CHECK_EXAMPLES_ELAPSED_TIMEOUT_</code><a class="copiable-link" href="#index-_005fR_005fCHECK_005fEXAMPLES_005fELAPSED_005fTIMEOUT_005f"> ¶</a></span></dt> <dd><p>Limit for running all the examples for one sub-architecture. </p> </dd> <dt><a id="index-_005fR_005fCHECK_005fONE_005fTEST_005fELAPSED_005fTIMEOUT_005f"></a><span><code class="code">_R_CHECK_ONE_TEST_ELAPSED_TIMEOUT_</code><a class="copiable-link" href="#index-_005fR_005fCHECK_005fONE_005fTEST_005fELAPSED_005fTIMEOUT_005f"> ¶</a></span></dt> <dd><p>Limit for running one test for one sub-architecture. Default <code class="env">_R_CHECK_TESTS_ELAPSED_TIMEOUT_</code>. </p> </dd> <dt><a id="index-_005fR_005fCHECK_005fTESTS_005fELAPSED_005fTIMEOUT_005f"></a><span><code class="code">_R_CHECK_TESTS_ELAPSED_TIMEOUT_</code><a class="copiable-link" href="#index-_005fR_005fCHECK_005fTESTS_005fELAPSED_005fTIMEOUT_005f"> ¶</a></span></dt> <dd><p>Limit for running all the tests for one sub-architecture (and the default limit for running one test). </p> </dd> <dt><a id="index-_005fR_005fCHECK_005fONE_005fVIGNETTE_005fELAPSED_005fTIMEOUT_005f"></a><span><code class="code">_R_CHECK_ONE_VIGNETTE_ELAPSED_TIMEOUT_</code><a class="copiable-link" href="#index-_005fR_005fCHECK_005fONE_005fVIGNETTE_005fELAPSED_005fTIMEOUT_005f"> ¶</a></span></dt> <dd><p>Limit for running the R code in one vignette, including for re-building each vignette separately. </p> </dd> <dt><a id="index-_005fR_005fCHECK_005fBUILD_005fVIGNETTES_005fELAPSED_005fTIMEOUT_005f"></a><span><code class="code">_R_CHECK_BUILD_VIGNETTES_ELAPSED_TIMEOUT_</code><a class="copiable-link" href="#index-_005fR_005fCHECK_005fBUILD_005fVIGNETTES_005fELAPSED_005fTIMEOUT_005f"> ¶</a></span></dt> <dd><p>Limit for re-building all vignettes. </p> </dd> <dt><a id="index-_005fR_005fCHECK_005fPKGMAN_005fELAPSED_005fTIMEOUT_005f"></a><span><code class="code">_R_CHECK_PKGMAN_ELAPSED_TIMEOUT_</code><a class="copiable-link" href="#index-_005fR_005fCHECK_005fPKGMAN_005fELAPSED_005fTIMEOUT_005f"> ¶</a></span></dt> <dd><p>Limit for each attempt at building the PDF package manual. </p></dd> </dl> <p>Another variable which enables stricter checks is to set <code class="env">R_CHECK_CONSTANTS</code> to <code class="code">5</code>. This checks that nothing<a class="footnote" id="DOCF23" href="#FOOT23"><sup>23</sup></a> changes the values of ‘constants’<a class="footnote" id="DOCF24" href="#FOOT24"><sup>24</sup></a> in R code. This is best used in conjunction with setting <code class="env">R_JIT_STRATEGY</code> to <code class="code">3</code>, which checks code on first use (by default most code is only checked after byte-compilation on second use). Unfortunately these checks slow down checking of examples, tests and vignettes, typically two-fold but in the worst cases at least a hundred-fold. </p> <p>The following environment variables can be used to customize the operation of <code class="command">INSTALL</code>. </p> <dl class="vtable"> <dt><a id="index-_005fR_005fINSTALL_005fLIBS_005fONLY_005fFORCE_005fDEPENDS_005fIMPORTS_005f"></a><span><code class="code">_R_INSTALL_LIBS_ONLY_FORCE_DEPENDS_IMPORTS_</code><a class="copiable-link" href="#index-_005fR_005fINSTALL_005fLIBS_005fONLY_005fFORCE_005fDEPENDS_005fIMPORTS_005f"> ¶</a></span></dt> <dd><p>If true, give an error if installing only package libraries via <samp class="option">--libs-only</samp> and some package imported or depended on is not available. Default: true (false only for special applications, which analyze native code of packages). </p></dd> </dl> <hr> </div> <div class="chapter-level-extent" id="R-coding-standards"> <div class="nav-panel"> <p> Next: <a href="#Testing-R-code" accesskey="n" rel="next">Testing R code</a>, Previous: <a href="#Tools" accesskey="p" rel="prev">Tools</a>, Up: <a href="#Top" accesskey="u" rel="up">R Internals</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-variable-index" title="Index" rel="index">Index</a>]</p> </div> <h2 class="chapter" id="R-coding-standards-1"><span>9 R coding standards<a class="copiable-link" href="#R-coding-standards-1"> ¶</a></span></h2> <a class="index-entry-id" id="index-coding-standards"></a> <p>R is meant to run on a wide variety of platforms, including Linux and most variants of Unix as well as Windows and macOS. Therefore, when extending R by either adding to the R base distribution or by providing an add-on package, one should not rely on features specific to only a few supported platforms, if this can be avoided. In particular, although most R developers use <abbr class="acronym">GNU</abbr> tools, they should not employ the <abbr class="acronym">GNU</abbr> extensions to standard tools. Whereas some other software packages explicitly rely on e.g. <abbr class="acronym">GNU</abbr> make or the <abbr class="acronym">GNU</abbr> C++ compiler, R does not. Nevertheless, R is a <abbr class="acronym">GNU</abbr> project, and the spirit of the <cite class="cite"><abbr class="acronym">GNU</abbr> Coding Standards</cite> should be followed if possible. </p> <p>The following tools can “safely be assumed” for R extensions. </p> <ul class="itemize mark-bullet"> <li>An ISO C99 C compiler. Note that extensions such as <abbr class="acronym">POSIX</abbr> 1003.1 must be tested for, typically using Autoconf unless you are sure they are supported on all mainstream R platforms (including Windows and macOS). </li><li>A fixed-form Fortran compiler. </li><li>A simple <code class="command">make</code>, considering the features of <code class="command">make</code> in 4.2 <abbr class="acronym">BSD</abbr> systems as a baseline. <a class="index-entry-id" id="index-make"></a> <p><abbr class="acronym">GNU</abbr> or other extensions, including pattern rules using ‘<samp class="samp">%</samp>’, the automatic variable ‘<samp class="samp">$^</samp>’, the ‘<samp class="samp">+=</samp>’ syntax to append to the value of a variable, the (“safe”) inclusion of makefiles with no error, conditional execution, and many more, must not be used (see Chapter “Features” in the <cite class="cite"><abbr class="acronym">GNU</abbr> Make Manual</cite> for more information). On the other hand, building R in a separate directory (not containing the sources) should work provided that <code class="command">make</code> supports the <code class="code">VPATH</code> mechanism. </p> <p>Windows-specific makefiles can assume <abbr class="acronym">GNU</abbr> <code class="command">make</code> 3.79 or later, as no other <code class="command">make</code> is viable on that platform. </p> </li><li>A Bourne shell and the “traditional” Unix programming tools, including <code class="command">grep</code>, <code class="command">sed</code>, and <code class="command">awk</code>. <p>There are <abbr class="acronym">POSIX</abbr> standards for these tools, but these may not be fully supported. Baseline features could be determined from a book such as <cite class="cite">The UNIX Programming Environment</cite> by Brian W. Kernighan & Rob Pike. Note in particular that ‘<samp class="samp">|</samp>’ in a regexp is an extended regexp, and is not supported by all versions of <code class="command">grep</code> or <code class="command">sed</code>. The Open Group Base Specifications, Issue 7, which are technically identical to IEEE Std 1003.1 (POSIX), 2008, are available at <a class="uref" href="https://pubs.opengroup.org/onlinepubs/9699919799/mindex.html">https://pubs.opengroup.org/onlinepubs/9699919799/mindex.html</a>. </p></li></ul> <p>Under Windows, most users will not have these tools installed, and you should not require their presence for the operation of your package. However, users who install your package from source will have them, as they can be assumed to have followed the instructions in “the Windows toolset” appendix of the “R Installation and Administration” manual to obtain them. Redirection cannot be assumed to be available via <code class="command">system</code> as this does not use a standard shell (let alone a Bourne shell). </p> <p>In addition, the following tools are needed for certain tasks. </p> <ul class="itemize mark-bullet"> <li>Perl version 5 is needed for the maintainer-only script <samp class="file">tools/help2man.pl</samp>. <a class="index-entry-id" id="index-Perl"></a> </li><li><code class="command">texinfo</code> version 5.1 or later is needed to build the HTML, PDF and Info files for the R manuals written in the <abbr class="acronym">GNU</abbr> Texinfo system. And that requires Perl. <a class="index-entry-id" id="index-makeinfo"></a> </li></ul> <p>It is also important that code is written in a way that allows others to understand it. This is particularly helpful for fixing problems, and includes using self-descriptive variable names, commenting the code, and also formatting it properly. The R Core Team recommends to use a basic indentation of 4 for R and C (and most likely also Perl) code, and 2 for documentation in Rd format. Emacs (21 or later) users can implement this indentation style by putting the following in one of their startup files, and using customization to set the <code class="code">c-default-style</code> to <code class="code">"bsd"</code> and <code class="code">c-basic-offset</code> to <code class="code">4</code>.) <a class="index-entry-id" id="index-emacs"></a> </p> <div class="example smallexample"> <div class="group"><pre class="example-preformatted">;;; ESS (add-hook 'ess-mode-hook (lambda () (ess-set-style 'C++ 'quiet) ;; Because ;; DEF GNU BSD K&R C++ ;; ess-indent-level 2 2 8 5 4 ;; ess-continued-statement-offset 2 2 8 5 4 ;; ess-brace-offset 0 0 -8 -5 -4 ;; ess-arg-function-offset 2 4 0 0 0 ;; ess-expression-offset 4 2 8 5 4 ;; ess-else-offset 0 0 0 0 0 ;; ess-close-brace-offset 0 0 0 0 0 (add-hook 'local-write-file-hooks (lambda () (ess-nuke-trailing-whitespace))))) (setq ess-nuke-trailing-whitespace-p 'ask) ;; or even ;; (setq ess-nuke-trailing-whitespace-p t) </pre></div><div class="group"><pre class="example-preformatted">;;; Perl (add-hook 'perl-mode-hook (lambda () (setq perl-indent-level 4))) </pre></div></div> <p>(The ‘GNU’ styles for Emacs’ C and R modes use a basic indentation of 2, which has been determined not to display the structure clearly enough when using narrow fonts.) </p> <hr> </div> <div class="chapter-level-extent" id="Testing-R-code"> <div class="nav-panel"> <p> Next: <a href="#Use-of-TeX-dialects" accesskey="n" rel="next">Use of TeX dialects</a>, Previous: <a href="#R-coding-standards" accesskey="p" rel="prev">R coding standards</a>, Up: <a href="#Top" accesskey="u" rel="up">R Internals</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-variable-index" title="Index" rel="index">Index</a>]</p> </div> <h2 class="chapter" id="Testing-R-code-1"><span>10 Testing R code<a class="copiable-link" href="#Testing-R-code-1"> ¶</a></span></h2> <p>When you (as R developer) add new functions to the R base (all the packages distributed with R), be careful to check if <kbd class="kbd">make test-Specific</kbd> or particularly, <kbd class="kbd">cd tests; make no-segfault.Rout</kbd> still works (without interactive user intervention, and on a standalone computer). If the new function, for example, accesses the Internet, or requires <abbr class="acronym">GUI</abbr> interaction, please add its name to the “stop list” in <samp class="file">tests/no-segfault.Rin</samp>. </p> <p>[To be revised: use <code class="command">make check-devel</code>, check the write barrier if you change internal structures.] </p> <hr> </div> <div class="chapter-level-extent" id="Use-of-TeX-dialects"> <div class="nav-panel"> <p> Next: <a href="#Current-and-future-directions" accesskey="n" rel="next">Current and future directions</a>, Previous: <a href="#Testing-R-code" accesskey="p" rel="prev">Testing R code</a>, Up: <a href="#Top" accesskey="u" rel="up">R Internals</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-variable-index" title="Index" rel="index">Index</a>]</p> </div> <h2 class="chapter" id="Use-of-TeX-dialects-1"><span>11 Use of TeX dialects<a class="copiable-link" href="#Use-of-TeX-dialects-1"> ¶</a></span></h2> <p>Various dialects of TeX are used for different purposes in R. The policy is that manuals be written in ‘<samp class="samp">texinfo</samp>’, and for convenience the main and Windows FAQs are also. This has the advantage that it is easy to produce <abbr class="acronym">HTML</abbr> and plain text versions as well as typeset manuals. </p> <p>LaTeX is not used directly, but rather as an intermediate format for typeset help documents and for vignettes. </p> <p>Care needs to be taken about the assumptions made about the R user’s system: it may not have either ‘<samp class="samp">texinfo</samp>’ or a TeX system installed. We have attempted to abstract out the cross-platform differences, and almost all the setting of typeset documents is done by <code class="code">tools::texi2dvi</code>. This is used for offline printing of help documents, preparing vignettes and for package manuals via <code class="command">R CMD Rd2pdf</code>. It is not currently used for the R manuals created in directory <samp class="file">doc/manual</samp>. </p> <p><code class="code">tools::texi2dvi</code> makes use of a system command <code class="command">texi2dvi</code> where available. On a Unix-alike this is usually part of ‘<samp class="samp">texinfo</samp>’, whereas on Windows if it exists at all it would be an executable, part of MiKTeX. If none is available, the R code runs a sequence of <code class="command">(pdf)latex</code>, <code class="command">bibtex</code> and <code class="command">makeindex</code> commands. </p> <p>This process has been rather vulnerable to the versions of the external software used: particular issues have been <code class="command">texi2dvi</code> and <samp class="file">texinfo.tex</samp> updates, mismatches between the two<a class="footnote" id="DOCF25" href="#FOOT25"><sup>25</sup></a>, versions of the LaTeX package ‘<samp class="samp">hyperref</samp>’ and quirks in index production. The licenses used for LaTeX and latterly ‘<samp class="samp">texinfo</samp>’ prohibit us from including ‘known good’ versions in the R distribution. </p> <p>On a Unix-alike <code class="command">configure</code> looks for the executables for TeX and friends and if found records the absolute paths in the system <samp class="file">Renviron</samp> file. This used to record ‘<samp class="samp">false</samp>’ if no command was found, but it nowadays records the name for looking up on the path at run time. The latter can be important for binary distributions: one does not want to be tied to, for example, TeX Live 2007. </p> <hr> </div> <div class="chapter-level-extent" id="Current-and-future-directions"> <div class="nav-panel"> <p> Next: <a href="#Function-and-variable-index" accesskey="n" rel="next">Function and variable index</a>, Previous: <a href="#Use-of-TeX-dialects" accesskey="p" rel="prev">Use of TeX dialects</a>, Up: <a href="#Top" accesskey="u" rel="up">R Internals</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-variable-index" title="Index" rel="index">Index</a>]</p> </div> <h2 class="chapter" id="Current-and-future-directions-1"><span>12 Current and future directions<a class="copiable-link" href="#Current-and-future-directions-1"> ¶</a></span></h2> <p>This chapter is for notes about possible in-progress and future changes to R: there is no commitment to release such changes, let alone to a timescale. </p> <ul class="mini-toc"> <li><a href="#Long-vectors" accesskey="1">Long vectors</a></li> <li><a href="#g_t64_002dbit-types" accesskey="2">64-bit types</a></li> <li><a href="#Large-matrices" accesskey="3">Large matrices</a></li> </ul> <hr> <div class="section-level-extent" id="Long-vectors"> <div class="nav-panel"> <p> Next: <a href="#g_t64_002dbit-types" accesskey="n" rel="next">64-bit types</a>, Previous: <a href="#Current-and-future-directions" accesskey="p" rel="prev">Current and future directions</a>, Up: <a href="#Current-and-future-directions" accesskey="u" rel="up">Current and future directions</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-variable-index" title="Index" rel="index">Index</a>]</p> </div> <h3 class="section" id="Long-vectors-1"><span>12.1 Long vectors<a class="copiable-link" href="#Long-vectors-1"> ¶</a></span></h3> <p>Vectors in R 2.x.y were limited to a length of 2^31 - 1 elements (about 2 billion), as the length is stored in the <code class="code">SEXPREC</code> as a C <code class="code">int</code>, and that type is used extensively to record lengths and element numbers, including in packages. </p> <p>Note that longer vectors are effectively impossible under 32-bit platforms because of their address limit, so this section applies only on 64-bit platforms. The internals are unchanged on a 32-bit build of R. </p> <p>A single object with 2^31 or more elements will take up at least 8GB of memory if integer or logical and 16GB if numeric or character, so routine use of such objects is still some way off. </p> <p>There is now some support for long vectors. This applies to raw, logical, integer, numeric and character vectors, and lists and expression vectors. (Elements of character vectors (<code class="code">CHARSXP</code>s) remain limited to 2^31 - 1 bytes.) Some considerations: </p> <ul class="itemize mark-bullet"> <li>This has been implemented by recording the length (and true length) as <code class="code">-1</code> and recording the actual length as a 64-bit field at the beginning of the header. Because a fair amount of code in R uses a signed type for the length, the ‘long length’ is recorded using the signed C99 type <code class="code">ptrdiff_t</code>, which is typedef-ed to <code class="code">R_xlen_t</code>. </li><li>These can in theory have 63-bit lengths, but note that current 64-bit OSes do not even theoretically offer 64-bit address spaces and there is currently a 52-bit limit (which exceeds the theoretical limit of current OSes and ensures that such lengths can be stored exactly in doubles). </li><li>The serialization format has been changed to accommodate longer lengths, but vectors of lengths up to 2^31-1 are stored in the same way as before. Longer vectors have their length field set to <code class="code">-1</code> and followed by two 32-bit fields giving the upper and lower 32-bits of the actual length. There is currently a sanity check which limits lengths to 2^48 on unserialization. </li><li>The type <code class="code">R_xlen_t</code> is made available to packages in C header <samp class="file">Rinternals.h</samp>: this should be fine in C code since C99 is required. People do try to use R internals in C++, but C++98 compilers are not required to support these types. </li><li>Indexing can be done via the use of doubles. The internal indexing code used to work with positive integer indices (and negative, logical and matrix indices were all converted to positive integers): it now works with either <code class="code">INTSXP</code> or <code class="code">REALSXP</code> indices. </li><li>The R function <code class="code">length</code> returns a double value if the length exceeds 2^31-1. Code calling <code class="code">as.integer(length(x))</code> before passing to <code class="code">.C</code>/<code class="code">.Fortran</code> should checks for an <code class="code">NA</code> result. </li></ul> <hr> </div> <div class="section-level-extent" id="g_t64_002dbit-types"> <div class="nav-panel"> <p> Next: <a href="#Large-matrices" accesskey="n" rel="next">Large matrices</a>, Previous: <a href="#Long-vectors" accesskey="p" rel="prev">Long vectors</a>, Up: <a href="#Current-and-future-directions" accesskey="u" rel="up">Current and future directions</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-variable-index" title="Index" rel="index">Index</a>]</p> </div> <h3 class="section" id="g_t64_002dbit-types-1"><span>12.2 64-bit types<a class="copiable-link" href="#g_t64_002dbit-types-1"> ¶</a></span></h3> <p>There is also some desire to be able to store larger integers in R, although the possibility of storing these as <code class="code">double</code> is often overlooked (and e.g. file pointers as returned by <code class="code">seek</code> are already stored as <code class="code">double</code>). </p> <p>Different routes have been proposed: </p> <ul class="itemize mark-bullet"> <li>Add a new type to R and use that for lengths and indices—most likely this would be a 64-bit signed type, say <code class="code">longint</code>. R’s usual implicit coercion rules would ensure that supplying an <code class="code">integer</code> vector for indexing or <code class="code">length<-</code> would work. </li><li>A more radical alternative is to change the existing <code class="code">integer</code> type to be 64-bit on 64-bit platforms (which was the approach taken by S-PLUS for DEC/Compaq Alpha systems). Or even on all platforms. </li><li>Allow either <code class="code">integer</code> or <code class="code">double</code> values for lengths and indices, and return <code class="code">double</code> only when necessary. </li></ul> <p>The third has the advantages of minimal disruption to existing code and not increasing memory requirements. In the first and third scenarios both R’s own code and user code would have to be adapted for lengths that were not of type <code class="code">integer</code>, and in the third code branches for long vectors would be tested rarely. </p> <p>Most users of the <code class="code">.C</code> and <code class="code">.Fortran</code> interfaces use <code class="code">as.integer</code> for lengths and element numbers, but a few omit these in the knowledge that these were of type <code class="code">integer</code>. It may be reasonable to assume that these are never intended to be used with long vectors. </p> <p>The remaining interfaces will need to cope with the changed <code class="code">VECTOR_SEXPREC</code> types. It seems likely that in most cases lengths are accessed by the <code class="code">length</code> and <code class="code">LENGTH</code> functions<a class="footnote" id="DOCF26" href="#FOOT26"><sup>26</sup></a> The current approach is to keep these returning 32-bit lengths and introduce ‘long’ versions <code class="code">xlength</code> and <code class="code">XLENGTH</code> which return <code class="code">R_xlen_t</code> values. </p> <p>See also <a class="uref" href="https://homepage.cs.uiowa.edu/~luke/talks/useR10.pdf">https://homepage.cs.uiowa.edu/~luke/talks/useR10.pdf</a>. </p> <hr> </div> <div class="section-level-extent" id="Large-matrices"> <div class="nav-panel"> <p> Previous: <a href="#g_t64_002dbit-types" accesskey="p" rel="prev">64-bit types</a>, Up: <a href="#Current-and-future-directions" accesskey="u" rel="up">Current and future directions</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-variable-index" title="Index" rel="index">Index</a>]</p> </div> <h3 class="section" id="Large-matrices-1"><span>12.3 Large matrices<a class="copiable-link" href="#Large-matrices-1"> ¶</a></span></h3> <p>Matrices are stored as vectors and so were also limited to 2^31-1 elements. Now longer vectors are allowed on 64-bit platforms, matrices with more elements are supported provided that each of the dimensions is no more than 2^31-1. However, not all applications can be supported. </p> <p>The main problem is linear algebra done by Fortran code compiled with 32-bit <code class="code">INTEGER</code>. Although not guaranteed, it seems that all the compilers currently used with R on a 64-bit platform allow matrices each of whose dimensions is less than 2^31 but with 2^31 or more elements and index them correctly, and a substantial part of the support software (such as <abbr class="acronym">BLAS</abbr> and <abbr class="acronym">LAPACK</abbr>) also work. </p> <p>There are exceptions: for example some complex <abbr class="acronym">LAPACK</abbr> auxiliary routines do use a single <code class="code">INTEGER</code> index and hence overflow silently and segfault or give incorrect results. One example seen was <code class="code">svd()</code> on a complex matrix. </p> <p>Since this is implementation-dependent, it is possible that optimized <abbr class="acronym">BLAS</abbr> and <abbr class="acronym">LAPACK</abbr> may have further restrictions: a segfault have been reported from <code class="code">svd()</code> using ATLAS on ‘<samp class="samp">x86_64</samp>’ Linux. </p> <p>For matrix algebra on large matrices one almost certainly wants a machine with a lot of RAM (100s of gigabytes), many cores and a multi-threaded <abbr class="acronym">BLAS</abbr>. </p> <hr> </div> </div> <div class="unnumbered-level-extent" id="Function-and-variable-index"> <div class="nav-panel"> <p> Next: <a href="#Concept-index" accesskey="n" rel="next">Concept index</a>, Previous: <a href="#Current-and-future-directions" accesskey="p" rel="prev">Current and future directions</a>, Up: <a href="#Top" accesskey="u" rel="up">R Internals</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-variable-index" title="Index" rel="index">Index</a>]</p> </div> <h2 class="unnumbered" id="Function-and-variable-index-1"><span>Function and variable index<a class="copiable-link" href="#Function-and-variable-index-1"> ¶</a></span></h2> <div class="printindex vr-printindex"> <table summary="" class="vr-letters-header-printindex"><tr><th>Jump to: </th><td><a class="summary-letter-printindex" href="#Function-and-variable-index_vr_symbol-1"><b>_</b></a> <a class="summary-letter-printindex" href="#Function-and-variable-index_vr_symbol-2"><b>.</b></a> <br> <a class="summary-letter-printindex" href="#Function-and-variable-index_vr_letter-A"><b>A</b></a> <a class="summary-letter-printindex" href="#Function-and-variable-index_vr_letter-C"><b>C</b></a> <a class="summary-letter-printindex" href="#Function-and-variable-index_vr_letter-D"><b>D</b></a> <a class="summary-letter-printindex" href="#Function-and-variable-index_vr_letter-E"><b>E</b></a> <a class="summary-letter-printindex" href="#Function-and-variable-index_vr_letter-G"><b>G</b></a> <a class="summary-letter-printindex" href="#Function-and-variable-index_vr_letter-I"><b>I</b></a> <a class="summary-letter-printindex" href="#Function-and-variable-index_vr_letter-L"><b>L</b></a> <a class="summary-letter-printindex" href="#Function-and-variable-index_vr_letter-M"><b>M</b></a> <a class="summary-letter-printindex" href="#Function-and-variable-index_vr_letter-N"><b>N</b></a> <a class="summary-letter-printindex" href="#Function-and-variable-index_vr_letter-P"><b>P</b></a> <a class="summary-letter-printindex" href="#Function-and-variable-index_vr_letter-R"><b>R</b></a> <a class="summary-letter-printindex" href="#Function-and-variable-index_vr_letter-S"><b>S</b></a> <a class="summary-letter-printindex" href="#Function-and-variable-index_vr_letter-T"><b>T</b></a> <a class="summary-letter-printindex" href="#Function-and-variable-index_vr_letter-U"><b>U</b></a> <a class="summary-letter-printindex" href="#Function-and-variable-index_vr_letter-V"><b>V</b></a> <a class="summary-letter-printindex" href="#Function-and-variable-index_vr_letter-W"><b>W</b></a> </td></tr></table> <table summary="" class="vr-entries-printindex" border="0"> <tr><td></td><th class="entries-header-printindex">Index Entry</th><th class="sections-header-printindex">Section</th></tr> <tr><td colspan="3"><hr></td></tr> <tr><th id="Function-and-variable-index_vr_symbol-1">_</th></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_005fR_005fCHECK_005fALL_005fNON_005fISO_005fC_005f"><code>_R_CHECK_ALL_NON_ISO_C_</code></a></td><td class="printindex-index-section"><a href="#Tools">Tools</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_005fR_005fCHECK_005fALWAYS_005fLOG_005fVIGNETTE_005fOUTPUT_005f"><code>_R_CHECK_ALWAYS_LOG_VIGNETTE_OUTPUT_</code></a></td><td class="printindex-index-section"><a href="#Tools">Tools</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_005fR_005fCHECK_005fASCII_005fCODE_005f"><code>_R_CHECK_ASCII_CODE_</code></a></td><td class="printindex-index-section"><a href="#Tools">Tools</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_005fR_005fCHECK_005fASCII_005fDATA_005f"><code>_R_CHECK_ASCII_DATA_</code></a></td><td class="printindex-index-section"><a href="#Tools">Tools</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_005fR_005fCHECK_005fAUTOCONF_005f"><code>_R_CHECK_AUTOCONF_</code></a></td><td class="printindex-index-section"><a href="#Tools">Tools</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_005fR_005fCHECK_005fBASHISMS_005f"><code>_R_CHECK_BASHISMS_</code></a></td><td class="printindex-index-section"><a href="#Tools">Tools</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_005fR_005fCHECK_005fBOGUS_005fRETURN_005f"><code>_R_CHECK_BOGUS_RETURN_</code></a></td><td class="printindex-index-section"><a href="#Tools">Tools</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_005fR_005fCHECK_005fBROWSER_005fNONINTERACTIVE_005f"><code>_R_CHECK_BROWSER_NONINTERACTIVE_</code></a></td><td class="printindex-index-section"><a href="#Tools">Tools</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_005fR_005fCHECK_005fBUILD_005fVIGNETTES_005fELAPSED_005fTIMEOUT_005f"><code>_R_CHECK_BUILD_VIGNETTES_ELAPSED_TIMEOUT_</code></a></td><td class="printindex-index-section"><a href="#Tools">Tools</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_005fR_005fCHECK_005fBUILD_005fVIGNETTES_005fSEPARATELY_005f"><code>_R_CHECK_BUILD_VIGNETTES_SEPARATELY_</code></a></td><td class="printindex-index-section"><a href="#Tools">Tools</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_005fR_005fCHECK_005fCLEAN_005fVIGN_005fTEST_005f"><code>_R_CHECK_CLEAN_VIGN_TEST_</code></a></td><td class="printindex-index-section"><a href="#Tools">Tools</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_005fR_005fCHECK_005fCODE_005fASSIGN_005fTO_005fGLOBALENV_005f"><code>_R_CHECK_CODE_ASSIGN_TO_GLOBALENV_</code></a></td><td class="printindex-index-section"><a href="#Tools">Tools</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_005fR_005fCHECK_005fCODE_005fATTACH_005f"><code>_R_CHECK_CODE_ATTACH_</code></a></td><td class="printindex-index-section"><a href="#Tools">Tools</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_005fR_005fCHECK_005fCODE_005fCLASS_005fIS_005fSTRING_005f"><code>_R_CHECK_CODE_CLASS_IS_STRING_</code></a></td><td class="printindex-index-section"><a href="#Tools">Tools</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_005fR_005fCHECK_005fCODE_005fDATA_005fINTO_005fGLOBALENV_005f"><code>_R_CHECK_CODE_DATA_INTO_GLOBALENV_</code></a></td><td class="printindex-index-section"><a href="#Tools">Tools</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_005fR_005fCHECK_005fCODE_005fUSAGE_005fVIA_005fNAMESPACES_005f"><code>_R_CHECK_CODE_USAGE_VIA_NAMESPACES_</code></a></td><td class="printindex-index-section"><a href="#Tools">Tools</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_005fR_005fCHECK_005fCODE_005fUSAGE_005fWITH_005fONLY_005fBASE_005fATTACHED_005f"><code>_R_CHECK_CODE_USAGE_WITH_ONLY_BASE_ATTACHED_</code></a></td><td class="printindex-index-section"><a href="#Tools">Tools</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_005fR_005fCHECK_005fCODETOOLS_005fPROFILE_005f"><code>_R_CHECK_CODETOOLS_PROFILE_</code></a></td><td class="printindex-index-section"><a href="#Tools">Tools</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_005fR_005fCHECK_005fCODOC_005fS4_005fMETHODS_005f"><code>_R_CHECK_CODOC_S4_METHODS_</code></a></td><td class="printindex-index-section"><a href="#Tools">Tools</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_005fR_005fCHECK_005fCOMPACT_005fDATA_005f"><code>_R_CHECK_COMPACT_DATA_</code></a></td><td class="printindex-index-section"><a href="#Tools">Tools</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_005fR_005fCHECK_005fCOMPILATION_005fFLAGS_005f"><code>_R_CHECK_COMPILATION_FLAGS_</code></a></td><td class="printindex-index-section"><a href="#Tools">Tools</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_005fR_005fCHECK_005fCONNECTIONS_005fLEFT_005fOPEN_005f"><code>_R_CHECK_CONNECTIONS_LEFT_OPEN_</code></a></td><td class="printindex-index-section"><a href="#Tools">Tools</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_005fR_005fCHECK_005fCRAN_005fINCOMING_005f"><code>_R_CHECK_CRAN_INCOMING_</code></a></td><td class="printindex-index-section"><a href="#Tools">Tools</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_005fR_005fCHECK_005fCRAN_005fINCOMING_005fREMOTE_005f"><code>_R_CHECK_CRAN_INCOMING_REMOTE_</code></a></td><td class="printindex-index-section"><a href="#Tools">Tools</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_005fR_005fCHECK_005fDATALIST_005f"><code>_R_CHECK_DATALIST_</code></a></td><td class="printindex-index-section"><a href="#Tools">Tools</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_005fR_005fCHECK_005fDEPENDS_005fONLY_005f"><code>_R_CHECK_DEPENDS_ONLY_</code></a></td><td class="printindex-index-section"><a href="#Tools">Tools</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_005fR_005fCHECK_005fDEPENDS_005fONLY_005fDATA_005f"><code>_R_CHECK_DEPENDS_ONLY_DATA_</code></a></td><td class="printindex-index-section"><a href="#Tools">Tools</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_005fR_005fCHECK_005fDEPENDS_005fONLY_005fEXAMPLES_005f"><code>_R_CHECK_DEPENDS_ONLY_EXAMPLES_</code></a></td><td class="printindex-index-section"><a href="#Tools">Tools</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_005fR_005fCHECK_005fDEPENDS_005fONLY_005fTESTS_005f"><code>_R_CHECK_DEPENDS_ONLY_TESTS_</code></a></td><td class="printindex-index-section"><a href="#Tools">Tools</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_005fR_005fCHECK_005fDEPENDS_005fONLY_005fVIGNETTES_005f"><code>_R_CHECK_DEPENDS_ONLY_VIGNETTES_</code></a></td><td class="printindex-index-section"><a href="#Tools">Tools</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_005fR_005fCHECK_005fDEPRECATED_005fDEFUNCT_005f"><code>_R_CHECK_DEPRECATED_DEFUNCT_</code></a></td><td class="printindex-index-section"><a href="#Tools">Tools</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_005fR_005fCHECK_005fDOC_005fSIZES_005f"><code>_R_CHECK_DOC_SIZES_</code></a></td><td class="printindex-index-section"><a href="#Tools">Tools</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_005fR_005fCHECK_005fDOC_005fSIZES2_005f"><code>_R_CHECK_DOC_SIZES2_</code></a></td><td class="printindex-index-section"><a href="#Tools">Tools</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_005fR_005fCHECK_005fDONTTEST_005fEXAMPLES_005f"><code>_R_CHECK_DONTTEST_EXAMPLES_</code></a></td><td class="printindex-index-section"><a href="#Tools">Tools</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_005fR_005fCHECK_005fDOT_005fFIRSTLIB_005f"><code>_R_CHECK_DOT_FIRSTLIB_</code></a></td><td class="printindex-index-section"><a href="#Tools">Tools</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_005fR_005fCHECK_005fDOT_005fINTERNAL_005f"><code>_R_CHECK_DOT_INTERNAL_</code></a></td><td class="printindex-index-section"><a href="#Tools">Tools</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_005fR_005fCHECK_005fELAPSED_005fTIMEOUT_005f"><code>_R_CHECK_ELAPSED_TIMEOUT_</code></a></td><td class="printindex-index-section"><a href="#Tools">Tools</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_005fR_005fCHECK_005fEXAMPLE_005fTIMING_005fCPU_005fTO_005fELAPSED_005fTHRESHOLD_005f"><code>_R_CHECK_EXAMPLE_TIMING_CPU_TO_ELAPSED_THRESHOLD_</code></a></td><td class="printindex-index-section"><a href="#Tools">Tools</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_005fR_005fCHECK_005fEXAMPLE_005fTIMING_005fTHRESHOLD_005f"><code>_R_CHECK_EXAMPLE_TIMING_THRESHOLD_</code></a></td><td class="printindex-index-section"><a href="#Tools">Tools</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_005fR_005fCHECK_005fEXAMPLES_005fELAPSED_005fTIMEOUT_005f"><code>_R_CHECK_EXAMPLES_ELAPSED_TIMEOUT_</code></a></td><td class="printindex-index-section"><a href="#Tools">Tools</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_005fR_005fCHECK_005fEXCESSIVE_005fIMPORTS_005f"><code>_R_CHECK_EXCESSIVE_IMPORTS_</code></a></td><td class="printindex-index-section"><a href="#Tools">Tools</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_005fR_005fCHECK_005fEXECUTABLES_005f"><code>_R_CHECK_EXECUTABLES_</code></a></td><td class="printindex-index-section"><a href="#Tools">Tools</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_005fR_005fCHECK_005fEXECUTABLES_005fEXCLUSIONS_005f"><code>_R_CHECK_EXECUTABLES_EXCLUSIONS_</code></a></td><td class="printindex-index-section"><a href="#Tools">Tools</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_005fR_005fCHECK_005fEXIT_005fON_005fFIRST_005fERROR_005f"><code>_R_CHECK_EXIT_ON_FIRST_ERROR_</code></a></td><td class="printindex-index-section"><a href="#Tools">Tools</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_005fR_005fCHECK_005fFF_005fCALLS_005f"><code>_R_CHECK_FF_CALLS_</code></a></td><td class="printindex-index-section"><a href="#Tools">Tools</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_005fR_005fCHECK_005fFF_005fDUP_005f"><code>_R_CHECK_FF_DUP_</code></a></td><td class="printindex-index-section"><a href="#Tools">Tools</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_005fR_005fCHECK_005fFORCE_005fSUGGESTS_005f"><code>_R_CHECK_FORCE_SUGGESTS_</code></a></td><td class="printindex-index-section"><a href="#Tools">Tools</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_005fR_005fCHECK_005fFUTURE_005fFILE_005fTIMESTAMPS_005f"><code>_R_CHECK_FUTURE_FILE_TIMESTAMPS_</code></a></td><td class="printindex-index-section"><a href="#Tools">Tools</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_005fR_005fCHECK_005fGCT_005fN_005f"><code>_R_CHECK_GCT_N_</code></a></td><td class="printindex-index-section"><a href="#Tools">Tools</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_005fR_005fCHECK_005fINSTALL_005fDEPENDS_005f"><code>_R_CHECK_INSTALL_DEPENDS_</code></a></td><td class="printindex-index-section"><a href="#Tools">Tools</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_005fR_005fCHECK_005fINSTALL_005fELAPSED_005fTIMEOUT_005f"><code>_R_CHECK_INSTALL_ELAPSED_TIMEOUT_</code></a></td><td class="printindex-index-section"><a href="#Tools">Tools</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_005fR_005fCHECK_005fINSTALL_005fTIMING_005fCPU_005fTO_005fELAPSED_005fTHRESHOLD_005f"><code>_R_CHECK_INSTALL_TIMING_CPU_TO_ELAPSED_THRESHOLD_</code></a></td><td class="printindex-index-section"><a href="#Tools">Tools</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_005fR_005fCHECK_005fLENGTH_005f1_005fCONDITION_005f"><code>_R_CHECK_LENGTH_1_CONDITION_</code></a></td><td class="printindex-index-section"><a href="#Tools">Tools</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_005fR_005fCHECK_005fLICENSE_005f"><code>_R_CHECK_LICENSE_</code></a></td><td class="printindex-index-section"><a href="#Tools">Tools</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_005fR_005fCHECK_005fLIMIT_005fCORES_005f"><code>_R_CHECK_LIMIT_CORES_</code></a></td><td class="printindex-index-section"><a href="#Tools">Tools</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_005fR_005fCHECK_005fMATRIX_005fDATA_005f"><code>_R_CHECK_MATRIX_DATA_</code></a></td><td class="printindex-index-section"><a href="#Tools">Tools</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_005fR_005fCHECK_005fMBCS_005fCONVERSION_005fFAILURE_005f"><code>_R_CHECK_MBCS_CONVERSION_FAILURE_</code></a></td><td class="printindex-index-section"><a href="#Tools">Tools</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_005fR_005fCHECK_005fNATIVE_005fROUTINE_005fREGISTRATION_005f"><code>_R_CHECK_NATIVE_ROUTINE_REGISTRATION_</code></a></td><td class="printindex-index-section"><a href="#Tools">Tools</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_005fR_005fCHECK_005fNEWS_005fIN_005fPLAIN_005fTEXT_005f"><code>_R_CHECK_NEWS_IN_PLAIN_TEXT_</code></a></td><td class="printindex-index-section"><a href="#Tools">Tools</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_005fR_005fCHECK_005fNO_005fRECOMMENDED_005f"><code>_R_CHECK_NO_RECOMMENDED_</code></a></td><td class="printindex-index-section"><a href="#Tools">Tools</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_005fR_005fCHECK_005fNO_005fSTOP_005fON_005fTEST_005fERROR_005f"><code>_R_CHECK_NO_STOP_ON_TEST_ERROR_</code></a></td><td class="printindex-index-section"><a href="#Tools">Tools</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_005fR_005fCHECK_005fONE_005fTEST_005fELAPSED_005fTIMEOUT_005f"><code>_R_CHECK_ONE_TEST_ELAPSED_TIMEOUT_</code></a></td><td class="printindex-index-section"><a href="#Tools">Tools</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_005fR_005fCHECK_005fONE_005fVIGNETTE_005fELAPSED_005fTIMEOUT_005f"><code>_R_CHECK_ONE_VIGNETTE_ELAPSED_TIMEOUT_</code></a></td><td class="printindex-index-section"><a href="#Tools">Tools</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_005fR_005fCHECK_005fORPHANED_005f"><code>_R_CHECK_ORPHANED_</code></a></td><td class="printindex-index-section"><a href="#Tools">Tools</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_005fR_005fCHECK_005fOVERWRITE_005fREGISTERED_005fS3_005fMETHODS_005f"><code>_R_CHECK_OVERWRITE_REGISTERED_S3_METHODS_</code></a></td><td class="printindex-index-section"><a href="#Tools">Tools</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_005fR_005fCHECK_005fPACKAGES_005fUSED_005fIN_005fTESTS_005fUSE_005fSUBDIRS_005f"><code>_R_CHECK_PACKAGES_USED_IN_TESTS_USE_SUBDIRS_</code></a></td><td class="printindex-index-section"><a href="#Tools">Tools</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_005fR_005fCHECK_005fPERMISSIONS_005f"><code>_R_CHECK_PERMISSIONS_</code></a></td><td class="printindex-index-section"><a href="#Tools">Tools</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_005fR_005fCHECK_005fPKG_005fSIZES_005f"><code>_R_CHECK_PKG_SIZES_</code></a></td><td class="printindex-index-section"><a href="#Tools">Tools</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_005fR_005fCHECK_005fPKG_005fSIZES_005fTHRESHOLD_005f"><code>_R_CHECK_PKG_SIZES_THRESHOLD_</code></a></td><td class="printindex-index-section"><a href="#Tools">Tools</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_005fR_005fCHECK_005fPKGMAN_005fELAPSED_005fTIMEOUT_005f"><code>_R_CHECK_PKGMAN_ELAPSED_TIMEOUT_</code></a></td><td class="printindex-index-section"><a href="#Tools">Tools</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_005fR_005fCHECK_005fPRAGMAS_005f"><code>_R_CHECK_PRAGMAS_</code></a></td><td class="printindex-index-section"><a href="#Tools">Tools</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_005fR_005fCHECK_005fR_005fDEPENDS_005f"><code>_R_CHECK_R_DEPENDS_</code></a></td><td class="printindex-index-section"><a href="#Tools">Tools</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_005fR_005fCHECK_005fR_005fON_005fPATH_005f"><code>_R_CHECK_R_ON_PATH_</code></a></td><td class="printindex-index-section"><a href="#Tools">Tools</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_005fR_005fCHECK_005fRD_005fALLOW_005fEMPTY_005fITEM_005fIN_005fDESCRIBE_005f"><code>_R_CHECK_RD_ALLOW_EMPTY_ITEM_IN_DESCRIBE_</code></a></td><td class="printindex-index-section"><a href="#Tools">Tools</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_005fR_005fCHECK_005fRD_005fCHECKRD_005fMINLEVEL_005f"><code>_R_CHECK_RD_CHECKRD_MINLEVEL_</code></a></td><td class="printindex-index-section"><a href="#Tools">Tools</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_005fR_005fCHECK_005fRD_005fCONTENTS_005f"><code>_R_CHECK_RD_CONTENTS_</code></a></td><td class="printindex-index-section"><a href="#Tools">Tools</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_005fR_005fCHECK_005fRD_005fEXAMPLES_005fT_005fAND_005fF_005f"><code>_R_CHECK_RD_EXAMPLES_T_AND_F_</code></a></td><td class="printindex-index-section"><a href="#Tools">Tools</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_005fR_005fCHECK_005fRD_005fLINE_005fWIDTHS_005f"><code>_R_CHECK_RD_LINE_WIDTHS_</code></a></td><td class="printindex-index-section"><a href="#Tools">Tools</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_005fR_005fCHECK_005fRD_005fMATH_005fRENDERING_005f"><code>_R_CHECK_RD_MATH_RENDERING_</code></a></td><td class="printindex-index-section"><a href="#Tools">Tools</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_005fR_005fCHECK_005fRD_005fNOTE_005fLOST_005fBRACES_005f"><code>_R_CHECK_RD_NOTE_LOST_BRACES_</code></a></td><td class="printindex-index-section"><a href="#Tools">Tools</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_005fR_005fCHECK_005fRD_005fSTYLE_005f"><code>_R_CHECK_RD_STYLE_</code></a></td><td class="printindex-index-section"><a href="#Tools">Tools</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_005fR_005fCHECK_005fRD_005fVALIDATE_005fRD2HTML_005f"><code>_R_CHECK_RD_VALIDATE_RD2HTML_</code></a></td><td class="printindex-index-section"><a href="#Tools">Tools</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_005fR_005fCHECK_005fRD_005fXREFS_005f"><code>_R_CHECK_RD_XREFS_</code></a></td><td class="printindex-index-section"><a href="#Tools">Tools</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_005fR_005fCHECK_005fREPLACING_005fIMPORTS_005f"><code>_R_CHECK_REPLACING_IMPORTS_</code></a></td><td class="printindex-index-section"><a href="#Tools">Tools</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_005fR_005fCHECK_005fS3_005fMETHODS_005fSHOW_005fPOSSIBLE_005fISSUES_005f"><code>_R_CHECK_S3_METHODS_SHOW_POSSIBLE_ISSUES_</code></a></td><td class="printindex-index-section"><a href="#Tools">Tools</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_005fR_005fCHECK_005fSCREEN_005fDEVICE_005f"><code>_R_CHECK_SCREEN_DEVICE_</code></a></td><td class="printindex-index-section"><a href="#Tools">Tools</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_005fR_005fCHECK_005fSERIALIZATION_005f"><code>_R_CHECK_SERIALIZATION_</code></a></td><td class="printindex-index-section"><a href="#Tools">Tools</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_005fR_005fCHECK_005fSHLIB_005fOPENMP_005fFLAGS_005f"><code>_R_CHECK_SHLIB_OPENMP_FLAGS_</code></a></td><td class="printindex-index-section"><a href="#Tools">Tools</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_005fR_005fCHECK_005fSKIP_005fARCH_005f"><code>_R_CHECK_SKIP_ARCH_</code></a></td><td class="printindex-index-section"><a href="#Tools">Tools</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_005fR_005fCHECK_005fSKIP_005fEXAMPLES_005fARCH_005f"><code>_R_CHECK_SKIP_EXAMPLES_ARCH_</code></a></td><td class="printindex-index-section"><a href="#Tools">Tools</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_005fR_005fCHECK_005fSKIP_005fTESTS_005fARCH_005f"><code>_R_CHECK_SKIP_TESTS_ARCH_</code></a></td><td class="printindex-index-section"><a href="#Tools">Tools</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_005fR_005fCHECK_005fSRC_005fMINUS_005fW_005fIMPLICIT_005f"><code>_R_CHECK_SRC_MINUS_W_IMPLICIT_</code></a></td><td class="printindex-index-section"><a href="#Tools">Tools</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_005fR_005fCHECK_005fSRC_005fMINUS_005fW_005fUNUSED_005f"><code>_R_CHECK_SRC_MINUS_W_UNUSED_</code></a></td><td class="printindex-index-section"><a href="#Tools">Tools</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_005fR_005fCHECK_005fSUBDIRS_005fNOCASE_005f"><code>_R_CHECK_SUBDIRS_NOCASE_</code></a></td><td class="printindex-index-section"><a href="#Tools">Tools</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_005fR_005fCHECK_005fSUBDIRS_005fSTRICT_005f"><code>_R_CHECK_SUBDIRS_STRICT_</code></a></td><td class="printindex-index-section"><a href="#Tools">Tools</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_005fR_005fCHECK_005fSUGGESTS_005fONLY_005f"><code>_R_CHECK_SUGGESTS_ONLY_</code></a></td><td class="printindex-index-section"><a href="#Tools">Tools</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_005fR_005fCHECK_005fSYSTEM_005fCLOCK_005f"><code>_R_CHECK_SYSTEM_CLOCK_</code></a></td><td class="printindex-index-section"><a href="#Tools">Tools</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_005fR_005fCHECK_005fTEST_005fTIMING_005fCPU_005fTO_005fELAPSED_005fTHRESHOLD_005f"><code>_R_CHECK_TEST_TIMING_CPU_TO_ELAPSED_THRESHOLD_</code></a></td><td class="printindex-index-section"><a href="#Tools">Tools</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_005fR_005fCHECK_005fTESTS_005fELAPSED_005fTIMEOUT_005f"><code>_R_CHECK_TESTS_ELAPSED_TIMEOUT_</code></a></td><td class="printindex-index-section"><a href="#Tools">Tools</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_005fR_005fCHECK_005fTESTS_005fNLINES_005f"><code>_R_CHECK_TESTS_NLINES_</code></a></td><td class="printindex-index-section"><a href="#Tools">Tools</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_005fR_005fCHECK_005fTHINGS_005fIN_005fCHECK_005fDIR_005f"><code>_R_CHECK_THINGS_IN_CHECK_DIR_</code></a></td><td class="printindex-index-section"><a href="#Tools">Tools</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_005fR_005fCHECK_005fTHINGS_005fIN_005fOTHER_005fDIRS_005f"><code>_R_CHECK_THINGS_IN_OTHER_DIRS_</code></a></td><td class="printindex-index-section"><a href="#Tools">Tools</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_005fR_005fCHECK_005fTHINGS_005fIN_005fTEMP_005fDIR_005f"><code>_R_CHECK_THINGS_IN_TEMP_DIR_</code></a></td><td class="printindex-index-section"><a href="#Tools">Tools</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_005fR_005fCHECK_005fTIMINGS_005f"><code>_R_CHECK_TIMINGS_</code></a></td><td class="printindex-index-section"><a href="#Tools">Tools</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_005fR_005fCHECK_005fTOPLEVEL_005fFILES_005f"><code>_R_CHECK_TOPLEVEL_FILES_</code></a></td><td class="printindex-index-section"><a href="#Tools">Tools</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_005fR_005fCHECK_005fUNDOC_005fUSE_005fALL_005fNAMES_005f"><code>_R_CHECK_UNDOC_USE_ALL_NAMES_</code></a></td><td class="printindex-index-section"><a href="#Tools">Tools</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_005fR_005fCHECK_005fUNSAFE_005fCALLS_005f"><code>_R_CHECK_UNSAFE_CALLS_</code></a></td><td class="printindex-index-section"><a href="#Tools">Tools</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_005fR_005fCHECK_005fURLS_005fSHOW_005f301_005fSTATUS_005f"><code>_R_CHECK_URLS_SHOW_301_STATUS_</code></a></td><td class="printindex-index-section"><a href="#Tools">Tools</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_005fR_005fCHECK_005fUSE_005fCODETOOLS_005f"><code>_R_CHECK_USE_CODETOOLS_</code></a></td><td class="printindex-index-section"><a href="#Tools">Tools</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_005fR_005fCHECK_005fUSE_005fINSTALL_005fLOG_005f"><code>_R_CHECK_USE_INSTALL_LOG_</code></a></td><td class="printindex-index-section"><a href="#Tools">Tools</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_005fR_005fCHECK_005fVALIDATE_005fUTF8_005f"><code>_R_CHECK_VALIDATE_UTF8_</code></a></td><td class="printindex-index-section"><a href="#Tools">Tools</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_005fR_005fCHECK_005fVC_005fDIRS_005f"><code>_R_CHECK_VC_DIRS_</code></a></td><td class="printindex-index-section"><a href="#Tools">Tools</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_005fR_005fCHECK_005fVIGNETTE_005fTIMING_005fCPU_005fTO_005fELAPSED_005fTHRESHOLD_005f"><code>_R_CHECK_VIGNETTE_TIMING_CPU_TO_ELAPSED_THRESHOLD_</code></a></td><td class="printindex-index-section"><a href="#Tools">Tools</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_005fR_005fCHECK_005fVIGNETTES_005fNLINES_005f"><code>_R_CHECK_VIGNETTES_NLINES_</code></a></td><td class="printindex-index-section"><a href="#Tools">Tools</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_005fR_005fCHECK_005fVIGNETTES_005fSKIP_005fRUN_005fMAYBE_005f"><code>_R_CHECK_VIGNETTES_SKIP_RUN_MAYBE_</code></a></td><td class="printindex-index-section"><a href="#Tools">Tools</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_005fR_005fCHECK_005fWALL_005fFORTRAN_005f"><code>_R_CHECK_WALL_FORTRAN_</code></a></td><td class="printindex-index-section"><a href="#Tools">Tools</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_005fR_005fCHECK_005fWINDOWS_005fDEVICE_005f"><code>_R_CHECK_WINDOWS_DEVICE_</code></a></td><td class="printindex-index-section"><a href="#Tools">Tools</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_005fR_005fCHECK_005fXREFS_005fMIND_005fSUSPECT_005fANCHORS_005f"><code>_R_CHECK_XREFS_MIND_SUSPECT_ANCHORS_</code></a></td><td class="printindex-index-section"><a href="#Tools">Tools</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_005fR_005fCHECK_005fXREFS_005fPKGS_005fARE_005fDECLARED_005f"><code>_R_CHECK_XREFS_PKGS_ARE_DECLARED_</code></a></td><td class="printindex-index-section"><a href="#Tools">Tools</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_005fR_005fCHECK_005fXREFS_005fREPOSITORIES_005f"><code>_R_CHECK_XREFS_REPOSITORIES_</code></a></td><td class="printindex-index-section"><a href="#Tools">Tools</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_005fR_005fCHECK_005fXREFS_005fUSE_005fALIASES_005fFROM_005fCRAN_005f"><code>_R_CHECK_XREFS_USE_ALIASES_FROM_CRAN_</code></a></td><td class="printindex-index-section"><a href="#Tools">Tools</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_005fR_005fINSTALL_005fLIBS_005fONLY_005fFORCE_005fDEPENDS_005fIMPORTS_005f"><code>_R_INSTALL_LIBS_ONLY_FORCE_DEPENDS_IMPORTS_</code></a></td><td class="printindex-index-section"><a href="#Tools">Tools</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_005fR_005fSHLIB_005fBUILD_005fOBJECTS_005fSYMBOL_005fTABLES_005f"><code>_R_SHLIB_BUILD_OBJECTS_SYMBOL_TABLES_</code></a></td><td class="printindex-index-section"><a href="#Tools">Tools</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_005fR_005fWIN_005fCHECK_005fINVALID_005fPARAMETERS_005f"><code>_R_WIN_CHECK_INVALID_PARAMETERS_</code></a></td><td class="printindex-index-section"><a href="#Tools">Tools</a></td></tr> <tr><td colspan="3"><hr></td></tr> <tr><th id="Function-and-variable-index_vr_symbol-2">.</th></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_002eDevice"><code>.Device</code></a></td><td class="printindex-index-section"><a href="#Base-environment">Base environment</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_002eDevices"><code>.Devices</code></a></td><td class="printindex-index-section"><a href="#Base-environment">Base environment</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_002eInternal"><code>.Internal</code></a></td><td class="printindex-index-section"><a href="#g_t_002eInternal-vs-_002ePrimitive">.Internal vs .Primitive</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_002eLast_002evalue"><code>.Last.value</code></a></td><td class="printindex-index-section"><a href="#Base-environment">Base environment</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_002eOptions"><code>.Options</code></a></td><td class="printindex-index-section"><a href="#Base-environment">Base environment</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_002ePrimitive"><code>.Primitive</code></a></td><td class="printindex-index-section"><a href="#g_t_002eInternal-vs-_002ePrimitive">.Internal vs .Primitive</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_002eRandom_002eseed"><code>.Random.seed</code></a></td><td class="printindex-index-section"><a href="#Global-environment">Global environment</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_002eSavedPlots"><code>.SavedPlots</code></a></td><td class="printindex-index-section"><a href="#Global-environment">Global environment</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_002eTraceback"><code>.Traceback</code></a></td><td class="printindex-index-section"><a href="#Base-environment">Base environment</a></td></tr> <tr><td colspan="3"><hr></td></tr> <tr><th id="Function-and-variable-index_vr_letter-A">A</th></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-alloca"><code>alloca</code></a></td><td class="printindex-index-section"><a href="#Memory-allocators">Memory allocators</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-ARGSUSED"><code>ARGSUSED</code></a></td><td class="printindex-index-section"><a href="#Rest-of-header">Rest of header</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-ATTRIB"><code>ATTRIB</code></a></td><td class="printindex-index-section"><a href="#Attributes">Attributes</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-attribute_005fhidden"><code>attribute_hidden</code></a></td><td class="printindex-index-section"><a href="#Hiding-C-entry-points">Hiding C entry points</a></td></tr> <tr><td colspan="3"><hr></td></tr> <tr><th id="Function-and-variable-index_vr_letter-C">C</th></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-copyMostAttrib"><code>copyMostAttrib</code></a></td><td class="printindex-index-section"><a href="#Attributes">Attributes</a></td></tr> <tr><td colspan="3"><hr></td></tr> <tr><th id="Function-and-variable-index_vr_letter-D">D</th></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-DDVAL"><code>DDVAL</code></a></td><td class="printindex-index-section"><a href="#Rest-of-header">Rest of header</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-debug-bit"><code>debug bit</code></a></td><td class="printindex-index-section"><a href="#Rest-of-header">Rest of header</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-DispatchGeneric"><code>DispatchGeneric</code></a></td><td class="printindex-index-section"><a href="#Argument-evaluation">Argument evaluation</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-DispatchOrEval"><code>DispatchOrEval</code></a></td><td class="printindex-index-section"><a href="#Argument-evaluation">Argument evaluation</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-dump_002eframes"><code>dump.frames</code></a></td><td class="printindex-index-section"><a href="#Global-environment">Global environment</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-DUPLICATE_005fATTRIB"><code>DUPLICATE_ATTRIB</code></a></td><td class="printindex-index-section"><a href="#Attributes">Attributes</a></td></tr> <tr><td colspan="3"><hr></td></tr> <tr><th id="Function-and-variable-index_vr_letter-E">E</th></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-emacs"><code>emacs</code></a></td><td class="printindex-index-section"><a href="#R-coding-standards">R coding standards</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-error"><code>error</code></a></td><td class="printindex-index-section"><a href="#Warnings-and-errors">Warnings and errors</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-errorcall"><code>errorcall</code></a></td><td class="printindex-index-section"><a href="#Warnings-and-errors">Warnings and errors</a></td></tr> <tr><td colspan="3"><hr></td></tr> <tr><th id="Function-and-variable-index_vr_letter-G">G</th></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-gp-bits"><code>gp bits</code></a></td><td class="printindex-index-section"><a href="#Rest-of-header">Rest of header</a></td></tr> <tr><td colspan="3"><hr></td></tr> <tr><th id="Function-and-variable-index_vr_letter-I">I</th></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-invisible"><code>invisible</code></a></td><td class="printindex-index-section"><a href="#Autoprinting">Autoprinting</a></td></tr> <tr><td colspan="3"><hr></td></tr> <tr><th id="Function-and-variable-index_vr_letter-L">L</th></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-last_002ewarning"><code>last.warning</code></a></td><td class="printindex-index-section"><a href="#Base-environment">Base environment</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-LEVELS"><code>LEVELS</code></a></td><td class="printindex-index-section"><a href="#Rest-of-header">Rest of header</a></td></tr> <tr><td colspan="3"><hr></td></tr> <tr><th id="Function-and-variable-index_vr_letter-M">M</th></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-make"><code>make</code></a></td><td class="printindex-index-section"><a href="#R-coding-standards">R coding standards</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-makeinfo"><code>makeinfo</code></a></td><td class="printindex-index-section"><a href="#R-coding-standards">R coding standards</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-MISSING"><code>MISSING</code></a></td><td class="printindex-index-section"><a href="#Rest-of-header">Rest of header</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-MISSING-1"><code>MISSING</code></a></td><td class="printindex-index-section"><a href="#Missingness">Missingness</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-mkChar"><code>mkChar</code></a></td><td class="printindex-index-section"><a href="#The-CHARSXP-cache">The CHARSXP cache</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-mkCharLenCE"><code>mkCharLenCE</code></a></td><td class="printindex-index-section"><a href="#The-CHARSXP-cache">The CHARSXP cache</a></td></tr> <tr><td colspan="3"><hr></td></tr> <tr><th id="Function-and-variable-index_vr_letter-N">N</th></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-NAMED"><code>NAMED</code></a></td><td class="printindex-index-section"><a href="#Rest-of-header">Rest of header</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-NAMED-1"><code>NAMED</code></a></td><td class="printindex-index-section"><a href="#Argument-evaluation">Argument evaluation</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-NAMED-2"><code>NAMED</code></a></td><td class="printindex-index-section"><a href="#g_t_002eInternal-vs-_002ePrimitive">.Internal vs .Primitive</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-named-bits"><code>named bits</code></a></td><td class="printindex-index-section"><a href="#Rest-of-header">Rest of header</a></td></tr> <tr><td colspan="3"><hr></td></tr> <tr><th id="Function-and-variable-index_vr_letter-P">P</th></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-Perl"><code>Perl</code></a></td><td class="printindex-index-section"><a href="#R-coding-standards">R coding standards</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-PRIMPRINT"><code>PRIMPRINT</code></a></td><td class="printindex-index-section"><a href="#Autoprinting">Autoprinting</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-PRSEEN"><code>PRSEEN</code></a></td><td class="printindex-index-section"><a href="#Rest-of-header">Rest of header</a></td></tr> <tr><td colspan="3"><hr></td></tr> <tr><th id="Function-and-variable-index_vr_letter-R">R</th></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-R_005falloc"><code>R_alloc</code></a></td><td class="printindex-index-section"><a href="#Memory-allocators">Memory allocators</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-R_005fAllocStringBuffer"><code>R_AllocStringBuffer</code></a></td><td class="printindex-index-section"><a href="#Memory-allocators">Memory allocators</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-R_005fBaseNamespace"><code>R_BaseNamespace</code></a></td><td class="printindex-index-section"><a href="#Namespaces">Namespaces</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-R_005fCalloc"><code>R_Calloc</code></a></td><td class="printindex-index-section"><a href="#Memory-allocators">Memory allocators</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-R_005fCheckStack"><code>R_CheckStack</code></a></td><td class="printindex-index-section"><a href="#Memory-allocators">Memory allocators</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-R_005fCheckStack2"><code>R_CheckStack2</code></a></td><td class="printindex-index-section"><a href="#Memory-allocators">Memory allocators</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-R_005fFree"><code>R_Free</code></a></td><td class="printindex-index-section"><a href="#Memory-allocators">Memory allocators</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-R_005fFreeStringBuffer"><code>R_FreeStringBuffer</code></a></td><td class="printindex-index-section"><a href="#Memory-allocators">Memory allocators</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-R_005fFreeStringBufferL"><code>R_FreeStringBufferL</code></a></td><td class="printindex-index-section"><a href="#Memory-allocators">Memory allocators</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-R_005fMissingArg"><code>R_MissingArg</code></a></td><td class="printindex-index-section"><a href="#Missingness">Missingness</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-R_005fRealloc"><code>R_Realloc</code></a></td><td class="printindex-index-section"><a href="#Memory-allocators">Memory allocators</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-R_005fVisible"><code>R_Visible</code></a></td><td class="printindex-index-section"><a href="#Autoprinting">Autoprinting</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-Rdll_002ehide"><code>Rdll.hide</code></a></td><td class="printindex-index-section"><a href="#Hiding-C-entry-points">Hiding C entry points</a></td></tr> <tr><td colspan="3"><hr></td></tr> <tr><th id="Function-and-variable-index_vr_letter-S">S</th></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-SET_005fARGUSED"><code>SET_ARGUSED</code></a></td><td class="printindex-index-section"><a href="#Rest-of-header">Rest of header</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-SET_005fATTRIB"><code>SET_ATTRIB</code></a></td><td class="printindex-index-section"><a href="#Attributes">Attributes</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-SET_005fDDVAL"><code>SET_DDVAL</code></a></td><td class="printindex-index-section"><a href="#Rest-of-header">Rest of header</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-SET_005fMISSING"><code>SET_MISSING</code></a></td><td class="printindex-index-section"><a href="#Rest-of-header">Rest of header</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-SET_005fNAMED"><code>SET_NAMED</code></a></td><td class="printindex-index-section"><a href="#Rest-of-header">Rest of header</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-SETLEVELS"><code>SETLEVELS</code></a></td><td class="printindex-index-section"><a href="#Rest-of-header">Rest of header</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-spare-bit"><code>spare bit</code></a></td><td class="printindex-index-section"><a href="#Rest-of-header">Rest of header</a></td></tr> <tr><td colspan="3"><hr></td></tr> <tr><th id="Function-and-variable-index_vr_letter-T">T</th></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-trace-bit"><code>trace bit</code></a></td><td class="printindex-index-section"><a href="#Rest-of-header">Rest of header</a></td></tr> <tr><td colspan="3"><hr></td></tr> <tr><th id="Function-and-variable-index_vr_letter-U">U</th></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-UseMethod"><code>UseMethod</code></a></td><td class="printindex-index-section"><a href="#Contexts">Contexts</a></td></tr> <tr><td colspan="3"><hr></td></tr> <tr><th id="Function-and-variable-index_vr_letter-V">V</th></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-vmaxget"><code>vmaxget</code></a></td><td class="printindex-index-section"><a href="#Memory-allocators">Memory allocators</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-vmaxset"><code>vmaxset</code></a></td><td class="printindex-index-section"><a href="#Memory-allocators">Memory allocators</a></td></tr> <tr><td colspan="3"><hr></td></tr> <tr><th id="Function-and-variable-index_vr_letter-W">W</th></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-warning"><code>warning</code></a></td><td class="printindex-index-section"><a href="#Warnings-and-errors">Warnings and errors</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-warningcall"><code>warningcall</code></a></td><td class="printindex-index-section"><a href="#Warnings-and-errors">Warnings and errors</a></td></tr> <tr><td colspan="3"><hr></td></tr> </table> <table summary="" class="vr-letters-footer-printindex"><tr><th>Jump to: </th><td><a class="summary-letter-printindex" href="#Function-and-variable-index_vr_symbol-1"><b>_</b></a> <a class="summary-letter-printindex" href="#Function-and-variable-index_vr_symbol-2"><b>.</b></a> <br> <a class="summary-letter-printindex" href="#Function-and-variable-index_vr_letter-A"><b>A</b></a> <a class="summary-letter-printindex" href="#Function-and-variable-index_vr_letter-C"><b>C</b></a> <a class="summary-letter-printindex" href="#Function-and-variable-index_vr_letter-D"><b>D</b></a> <a class="summary-letter-printindex" href="#Function-and-variable-index_vr_letter-E"><b>E</b></a> <a class="summary-letter-printindex" href="#Function-and-variable-index_vr_letter-G"><b>G</b></a> <a class="summary-letter-printindex" href="#Function-and-variable-index_vr_letter-I"><b>I</b></a> <a class="summary-letter-printindex" href="#Function-and-variable-index_vr_letter-L"><b>L</b></a> <a class="summary-letter-printindex" href="#Function-and-variable-index_vr_letter-M"><b>M</b></a> <a class="summary-letter-printindex" href="#Function-and-variable-index_vr_letter-N"><b>N</b></a> <a class="summary-letter-printindex" href="#Function-and-variable-index_vr_letter-P"><b>P</b></a> <a class="summary-letter-printindex" href="#Function-and-variable-index_vr_letter-R"><b>R</b></a> <a class="summary-letter-printindex" href="#Function-and-variable-index_vr_letter-S"><b>S</b></a> <a class="summary-letter-printindex" href="#Function-and-variable-index_vr_letter-T"><b>T</b></a> <a class="summary-letter-printindex" href="#Function-and-variable-index_vr_letter-U"><b>U</b></a> <a class="summary-letter-printindex" href="#Function-and-variable-index_vr_letter-V"><b>V</b></a> <a class="summary-letter-printindex" href="#Function-and-variable-index_vr_letter-W"><b>W</b></a> </td></tr></table> </div> <hr> </div> <div class="unnumbered-level-extent" id="Concept-index"> <div class="nav-panel"> <p> Previous: <a href="#Function-and-variable-index" accesskey="p" rel="prev">Function and variable index</a>, Up: <a href="#Top" accesskey="u" rel="up">R Internals</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-variable-index" title="Index" rel="index">Index</a>]</p> </div> <h2 class="unnumbered" id="Concept-index-1"><span>Concept index<a class="copiable-link" href="#Concept-index-1"> ¶</a></span></h2> <div class="printindex cp-printindex"> <table summary="" class="cp-letters-header-printindex"><tr><th>Jump to: </th><td><a class="summary-letter-printindex" href="#Concept-index_cp_symbol-1"><b>.</b></a> <br> <a class="summary-letter-printindex" href="#Concept-index_cp_letter-A"><b>A</b></a> <a class="summary-letter-printindex" href="#Concept-index_cp_letter-B"><b>B</b></a> <a class="summary-letter-printindex" href="#Concept-index_cp_letter-C"><b>C</b></a> <a class="summary-letter-printindex" href="#Concept-index_cp_letter-E"><b>E</b></a> <a class="summary-letter-printindex" href="#Concept-index_cp_letter-F"><b>F</b></a> <a class="summary-letter-printindex" href="#Concept-index_cp_letter-G"><b>G</b></a> <a class="summary-letter-printindex" href="#Concept-index_cp_letter-L"><b>L</b></a> <a class="summary-letter-printindex" href="#Concept-index_cp_letter-M"><b>M</b></a> <a class="summary-letter-printindex" href="#Concept-index_cp_letter-N"><b>N</b></a> <a class="summary-letter-printindex" href="#Concept-index_cp_letter-P"><b>P</b></a> <a class="summary-letter-printindex" href="#Concept-index_cp_letter-S"><b>S</b></a> <a class="summary-letter-printindex" href="#Concept-index_cp_letter-U"><b>U</b></a> <a class="summary-letter-printindex" href="#Concept-index_cp_letter-V"><b>V</b></a> <a class="summary-letter-printindex" href="#Concept-index_cp_letter-W"><b>W</b></a> </td></tr></table> <table summary="" class="cp-entries-printindex" border="0"> <tr><td></td><th class="entries-header-printindex">Index Entry</th><th class="sections-header-printindex">Section</th></tr> <tr><td colspan="3"><hr></td></tr> <tr><th id="Concept-index_cp_symbol-1">.</th></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_002e_002e_002e-argument">... argument</a></td><td class="printindex-index-section"><a href="#Rest-of-header">Rest of header</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_002e_002e_002e-argument-1">... argument</a></td><td class="printindex-index-section"><a href="#Dot_002ddot_002ddot-arguments">Dot-dot-dot arguments</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-_002eInternal-function">.Internal function</a></td><td class="printindex-index-section"><a href="#Argument-evaluation">Argument evaluation</a></td></tr> <tr><td colspan="3"><hr></td></tr> <tr><th id="Concept-index_cp_letter-A">A</th></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-allocation-classes">allocation classes</a></td><td class="printindex-index-section"><a href="#Allocation-classes">Allocation classes</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-argument-evaluation">argument evaluation</a></td><td class="printindex-index-section"><a href="#Argument-evaluation">Argument evaluation</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-argument-list">argument list</a></td><td class="printindex-index-section"><a href="#SEXPTYPEs">SEXPTYPEs</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-atomic-vector-type">atomic vector type</a></td><td class="printindex-index-section"><a href="#SEXPTYPEs">SEXPTYPEs</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-attributes">attributes</a></td><td class="printindex-index-section"><a href="#Attributes">Attributes</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-attributes_002c-preserving">attributes, preserving</a></td><td class="printindex-index-section"><a href="#Attributes">Attributes</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-autoprinting">autoprinting</a></td><td class="printindex-index-section"><a href="#Autoprinting">Autoprinting</a></td></tr> <tr><td colspan="3"><hr></td></tr> <tr><th id="Concept-index_cp_letter-B">B</th></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-base-environment">base environment</a></td><td class="printindex-index-section"><a href="#Environments-and-variable-lookup">Environments and variable lookup</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-base-environment-1">base environment</a></td><td class="printindex-index-section"><a href="#Base-environment">Base environment</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-base-namespace">base namespace</a></td><td class="printindex-index-section"><a href="#Namespaces">Namespaces</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-builtin-function">builtin function</a></td><td class="printindex-index-section"><a href="#Argument-evaluation">Argument evaluation</a></td></tr> <tr><td colspan="3"><hr></td></tr> <tr><th id="Concept-index_cp_letter-C">C</th></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-coding-standards">coding standards</a></td><td class="printindex-index-section"><a href="#R-coding-standards">R coding standards</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-context">context</a></td><td class="printindex-index-section"><a href="#Contexts">Contexts</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-copying-semantics">copying semantics</a></td><td class="printindex-index-section"><a href="#Rest-of-header">Rest of header</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-copying-semantics-1">copying semantics</a></td><td class="printindex-index-section"><a href="#Attributes">Attributes</a></td></tr> <tr><td colspan="3"><hr></td></tr> <tr><th id="Concept-index_cp_letter-E">E</th></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-environment">environment</a></td><td class="printindex-index-section"><a href="#Environments-and-variable-lookup">Environments and variable lookup</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-environment_002c-base">environment, base</a></td><td class="printindex-index-section"><a href="#Environments-and-variable-lookup">Environments and variable lookup</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-environment_002c-base-1">environment, base</a></td><td class="printindex-index-section"><a href="#Base-environment">Base environment</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-environment_002c-global">environment, global</a></td><td class="printindex-index-section"><a href="#Global-environment">Global environment</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-expression">expression</a></td><td class="printindex-index-section"><a href="#SEXPTYPEs">SEXPTYPEs</a></td></tr> <tr><td colspan="3"><hr></td></tr> <tr><th id="Concept-index_cp_letter-F">F</th></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-function">function</a></td><td class="printindex-index-section"><a href="#SEXPTYPEs">SEXPTYPEs</a></td></tr> <tr><td colspan="3"><hr></td></tr> <tr><th id="Concept-index_cp_letter-G">G</th></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-garbage-collector">garbage collector</a></td><td class="printindex-index-section"><a href="#The-write-barrier">The write barrier</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-generic_002c-generic">generic, generic</a></td><td class="printindex-index-section"><a href="#Argument-evaluation">Argument evaluation</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-generic_002c-internal">generic, internal</a></td><td class="printindex-index-section"><a href="#Argument-evaluation">Argument evaluation</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-global-environment">global environment</a></td><td class="printindex-index-section"><a href="#Global-environment">Global environment</a></td></tr> <tr><td colspan="3"><hr></td></tr> <tr><th id="Concept-index_cp_letter-L">L</th></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-language-object">language object</a></td><td class="printindex-index-section"><a href="#SEXPTYPEs">SEXPTYPEs</a></td></tr> <tr><td colspan="3"><hr></td></tr> <tr><th id="Concept-index_cp_letter-M">M</th></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-method-dispatch">method dispatch</a></td><td class="printindex-index-section"><a href="#Contexts">Contexts</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-missingness">missingness</a></td><td class="printindex-index-section"><a href="#Missingness">Missingness</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-modules">modules</a></td><td class="printindex-index-section"><a href="#Modules">Modules</a></td></tr> <tr><td colspan="3"><hr></td></tr> <tr><th id="Concept-index_cp_letter-N">N</th></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-namespace">namespace</a></td><td class="printindex-index-section"><a href="#Namespaces">Namespaces</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-namespace_002c-base">namespace, base</a></td><td class="printindex-index-section"><a href="#Namespaces">Namespaces</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-node">node</a></td><td class="printindex-index-section"><a href="#SEXPs">SEXPs</a></td></tr> <tr><td colspan="3"><hr></td></tr> <tr><th id="Concept-index_cp_letter-P">P</th></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-preserving-attributes">preserving attributes</a></td><td class="printindex-index-section"><a href="#Attributes">Attributes</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-primitive-function">primitive function</a></td><td class="printindex-index-section"><a href="#Argument-evaluation">Argument evaluation</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-promise">promise</a></td><td class="printindex-index-section"><a href="#Rest-of-header">Rest of header</a></td></tr> <tr><td colspan="3"><hr></td></tr> <tr><th id="Concept-index_cp_letter-S">S</th></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-S4-type">S4 type</a></td><td class="printindex-index-section"><a href="#SEXPTYPEs">SEXPTYPEs</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-search-path">search path</a></td><td class="printindex-index-section"><a href="#Search-paths">Search paths</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-serialization">serialization</a></td><td class="printindex-index-section"><a href="#Serialization-Formats">Serialization Formats</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-SEXP">SEXP</a></td><td class="printindex-index-section"><a href="#SEXPs">SEXPs</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-SEXPREC">SEXPREC</a></td><td class="printindex-index-section"><a href="#SEXPs">SEXPs</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-SEXPTYPE">SEXPTYPE</a></td><td class="printindex-index-section"><a href="#SEXPTYPEs">SEXPTYPEs</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-SEXPTYPE-table">SEXPTYPE table</a></td><td class="printindex-index-section"><a href="#SEXPTYPEs">SEXPTYPEs</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-special-function">special function</a></td><td class="printindex-index-section"><a href="#Argument-evaluation">Argument evaluation</a></td></tr> <tr><td colspan="3"><hr></td></tr> <tr><th id="Concept-index_cp_letter-U">U</th></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-user-databases">user databases</a></td><td class="printindex-index-section"><a href="#Environments-and-variable-lookup">Environments and variable lookup</a></td></tr> <tr><td colspan="3"><hr></td></tr> <tr><th id="Concept-index_cp_letter-V">V</th></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-variable-lookup">variable lookup</a></td><td class="printindex-index-section"><a href="#Environments-and-variable-lookup">Environments and variable lookup</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-vector-type">vector type</a></td><td class="printindex-index-section"><a href="#The-_0027data_0027">The 'data'</a></td></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-visibility">visibility</a></td><td class="printindex-index-section"><a href="#Visibility">Visibility</a></td></tr> <tr><td colspan="3"><hr></td></tr> <tr><th id="Concept-index_cp_letter-W">W</th></tr> <tr><td></td><td class="printindex-index-entry"><a href="#index-write-barrier">write barrier</a></td><td class="printindex-index-section"><a href="#The-write-barrier">The write barrier</a></td></tr> <tr><td colspan="3"><hr></td></tr> </table> <table summary="" class="cp-letters-footer-printindex"><tr><th>Jump to: </th><td><a class="summary-letter-printindex" href="#Concept-index_cp_symbol-1"><b>.</b></a> <br> <a class="summary-letter-printindex" href="#Concept-index_cp_letter-A"><b>A</b></a> <a class="summary-letter-printindex" href="#Concept-index_cp_letter-B"><b>B</b></a> <a class="summary-letter-printindex" href="#Concept-index_cp_letter-C"><b>C</b></a> <a class="summary-letter-printindex" href="#Concept-index_cp_letter-E"><b>E</b></a> <a class="summary-letter-printindex" href="#Concept-index_cp_letter-F"><b>F</b></a> <a class="summary-letter-printindex" href="#Concept-index_cp_letter-G"><b>G</b></a> <a class="summary-letter-printindex" href="#Concept-index_cp_letter-L"><b>L</b></a> <a class="summary-letter-printindex" href="#Concept-index_cp_letter-M"><b>M</b></a> <a class="summary-letter-printindex" href="#Concept-index_cp_letter-N"><b>N</b></a> <a class="summary-letter-printindex" href="#Concept-index_cp_letter-P"><b>P</b></a> <a class="summary-letter-printindex" href="#Concept-index_cp_letter-S"><b>S</b></a> <a class="summary-letter-printindex" href="#Concept-index_cp_letter-U"><b>U</b></a> <a class="summary-letter-printindex" href="#Concept-index_cp_letter-V"><b>V</b></a> <a class="summary-letter-printindex" href="#Concept-index_cp_letter-W"><b>W</b></a> </td></tr></table> </div> </div> </div> <div class="footnotes-segment"> <hr> <h4 class="footnotes-heading">Footnotes</h4> <h5 class="footnote-body-heading"><a id="FOOT1" href="#DOCF1">(1)</a></h5> <p>strictly, a <code class="code">SEXPREC</code> node; <code class="code">VECTOR_SEXPREC</code> nodes are slightly smaller but followed by data in the node.</p> <h5 class="footnote-body-heading"><a id="FOOT2" href="#DOCF2">(2)</a></h5> <p>a pointer to a function or a symbol to look up the function by name, or a language object to be evaluated to give a function.</p> <h5 class="footnote-body-heading"><a id="FOOT3" href="#DOCF3">(3)</a></h5> <p>The only current use is for hash tables of environments (<code class="code">VECSXP</code>s), where <code class="code">length</code> is the size of the table and <code class="code">truelength</code> is the number of primary slots in use, for the reference hash tables in serialization (<code class="code">VECSXP</code>s), and for ‘growable’ vectors (atomic vectors, <code class="code">VECSXP</code>s and <code class="code">EXPRSXP</code>s) which are created by slightly over-committing when enlarging a vector during subassignment, so that some number of the following enlargements during subassignment can be performed in place), where <code class="code">truelength</code> is the number of slots in use. </p> <h5 class="footnote-body-heading"><a id="FOOT4" href="#DOCF4">(4)</a></h5> <p>Remember that attaching a list or a saved image actually creates and populates an environment and attaches that.</p> <h5 class="footnote-body-heading"><a id="FOOT5" href="#DOCF5">(5)</a></h5> <p>There is currently one other difference: when profiling builtin functions are counted as function calls but specials are not.</p> <h5 class="footnote-body-heading"><a id="FOOT6" href="#DOCF6">(6)</a></h5> <p>the other current example is left brace, which is implemented as a primitive.</p> <h5 class="footnote-body-heading"><a id="FOOT7" href="#DOCF7">(7)</a></h5> <p>only bits 0:4 are currently used for <code class="code">SEXPTYPE</code>s but values 241:255 are used for pseudo-<code class="code">SEXPTYPE</code>s.</p> <h5 class="footnote-body-heading"><a id="FOOT8" href="#DOCF8">(8)</a></h5> <p>Currently the only relevant bits are 0:1, 4, 14:15.</p> <h5 class="footnote-body-heading"><a id="FOOT9" href="#DOCF9">(9)</a></h5> <p>See define <code class="code">USE_UTF8_IF_POSSIBLE</code> in old versions of file <samp class="file">src/main/gram.c</samp>.</p> <h5 class="footnote-body-heading"><a id="FOOT10" href="#DOCF10">(10)</a></h5> <p>or UTF-16 if support for surrogates is enabled in the OS, which it used not to be when encoding support was added to R.</p> <h5 class="footnote-body-heading"><a id="FOOT11" href="#DOCF11">(11)</a></h5> <p>but not the GraphApp toolkit.</p> <h5 class="footnote-body-heading"><a id="FOOT12" href="#DOCF12">(12)</a></h5> <p>This can also create non-S4 objects, as in <code class="code">new("integer")</code>.</p> <h5 class="footnote-body-heading"><a id="FOOT13" href="#DOCF13">(13)</a></h5> <p>although this is not recommended as it is less future-proof.</p> <h5 class="footnote-body-heading"><a id="FOOT14" href="#DOCF14">(14)</a></h5> <p>but apparently not on Windows.</p> <h5 class="footnote-body-heading"><a id="FOOT15" href="#DOCF15">(15)</a></h5> <p>The C code is in files <samp class="file">base.c</samp>, <samp class="file">graphics.c</samp>, <samp class="file">par.c</samp>, <samp class="file">plot.c</samp> and <samp class="file">plot3d.c</samp> in directory <samp class="file">src/main</samp>.</p> <h5 class="footnote-body-heading"><a id="FOOT16" href="#DOCF16">(16)</a></h5> <p>although that needs to be handled carefully, as for example the <code class="code">circle</code> callback is given a radius (and that should be interpreted as in the x units).</p> <h5 class="footnote-body-heading"><a id="FOOT17" href="#DOCF17">(17)</a></h5> <p>It is possible for the device to find the <code class="code">GEDevDesc</code> which points to its <code class="code">DevDesc</code>, and this is done often enough that there is a convenience function <code class="code">desc2GEDesc</code> to do so.</p> <h5 class="footnote-body-heading"><a id="FOOT18" href="#DOCF18">(18)</a></h5> <p>Calling <code class="code">R_CheckDeviceAvailable()</code> ensures there is a free slot or throws an error.</p> <h5 class="footnote-body-heading"><a id="FOOT19" href="#DOCF19">(19)</a></h5> <p>in device coordinates</p> <h5 class="footnote-body-heading"><a id="FOOT20" href="#DOCF20">(20)</a></h5> <p>It is technically possible to use alpha-blending on metafile devices such as printers, but it seems few drivers have support for this.</p> <h5 class="footnote-body-heading"><a id="FOOT21" href="#DOCF21">(21)</a></h5> <p>an Xcode project, in SVN at <a class="uref" href="https://svn.r-project.org/R-packages/trunk/Mac-GUI/">https://svn.r-project.org/R-packages/trunk/Mac-GUI/</a>.</p> <h5 class="footnote-body-heading"><a id="FOOT22" href="#DOCF22">(22)</a></h5> <p>under Windows, junction points, or copies if environment variable <code class="env">R_WIN_NO_JUNCTIONS</code> has a non-empty value.</p> <h5 class="footnote-body-heading"><a id="FOOT23" href="#DOCF23">(23)</a></h5> <p>The usual culprits are calls to compiled code <em class="emph">via</em> <code class="code">.Call</code> or <code class="code">.External</code> which alter their arguments.</p> <h5 class="footnote-body-heading"><a id="FOOT24" href="#DOCF24">(24)</a></h5> <p>things which the byte compiler assumes do not change, e.g. function bodies.</p> <h5 class="footnote-body-heading"><a id="FOOT25" href="#DOCF25">(25)</a></h5> <p>Linux distributions tend to unbundle <samp class="file">texinfo.tex</samp> from ‘<samp class="samp">texinfo</samp>’.</p> <h5 class="footnote-body-heading"><a id="FOOT26" href="#DOCF26">(26)</a></h5> <p>but <code class="code">LENGTH</code> is a macro under some internal uses.</p> </div> </body> </html>