forked from csgillespie/efficientR
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path9-efficient-memory.html
237 lines (214 loc) · 15.7 KB
/
9-efficient-memory.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="pandoc" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="author" content="Colin Gillespie and Robin Lovelace" />
<meta name="date" content="2016-02-16" />
<script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"></script>
<title>Efficient R programming</title>
<script src="libs/jquery-1.11.3/jquery.min.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link href="libs/bootstrap-3.3.5/css/bootstrap.min.css" rel="stylesheet" />
<script src="libs/bootstrap-3.3.5/js/bootstrap.min.js"></script>
<script src="libs/bootstrap-3.3.5/shim/html5shiv.min.js"></script>
<script src="libs/bootstrap-3.3.5/shim/respond.min.js"></script>
<style type="text/css">code{white-space: pre;}</style>
<style type="text/css">
div.sourceCode { overflow-x: auto; }
table.sourceCode, tr.sourceCode, td.lineNumbers, td.sourceCode {
margin: 0; padding: 0; vertical-align: baseline; border: none; }
table.sourceCode { width: 100%; line-height: 100%; }
td.lineNumbers { text-align: right; padding-right: 4px; padding-left: 4px; color: #aaaaaa; border-right: 1px solid #aaaaaa; }
td.sourceCode { padding-left: 5px; }
code > span.kw { color: #007020; font-weight: bold; } /* Keyword */
code > span.dt { color: #902000; } /* DataType */
code > span.dv { color: #40a070; } /* DecVal */
code > span.bn { color: #40a070; } /* BaseN */
code > span.fl { color: #40a070; } /* Float */
code > span.ch { color: #4070a0; } /* Char */
code > span.st { color: #4070a0; } /* String */
code > span.co { color: #60a0b0; font-style: italic; } /* Comment */
code > span.ot { color: #007020; } /* Other */
code > span.al { color: #ff0000; font-weight: bold; } /* Alert */
code > span.fu { color: #06287e; } /* Function */
code > span.er { color: #ff0000; font-weight: bold; } /* Error */
code > span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warning */
code > span.cn { color: #880000; } /* Constant */
code > span.sc { color: #4070a0; } /* SpecialChar */
code > span.vs { color: #4070a0; } /* VerbatimString */
code > span.ss { color: #bb6688; } /* SpecialString */
code > span.im { } /* Import */
code > span.va { color: #19177c; } /* Variable */
code > span.cf { color: #007020; font-weight: bold; } /* ControlFlow */
code > span.op { color: #666666; } /* Operator */
code > span.bu { } /* BuiltIn */
code > span.ex { } /* Extension */
code > span.pp { color: #bc7a00; } /* Preprocessor */
code > span.at { color: #7d9029; } /* Attribute */
code > span.do { color: #ba2121; font-style: italic; } /* Documentation */
code > span.an { color: #60a0b0; font-weight: bold; font-style: italic; } /* Annotation */
code > span.cv { color: #60a0b0; font-weight: bold; font-style: italic; } /* CommentVar */
code > span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Information */
</style>
<style type="text/css">
pre:not([class]) {
background-color: white;
}
</style>
<style type = "text/css">
.main-container {
max-width: 940px;
margin-left: auto;
margin-right: auto;
}
code {
color: inherit;
background-color: rgba(0, 0, 0, 0.04);
}
img {
max-width:100%;
height: auto;
}
</style>
</head>
<body>
<div class="container-fluid main-container">
<div class="row">
<div class="col-sm-12">
<div id="TOC">
<ul>
<li class="has-sub"><a href="index.html#building-the-book"><span class="toc-section-number">1</span> Building the book</a><ul>
<li><a href="1-1-dependencies-for-this-book.html#dependencies-for-this-book"><span class="toc-section-number">1.1</span> Dependencies for this book</a></li>
</ul></li>
<li><a href="2-introduction.html#introduction"><span class="toc-section-number">2</span> Introduction</a></li>
<li class="has-sub"><a href="3-efficient-set-up.html#efficient-set-up"><span class="toc-section-number">3</span> Efficient set-up</a><ul>
<li class="has-sub"><a href="3-1-operating-system.html#operating-system"><span class="toc-section-number">3.1</span> Operating system</a><ul>
<li><a href="3-1-operating-system.html#operating-system-and-resource-monitoring"><span class="toc-section-number">3.1.1</span> Operating system and resource monitoring</a></li>
<li><a href="3-1-operating-system.html#exercises"><span class="toc-section-number">3.1.2</span> Exercises</a></li>
</ul></li>
<li class="has-sub"><a href="3-2-r-version.html#r-version"><span class="toc-section-number">3.2</span> R version</a><ul>
<li><a href="3-2-r-version.html#installing-r"><span class="toc-section-number">3.2.1</span> Installing R</a></li>
<li><a href="3-2-r-version.html#updating-r"><span class="toc-section-number">3.2.2</span> Updating R</a></li>
<li><a href="3-2-r-version.html#installing-r-packages"><span class="toc-section-number">3.2.3</span> Installing R packages</a></li>
<li><a href="3-2-r-version.html#deps"><span class="toc-section-number">3.2.4</span> Installing R packages with dependencies</a></li>
<li><a href="3-2-r-version.html#updating-r-packages"><span class="toc-section-number">3.2.5</span> Updating R packages</a></li>
<li><a href="3-2-r-version.html#exercises-1"><span class="toc-section-number">3.2.6</span> Exercises</a></li>
</ul></li>
<li class="has-sub"><a href="3-3-r-startup.html#r-startup"><span class="toc-section-number">3.3</span> R startup</a><ul>
<li><a href="3-3-r-startup.html#rprofile"><span class="toc-section-number">3.3.1</span> The <code>.Rprofile</code> file</a></li>
<li><a href="3-3-r-startup.html#example-.rprofile-settings"><span class="toc-section-number">3.3.2</span> Example <code>.Rprofile</code> settings</a></li>
<li><a href="3-3-r-startup.html#renviron"><span class="toc-section-number">3.3.3</span> The <code>.Renviron</code> file</a></li>
<li><a href="3-3-r-startup.html#exercises-2"><span class="toc-section-number">3.3.4</span> Exercises</a></li>
</ul></li>
<li class="has-sub"><a href="3-4-rstudio.html#rstudio"><span class="toc-section-number">3.4</span> RStudio</a><ul>
<li><a href="3-4-rstudio.html#install-rstudio"><span class="toc-section-number">3.4.1</span> Installing and updating RStudio</a></li>
<li><a href="3-4-rstudio.html#window-pane-layout"><span class="toc-section-number">3.4.2</span> Window pane layout</a></li>
<li><a href="3-4-rstudio.html#exercises-3"><span class="toc-section-number">3.4.3</span> Exercises</a></li>
<li><a href="3-4-rstudio.html#rstudio-options"><span class="toc-section-number">3.4.4</span> RStudio options</a></li>
<li><a href="3-4-rstudio.html#auto-completion"><span class="toc-section-number">3.4.5</span> Auto-completion</a></li>
<li><a href="3-4-rstudio.html#keyboard-shortcuts"><span class="toc-section-number">3.4.6</span> Keyboard shortcuts</a></li>
<li><a href="3-4-rstudio.html#object-display-and-output-table"><span class="toc-section-number">3.4.7</span> Object display and output table</a></li>
<li><a href="3-4-rstudio.html#project-management"><span class="toc-section-number">3.4.8</span> Project management</a></li>
<li><a href="3-4-rstudio.html#exercises-4"><span class="toc-section-number">3.4.9</span> Exercises</a></li>
</ul></li>
<li class="has-sub"><a href="3-5-blas-and-alternative-r-interpreters.html#blas-and-alternative-r-interpreters"><span class="toc-section-number">3.5</span> BLAS and alternative R interpreters</a><ul>
<li><a href="3-5-blas-and-alternative-r-interpreters.html#revolution-r"><span class="toc-section-number">3.5.1</span> Revolution R</a></li>
<li><a href="3-5-blas-and-alternative-r-interpreters.html#other-interpreters"><span class="toc-section-number">3.5.2</span> Other interpreters</a></li>
<li><a href="3-5-blas-and-alternative-r-interpreters.html#useful-blasbenchmarking-resources"><span class="toc-section-number">3.5.3</span> Useful BLAS/benchmarking resources</a></li>
<li><a href="3-5-blas-and-alternative-r-interpreters.html#exercises-5"><span class="toc-section-number">3.5.4</span> Exercises</a></li>
</ul></li>
</ul></li>
<li class="has-sub"><a href="4-efficient-hardware.html#efficient-hardware"><span class="toc-section-number">4</span> Efficient hardware</a><ul>
<li><a href="4-1-introduction-what-is-a-byte.html#introduction-what-is-a-byte"><span class="toc-section-number">4.1</span> Introduction: what is a byte?</a></li>
<li class="has-sub"><a href="4-2-ram.html#ram"><span class="toc-section-number">4.2</span> Random access memory: RAM</a><ul>
<li><a href="4-2-ram.html#exercises-6"><span class="toc-section-number">4.2.1</span> Exercises</a></li>
</ul></li>
<li><a href="4-3-hard-drives-hdd-vs-ssd.html#hard-drives-hdd-vs-ssd"><span class="toc-section-number">4.3</span> Hard drives: HDD vs SSD</a></li>
<li class="has-sub"><a href="4-4-operating-systems-32-bit-or-64-bit.html#operating-systems-32-bit-or-64-bit"><span class="toc-section-number">4.4</span> Operating systems: 32-bit or 64-bit</a><ul>
<li><a href="4-4-operating-systems-32-bit-or-64-bit.html#exercises-7"><span class="toc-section-number">4.4.1</span> Exercises</a></li>
</ul></li>
<li><a href="4-5-central-processing-unit-cpu.html#central-processing-unit-cpu"><span class="toc-section-number">4.5</span> Central processing unit (CPU)</a></li>
<li class="has-sub"><a href="4-6-cloud-computing.html#cloud-computing"><span class="toc-section-number">4.6</span> Cloud computing</a><ul>
<li><a href="4-6-cloud-computing.html#amazon-ec2"><span class="toc-section-number">4.6.1</span> Amazon EC2</a></li>
<li><a href="4-6-cloud-computing.html#exercise"><span class="toc-section-number">4.6.2</span> Exercise</a></li>
</ul></li>
</ul></li>
<li class="has-sub"><a href="5-efficient-workflow.html#efficient-workflow"><span class="toc-section-number">5</span> Efficient workflow</a><ul>
<li class="has-sub"><a href="5-1-project-planning.html#project-planning"><span class="toc-section-number">5.1</span> Project planning</a><ul>
<li><a href="5-1-project-planning.html#exercises-8"><span class="toc-section-number">5.1.1</span> Exercises</a></li>
</ul></li>
<li><a href="5-2-pkgs.html#pkgs"><span class="toc-section-number">5.2</span> Package selection</a></li>
<li class="has-sub"><a href="5-3-importing-data.html#importing-data"><span class="toc-section-number">5.3</span> Importing data</a><ul>
<li><a href="5-3-importing-data.html#fast-data-reading"><span class="toc-section-number">5.3.1</span> Fast data reading</a></li>
<li><a href="5-3-importing-data.html#preprocessing-outside-r"><span class="toc-section-number">5.3.2</span> Preprocessing outside R</a></li>
<li><a href="5-3-importing-data.html#working-with-databases"><span class="toc-section-number">5.3.3</span> Working with databases</a></li>
</ul></li>
<li><a href="5-4-tidying-data-with-tidyr.html#tidying-data-with-tidyr"><span class="toc-section-number">5.4</span> Tidying data with <strong>tidyr</strong></a></li>
<li class="has-sub"><a href="5-5-dplyr.html#dplyr"><span class="toc-section-number">5.5</span> Data processing</a><ul>
<li><a href="5-5-dplyr.html#renaming-columns"><span class="toc-section-number">5.5.1</span> Renaming columns</a></li>
<li><a href="5-5-dplyr.html#filtering-rows"><span class="toc-section-number">5.5.2</span> Filtering rows</a></li>
<li><a href="5-5-dplyr.html#filtering-columns"><span class="toc-section-number">5.5.3</span> Filtering columns</a></li>
<li><a href="5-5-dplyr.html#data-aggregation"><span class="toc-section-number">5.5.4</span> Data aggregation</a></li>
</ul></li>
<li class="has-sub"><a href="5-6-updating-column-classes.html#updating-column-classes"><span class="toc-section-number">5.6</span> Updating column classes</a><ul>
<li><a href="5-6-updating-column-classes.html#chaining-operations-with-dplyr"><span class="toc-section-number">5.6.1</span> Chaining operations with <strong>dplyr</strong></a></li>
<li><a href="5-6-updating-column-classes.html#data.table"><span class="toc-section-number">5.6.2</span> <strong>data.table</strong></a></li>
</ul></li>
<li><a href="5-7-publication.html#publication"><span class="toc-section-number">5.7</span> Publication</a></li>
</ul></li>
<li><a href="6-efficient-collaboration.html#efficient-collaboration"><span class="toc-section-number">6</span> Efficient collaboration</a></li>
<li class="has-sub"><a href="7-efficient-programming.html#efficient-programming"><span class="toc-section-number">7</span> Efficient programming</a><ul>
<li class="has-sub"><a href="7-1-data-types.html#data-types"><span class="toc-section-number">7.1</span> Data types</a><ul>
<li><a href="7-1-data-types.html#vectors"><span class="toc-section-number">7.1.1</span> Vectors</a></li>
<li><a href="7-1-data-types.html#factors"><span class="toc-section-number">7.1.2</span> Factors</a></li>
<li><a href="7-1-data-types.html#data-frames"><span class="toc-section-number">7.1.3</span> Data frames</a></li>
<li><a href="7-1-data-types.html#matrix"><span class="toc-section-number">7.1.4</span> Matrix</a></li>
<li><a href="7-1-data-types.html#S3"><span class="toc-section-number">7.1.5</span> S3 objects</a></li>
<li><a href="7-1-data-types.html#efficient-data-structures"><span class="toc-section-number">7.1.6</span> Efficient data structures</a></li>
</ul></li>
<li class="has-sub"><a href="7-2-good-programming-techniques.html#good-programming-techniques"><span class="toc-section-number">7.2</span> Good programming techniques</a><ul>
<li><a href="7-2-good-programming-techniques.html#general-tips"><span class="toc-section-number">7.2.1</span> General tips</a></li>
<li><a href="7-2-good-programming-techniques.html#caching-variables"><span class="toc-section-number">7.2.2</span> Caching variables</a></li>
<li><a href="7-2-good-programming-techniques.html#function-closures"><span class="toc-section-number">7.2.3</span> Function closures</a></li>
<li><a href="7-2-good-programming-techniques.html#vectorised-code"><span class="toc-section-number">7.2.4</span> Vectorised code</a></li>
</ul></li>
<li class="has-sub"><a href="7-3-parallel-computing.html#parallel-computing"><span class="toc-section-number">7.3</span> Parallel computing</a><ul>
<li><a href="7-3-parallel-computing.html#parallel-versions-of-apply-functions"><span class="toc-section-number">7.3.1</span> Parallel versions of apply functions</a></li>
<li><a href="7-3-parallel-computing.html#example-parallel-bootstraping"><span class="toc-section-number">7.3.2</span> Example: parallel bootstraping</a></li>
<li><a href="7-3-parallel-computing.html#process-forking"><span class="toc-section-number">7.3.3</span> Process forking</a></li>
</ul></li>
<li class="has-sub"><a href="7-4-the-byte-compiler.html#the-byte-compiler"><span class="toc-section-number">7.4</span> The byte compiler</a><ul>
<li><a href="7-4-the-byte-compiler.html#example-the-mean-function"><span class="toc-section-number">7.4.1</span> Example: the mean function</a></li>
<li><a href="7-4-the-byte-compiler.html#compiling-code"><span class="toc-section-number">7.4.2</span> Compiling code</a></li>
</ul></li>
</ul></li>
<li><a href="8-efficient-rcpp.html#efficient-rcpp"><span class="toc-section-number">8</span> Efficient Rcpp</a></li>
<li><a href="9-efficient-memory.html#efficient-memory"><span class="toc-section-number">9</span> Efficient Memory</a></li>
<li><a href="10-efficient-learning.html#efficient-learning"><span class="toc-section-number">10</span> Efficient Learning</a></li>
</ul>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-12">
<div id="efficient-memory" class="section level1">
<h1><span class="header-section-number">9</span> Efficient Memory</h1>
</div>
<p style="text-align: center;">
<button class="btn btn-default"><a href="8-efficient-rcpp.html">Previous</a></button>
<button class="btn btn-default"><a href="10-efficient-learning.html">Next</a></button>
</p>
</div>
</div>
</div>
<script>
// add bootstrap table styles to pandoc tables
$(document).ready(function () {
$('tr.header').parent('thead').parent('table').addClass('table table-condensed');
});
</script>
</body>
</html>