This repository was archived by the owner on Jan 6, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathwk07_package.html
549 lines (475 loc) · 23.3 KB
/
wk07_package.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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
<!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="author" content="Ben Best" />
<meta name="date" content="2016-05-20" />
<title>Quick Intro to Package Development with devtools</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/cosmo.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>
<!-- http://www.favicon-generator.org/ -->
<link rel="apple-touch-icon" sizes="57x57" href="favicons/apple-icon-57x57.png">
<link rel="apple-touch-icon" sizes="60x60" href="favicons/apple-icon-60x60.png">
<link rel="apple-touch-icon" sizes="72x72" href="favicons/apple-icon-72x72.png">
<link rel="apple-touch-icon" sizes="76x76" href="favicons/apple-icon-76x76.png">
<link rel="apple-touch-icon" sizes="114x114" href="favicons/apple-icon-114x114.png">
<link rel="apple-touch-icon" sizes="120x120" href="favicons/apple-icon-120x120.png">
<link rel="apple-touch-icon" sizes="144x144" href="favicons/apple-icon-144x144.png">
<link rel="apple-touch-icon" sizes="152x152" href="favicons/apple-icon-152x152.png">
<link rel="apple-touch-icon" sizes="180x180" href="favicons/apple-icon-180x180.png">
<link rel="icon" type="image/png" sizes="192x192" href="favicons/android-icon-192x192.png">
<link rel="icon" type="image/png" sizes="32x32" href="favicons/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="96x96" href="favicons/favicon-96x96.png">
<link rel="icon" type="image/png" sizes="16x16" href="favicons/favicon-16x16.png">
<link rel="manifest" href="favicons/manifest.json">
<meta name="msapplication-TileColor" content="#ffffff">
<meta name="msapplication-TileImage" content="../favicons/ms-icon-144x144.png">
<meta name="theme-color" content="#ffffff">
<link rel="shortcut icon" type="image/x-icon" href="favicon.ico">
<link href="libs/tocify-1.9.1/jquery.tocify.css" rel="stylesheet">
<script src="libs/tocify-1.9.1/jquery-ui-1.9.2.custom.min.js"></script>
<script src="libs/tocify-1.9.1/jquery.tocify.min.js"></script>
<link href="libs/lightbox-2.8.2/css/lightbox.min.css" rel="stylesheet">
<!--
Font Awesome: http://fortawesome.github.io/Font-Awesome/icons
Octicons: https://octicons.github.com
-->
<link rel="stylesheet" href="libs/font-awesome-4.5.0/css/font-awesome.min.css">
<link rel="stylesheet" href="libs/octicons-3.3.0/octicons.css">
<style type="text/css">
@media (max-width: 992px) {
#toc {
position: relative;
width: 100%;
margin: 0px 0px 20px 0px;
}
}
</style>
<style type="text/css">code{white-space: pre;}</style>
<link rel="stylesheet"
href="libs/highlight/textmate.css"
type="text/css" />
<script src="libs/highlight/highlight.js"></script>
<style type="text/css">
pre:not([class]) {
background-color: white;
}
</style>
<script type="text/javascript">
if (window.hljs && document.readyState && document.readyState === "complete") {
window.setTimeout(function() {
hljs.initHighlighting();
}, 0);
}
</script>
<style type="text/css">
h1 {
font-size: 34px;
}
h1.title {
font-size: 38px;
}
h2 {
font-size: 30px;
}
h3 {
font-size: 24px;
}
h4 {
font-size: 18px;
}
h5 {
font-size: 16px;
}
h6 {
font-size: 12px;
}
.table th:not([align]) {
text-align: left;
}
</style>
<link rel="stylesheet" href="libs/font-awesome-4.5.0/css/font-awesome.min.css" type="text/css" />
<link rel="stylesheet" href="libs/octicons-3.3.0/octicons.css" type="text/css" />
<link rel="stylesheet" href="styles/styles.css" type="text/css" />
</head>
<body>
<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;
}
.tabbed-pane {
padding-top: 12px;
}
button.code-folding-btn:focus {
outline: none;
}
</style>
<div class="container-fluid main-container">
<!-- tabsets -->
<script src="libs/navigation-1.0/tabsets.js"></script>
<script>
$(document).ready(function () {
window.buildTabsets("TOC");
});
</script>
<!-- code folding -->
<!--- https://codepo8.github.io/css-fork-on-github-ribbon/
<style>#forkongithub a{background:#000;color:#fff;text-decoration:none;font-family:arial,sans-serif;text-align:center;font-weight:bold;padding:5px 40px;font-size:1rem;line-height:2rem;position:relative;transition:0.5s;}#forkongithub a:hover{background:#c11;color:#fff;}#forkongithub a::before,#forkongithub a::after{content:"";width:100%;display:block;position:absolute;top:1px;left:0;height:1px;background:#fff;}#forkongithub a::after{bottom:1px;top:auto;}@media screen and (min-width:800px){#forkongithub{position:fixed;display:block;top:0;left:0;width:200px;overflow:hidden;height:200px;z-index:9999;}#forkongithub a{width:200px;position:absolute;top:60px;left:-60px;transform:rotate(-45deg);-webkit-transform:rotate(-45deg);-ms-transform:rotate(-45deg);-moz-transform:rotate(-45deg);-o-transform:rotate(-45deg);box-shadow:4px 4px 10px rgba(0,0,0,0.8);}}</style><span id="forkongithub"><a href="https://github.com/ucsb-bren/env-info">Fork me on GitHub</a></span>
-->
<div class="row-fluid">
<div class="navbar navbar-default navbar-fixed-top navbar-transparent">
<div class="container">
<div class="navbar-header">
<a href="http://ucsb-bren.github.io/env-info/" class="navbar-brand"><i class="fa fa-home"></i> env-info</a>
<button class="navbar-toggle" type="button" data-toggle="collapse" data-target="#navbar-main">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<div class="navbar-collapse collapse" id="navbar-main">
<!--
<ul class="nav navbar-nav">
<li>
<a href="/#schedule"><i class="fa fa-calendar"></i> schedule</a>
</li>
</ul>
-->
<ul class="nav navbar-nav navbar-right">
<li><a href="/students"><i class="fa fa-users"></i> students</a></li>
</ul>
</div>
</div>
</div>
</div>
<div class="row-fluid">
<div class="span3 col-md-3">
<div id="toc"></div>
</div>
<div class="main-content span9 col-md-9">
<div class="fluid-row" id="header">
<h1 class="title toc-ignore">Quick Intro to Package Development with <code>devtools</code></h1>
<h4 class="author"><em>Ben Best</em></h4>
<h4 class="date"><em>2016-05-20</em></h4>
</div>
<div id="overview" class="section level2">
<h2>Overview</h2>
<p>Packages are the preferred way to bundle up functions, so others can easily use them. You use packages all the time, such as every time you load them with the <code>library()</code> function.</p>
<p>The following quick introduction is based on distilling the most minimal example from the following:</p>
<ul>
<li><a href="http://r-pkgs.had.co.nz/">book: R packages</a></li>
<li><a href="./refs/cheatsheets/devtools-cheatsheet.pdf">cheat sheet: Package Development with <code>devtools</code></a></li>
</ul>
<p>The R code below walks you through creation of an R package called <code>mypackage</code> having the following top level file and folder (<code>*/</code>) structure:</p>
<pre><code>mypackage
├── DESCRIPTION
├── NAMESPACE
├── data/
├── man/
├── R/
├── tests/
└── vignettes/</code></pre>
<p>These files and folders correspond to the following characteristic offerings of an R package:</p>
<ul>
<li><strong>functions</strong> in <code>R/</code> scripts. Functions are written here with input arguments and return objects.</li>
<li><strong>documentation</strong> in <code>man/</code>. Documentation is automatically generated from the <code>roxygen2</code> comments in the R scripts. Help is then available from the console via <code>?add</code> (eg for <code>add()</code> function).</li>
<li><strong>data</strong> in <code>data/</code>. Data can then be loaded via <code>data(x)</code> (eg for <code>x</code> data).</li>
<li><strong>tests</strong> in <code>tests/</code>. Tests ensure checking for consistent behavior as your functions grow.</li>
<li><strong>vignettes</strong> in <code>vignettes/</code>. Vignettes are a long form of documentation that allow you to walk the user through a larger amount of analysis, especially useful for showing relatedness between functions. Since they are rendered from Rmarkdown to HTML, you can show plots, tables and more richly formatted documentation.</li>
<li><strong>sharing</strong> via <code>install_github()</code>. By pushing your code to Github, you can then share a single line of code using the <code>devtools::install_github()</code> function so others can install and use your function immediately.</li>
</ul>
</div>
<div id="create-repo" class="section level2">
<h2>Create repo</h2>
<p>Start by <a href="https://help.github.com/articles/create-a-repo/">creating a repository</a> in Github. For this tutorial, I recommend:</p>
<ul>
<li>Owner: <strong><user></strong> (for me: bbest), Repository: <strong>mypackage</strong></li>
<li>Description: <strong>R package to do some basic math</strong></li>
<li>YES, <strong>Initialize this repository with a README</strong></li>
</ul>
<p>Now git clone this repository to your machine from within RStudio’s menu File > New Project > Version Control > Git:</p>
<ul>
<li>Repository URL: <strong><a href="https://github.com/" class="uri">https://github.com/</a><user>/mypackage.git</strong> (for me: <a href="https://github.com/bbest/mypackage.git" class="uri">https://github.com/bbest/mypackage.git</a>)</li>
<li>Project directory name: <strong>mypackage</strong></li>
<li>Create project as subdirectory of: <strong>~/github</strong> (or wherever you like)</li>
</ul>
</div>
<div id="load-devtools" class="section level2">
<h2>Load devtools</h2>
<p>The <a href="https://github.com/hadley/devtools"><code>devtools</code></a> package makes R packages easy. All the functions below are from this library. Thank you <a href="https://github.com/hadley">@hadley</a>!</p>
<pre class="r"><code># load devtools package
if (!require('devtools')) install.packages('devtools')
library(devtools)</code></pre>
</div>
<div id="setup-the-package" class="section level2">
<h2>Setup the package</h2>
<p>Setup the existing folder to be a package. (Alternatively you can use <code>devtools::create()</code> to create from scratch.)</p>
<pre class="r"><code>setup()</code></pre>
<p>Notice how this function creates the <code>DESCRIPTION</code> and <code>NAMESPACE</code> files, and <code>R</code> folder.</p>
<pre><code>Creating package 'mypackage' in '/Users/bbest/github/mypackage'
No DESCRIPTION found. Creating with values:
Package: mypackage
Title: What the Package Does (one line, title case)
Version: 0.0.0.9000
Authors@R: person("First", "Last", email = "first.last@example.com", role = c("aut", "cre"))
Description: What the package does (one paragraph).
Depends: R (>= 3.2.3)
License: What license is it under?
LazyData: true</code></pre>
<p>Notice how if you re-open RStudio to <code>mypackage.Rproj</code> an extra <strong>Build</strong> tab appears, per the <a href=".refs/cheatsheets/rstudio-IDE-cheatsheet.pdf">rstudio-IDE-cheatsheet</a>:</p>
<div class="figure">
<img src="wk07_program2/img/rstudio-IDE-cheatsheet_package-writing.png" />
</div>
<p>See more:</p>
<ul>
<li><a href="../refs/cheatsheets/devtools-cheatsheet.pdf">devtools-cheatsheet</a>: Package Structure, Setup, Write code in R/</li>
<li><a href="http://r-pkgs.had.co.nz/package.html">Package structure · R packages</a></li>
</ul>
</div>
<div id="functions-in-r" class="section level2">
<h2>Functions in R/</h2>
<p>Now create an R file with a custom <code>add()</code> function, load the package with <code>devtools::load_all()</code> and try out the function.</p>
<pre class="r"><code>library(devtools)
# write add function to add.R file in R/ folder
cat("add <- function(x, y){ x+ y }", file='R/add.R')
# load the library from source
load_all()
# try function
add(1,2)</code></pre>
<p>Note the function <strong><code>cat()</code></strong> which “concatenates”, or joins together, R objects and prints. This is a programmer’s way of creating a file with content. Normally you would just create this new file in the RStudio editor.</p>
</div>
<div id="document-to-man" class="section level2">
<h2>Document to man/</h2>
<p>Add documentation to the custom <code>add()</code> function using <a href="https://cran.r-project.org/web/packages/roxygen2/vignettes/roxygen2.html">roxygen2</a> style, generate documentation with <code>devtools::document()</code>, reload the package, and try out the help documentation.</p>
<pre class="r"><code># write add function with documentation
cat(
"#' Add together two numbers.
#'
#' @param x A number.
#' @param y A number.
#' @return The sum of \\code{x} and \\code{y}.
#' @examples
#' add(1, 1)
#' @export
add <- function(x, y){
x+ y
}", file='R/add.R')
# update R documentation (*.Rd) in manual folder man/
document()
# load the library from source
load_all()
# try function
add(1,2)
# check documentation
?add</code></pre>
<p>Notice how <code>document()</code> creates the <a href="https://github.com/bbest/bbest.github.io/blob/master/mypackage/R/add.R"><code>man/add.Rd</code></a> for the <code>add()</code> function (and would other <code>man/*.Rd</code> files for more functions) and updates <code>DESCRIPTION</code> and <code>NAMESPACE</code> files.</p>
<pre><code>Updating roxygen version in ~/bbest.github.io/mypackage/DESCRIPTION
Writing NAMESPACE
Writing add.Rd</code></pre>
<p>See more:</p>
<ul>
<li><a href="../refs/cheatsheets/devtools-cheatsheet.pdf">devtools-cheatsheet</a>: Write code in R/, Document in man/, Organize in NAMESPACE, Setup in DESCRIPTION</li>
<li><a href="http://r-pkgs.had.co.nz/r.html">R code · R packages</a></li>
<li><a href="http://r-pkgs.had.co.nz/description.html">Package basics · R packages</a></li>
<li><a href="http://r-pkgs.had.co.nz/man.html">Object documentation · R packages</a></li>
</ul>
</div>
<div id="add-data-to-data" class="section level2">
<h2>Add data to data/</h2>
<p>Add custom data with <code>devtools::use_data()</code>, and load the data with base function <code>data()</code>.</p>
<pre class="r"><code># create data
x = 1:10
y = 1:100
# store in data/*.rda
use_data(x, y)
# use data in example
load_all()
data(x,y)
add(x,y)</code></pre>
<p>Notice how <code>use_data()</code> creates the <code>data/*.rda</code> files.</p>
<pre><code>Saving x, y as x.rda, y.rda to ~/bbest.github.io/mypackage/data</code></pre>
<p>See more:</p>
<ul>
<li><a href="../refs/cheatsheets/devtools-cheatsheet.pdf">devtools-cheatsheet</a>: Add data in data/</li>
<li><a href="http://r-pkgs.had.co.nz/data.html">Data · R packages</a></li>
</ul>
</div>
<div id="test-in-tests" class="section level2">
<h2>Test in tests/</h2>
<p>Create test infrastructure with <code>devtools::use_testthat()</code>, create some tests in <code>test_add.R</code>, and run tests with <code>devtools::test()</code>.</p>
<pre class="r"><code># setup for tests (one time only)
use_testthat()
# write test for add function
cat(
"context('add')
test_that('add works', {
expect_equal(add(1,1), 2)
expect_equal(add(1,2), 3)
expect_equal(add(1,100), 101)
})
", file = 'tests/testthat/test_add.R')
# run tests
test()</code></pre>
<p>The <code>use_testthat()</code> creates the <code>test/testthat</code> folder and <code>tests/testthat.R</code> main script. Adding <a href="https://github.com/bbest/bbest.github.io/blob/master/mypackage/tests/testthat/test_add.R"><code>tests/testthat/test_add.R</code></a> adds 3 tests, each of which get executed when running <code>test()</code> which reports success with a single <code>.</code> and finishes with <code>DONE</code>.</p>
<pre><code>Loading mypackage
Loading required package: testthat
Testing mypackage
add : ...
DONE </code></pre>
<p>See more:</p>
<ul>
<li><a href="../refs/cheatsheets/devtools-cheatsheet.pdf">devtools-cheatsheet</a>: Test in tests/</li>
<li><a href="http://r-pkgs.had.co.nz/tests.html">Testing · R packages</a></li>
</ul>
</div>
<div id="check-with-travis" class="section level2">
<h2>Check with Travis</h2>
<p>Once you have tests built, wouldn’t it be nice to automatically run the tests every time a new commit is made to Github? This is called “continuous integration” in developer circles, and the idea is to continuously integrate tests with changes in code to ensure all is happy as you develop. If any of the tests fail, you get emailed and can fix the problem sooner than later. There’s a great free service by <a href="https://travis-ci.org">Travis CI</a> that can be setup to run any tests on any Github repository at every new commit that gets pushed or merged.</p>
<p>Before you run the next command to add the Travis CI infrastructure, I recommend running a git commit and push.</p>
<pre class="r"><code>use_travis()</code></pre>
<p>This creates the special file <code>.travis.yml</code> containing the test instructions.</p>
<pre><code>Adding .travis.yml to mypackage. Next:
* Turn on travis for this repo at https://travis-ci.org/profile
* Add a travis shield to your README.md:
[](https://travis-ci.org/bbest/mypackage)</code></pre>
<p>Per the instructions, visit <a href="https://travis-ci.org/profile" class="uri">https://travis-ci.org/profile</a> to create a profile to link to your Github account and turn on Travis with a little slider to your <code>mypackage</code>.</p>
<p>Let’s add the “travis shield” line above to the README.md (replace with your Github <code><user></code>, not <code>bbest</code>). Note the <code>append=T</code> argument.</p>
<pre class="r"><code>cat('
[](https://travis-ci.org/bbest/mypackage)
', file='README.md', append=T)</code></pre>
<p>Do another git commit and push. Now visit <a href="https://travis-ci.org/USER/mypackage">travis-ci.org/USER/mypackage</a> (for me <a href="https://travis-ci.org/bbest/mypackage">travis-ci.org/bbest/mypackage</a>). I can see that based on the Build History, I get the following “build failing” based on 2 warnings converted to errors:</p>
<pre><code>Checking package
checking DESCRIPTION meta-information ... WARNING
Non-standard license specification:
What license is it under?
Standardizable: FALSE checking for missing documentation entries ... WARNING
Undocumented code objects:
‘x’ ‘y’
Undocumented data sets:
‘x’ ‘y’
All user-level objects in a package should have documentation entries.
See chapter ‘Writing R documentation files’ in the ‘Writing R
Extensions’ manual. DONE
Status: 2 WARNINGs
R CMD check logs
Found warnings, treating as errors (as requested).</code></pre>
<p>You can also see this “build failing” status at <a href="https://github.com/USER/mypackage">github.com/USER/mypackage</a> (for me <a href="https://github.com/bbest/mypackage">github.com/bbest/mypackage</a>) which shows the README.md at the bottom with the “travis shield”:</p>
<img src="wk07_program2/img/travis-ci_build-failing.png" width="100"/>
<p>Let’s fix these warnings to get the build to pass:</p>
<ul>
<li>use permissive MIT license. See <a href="https://github.com/blog/1530-choosing-an-open-source-license">Choosing an Open Source License</a>.</li>
<li>add <a href="http://r-pkgs.had.co.nz/data.html#documenting-data">documentation to the data</a></li>
</ul>
<pre class="r"><code># fix license
use_mit_license()
# add data documentation
cat("
#' 1 thru 10
#'
#' A simple dataset
'x'
#' 1 thru 100
#'
#' Another simple dataset
#'
'y'
", file = 'R/data.R')
document()</code></pre>
<p>Now git commit and push again, to see if that fixes your build to build passing:</p>
<img src="wk07_program2/img/travis-ci_build-passing.png" width="100"/>
<p>See more:</p>
<ul>
<li><a href="http://r-pkgs.had.co.nz/check.html#travis">Checking a package · R packages</a></li>
</ul>
</div>
<div id="teach-with-vignettes" class="section level2">
<h2>Teach with vignettes/</h2>
<p>Finally, you can teach with vignettes, which are a longer form than just a single function or data help. Better yet, you can write them as an Rmarkdown file so they can render tables, images, etc.</p>
<pre class="r"><code># create a draft vignette
use_vignette('math')
# build vignettes, install locally
tgz = build()
install_local(tgz)
# try vignette
library(mypackage)
vignette('math')</code></pre>
<p>Notice how <code>use_vignette('math')</code> creates <code>vignettes/math.Rmd</code>, an Rmarkdown file which you can freely edit. The default draft with title “Vignette Title” by “Vignette Author” should be customized, but offers some helpful tips on how to craft a vignette. See this example as rendered <a href="http://bbest.github.io/mypackage/vignettes/math.html">math.html</a>.</p>
<p>See more:</p>
<ul>
<li><a href="../refs/cheatsheets/devtools-cheatsheet.pdf">devtools-cheatsheet</a>: Teach in vignettes/</li>
<li><a href="http://r-pkgs.had.co.nz/vignettes.html">Vignettes · R packages</a></li>
</ul>
</div>
<div id="share-via-github_install" class="section level2">
<h2>Share via <code>github_install()</code></h2>
<p>Now that you’ve created a complete R package, it’s time to run a git <strong>Commit</strong>, and <strong>Push</strong> to your Github repository. Then you can share a single command for anyone else to install the R package. For my R package, files at <a href="https://github.com/bbest/mypackage">github.com/bbest/mypackage</a>, it would be:</p>
<pre class="r"><code>devtools::install_github('bbest/mypackage', build_vignettes=T)</code></pre>
<p>Notice how the first argument is of the form <code><owner>/<repository></code>.</p>
</div>
</div> <!--span-9-->
</div> <!--row-fluid-->
<!--
<script src="{{ site.baseurl }}/libs/lightbox-2.8.2/js/lightbox.min.js"></script>
<script>
lightbox.option({
'albumLabel': 'Example %1 of %2',
'resizeDuration': 200,
'fadeDuration': 200,
'wrapAround': true
})
</script>
-->
<style type="text/css">
.main-container {
max-width: none;
}
</style>
<script>
$(function() {
var toc = $("#toc").tocify({
selectors: "h2,h3",
theme: "bootstrap3",
context: '.main-content',
hashGenerator: 'pretty',
showAndHide: false
}).data("toc-tocify");
$(".optionName").popover({ trigger: "hover" });
});
</script>
<div style="color:gray; text-align: right;" >
<span class="octicon octicon-repo-forked"></span> <b>Fork</b> me at <a href="http://github.com/ucsb-bren/env-info">github.com/<b>ucsb-bren/env-info</b></a>
</div>
</div>
<script>
// add bootstrap table styles to pandoc tables
$(document).ready(function () {
$('tr.header').parent('thead').parent('table').addClass('table table-condensed');
});
</script>
<!-- dynamically load mathjax for compatibility with self-contained -->
<script>
(function () {
var script = document.createElement("script");
script.type = "text/javascript";
script.src = "https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML";
document.getElementsByTagName("head")[0].appendChild(script);
})();
</script>
</body>
</html>