-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrdev.html
More file actions
262 lines (234 loc) · 18.4 KB
/
rdev.html
File metadata and controls
262 lines (234 loc) · 18.4 KB
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
<!DOCTYPE html>
<!-- Generated by pkgdown: do not edit by hand --><html lang="en-US">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Introduction to rdev • rdev</title>
<!-- favicons --><link rel="icon" type="image/png" sizes="96x96" href="../favicon-96x96.png">
<link rel="icon" type="”image/svg+xml”" href="../favicon.svg">
<link rel="apple-touch-icon" sizes="180x180" href="../apple-touch-icon.png">
<link rel="icon" sizes="any" href="../favicon.ico">
<link rel="manifest" href="../site.webmanifest">
<script src="../lightswitch.js"></script><script src="../deps/jquery-3.6.0/jquery-3.6.0.min.js"></script><meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link href="../deps/bootstrap-5.3.1/bootstrap.min.css" rel="stylesheet">
<script src="../deps/bootstrap-5.3.1/bootstrap.bundle.min.js"></script><link href="../deps/font-awesome-6.5.2/css/all.min.css" rel="stylesheet">
<link href="../deps/font-awesome-6.5.2/css/v4-shims.min.css" rel="stylesheet">
<script src="../deps/headroom-0.11.0/headroom.min.js"></script><script src="../deps/headroom-0.11.0/jQuery.headroom.min.js"></script><script src="../deps/bootstrap-toc-1.0.1/bootstrap-toc.min.js"></script><script src="../deps/clipboard.js-2.0.11/clipboard.min.js"></script><script src="../deps/search-1.0.0/autocomplete.jquery.min.js"></script><script src="../deps/search-1.0.0/fuse.min.js"></script><script src="../deps/search-1.0.0/mark.min.js"></script><!-- pkgdown --><script src="../pkgdown.js"></script><link href="../extra.css" rel="stylesheet">
<meta property="og:title" content="Introduction to rdev">
</head>
<body>
<a href="#main" class="visually-hidden-focusable">Skip to contents</a>
<nav class="navbar navbar-expand-lg fixed-top " aria-label="Site navigation"><div class="container">
<a class="navbar-brand me-2" href="../index.html">rdev</a>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">1.15.3</small>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbar" aria-controls="navbar" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div id="navbar" class="collapse navbar-collapse ms-3">
<ul class="navbar-nav me-auto">
<li class="active nav-item"><a class="nav-link" href="../articles/rdev.html">Get started</a></li>
<li class="nav-item"><a class="nav-link" href="../reference/index.html">Reference</a></li>
<li class="nav-item dropdown">
<button class="nav-link dropdown-toggle" type="button" id="dropdown-articles" data-bs-toggle="dropdown" aria-expanded="false" aria-haspopup="true">Articles</button>
<ul class="dropdown-menu" aria-labelledby="dropdown-articles">
<li><a class="dropdown-item" href="../articles/analysis-package-layout.html">Analysis Package Layout</a></li>
<li><a class="dropdown-item" href="../articles/style-guide.html">Style Guide</a></li>
</ul>
</li>
<li class="nav-item"><a class="nav-link" href="../news/index.html">Changelog</a></li>
</ul>
<ul class="navbar-nav">
<li class="nav-item"><form class="form-inline" role="search">
<input class="form-control" type="search" name="search-input" id="search-input" autocomplete="off" aria-label="Search site" placeholder="Search for" data-search-index="../search.json">
</form></li>
<li class="nav-item"><a class="external-link nav-link" href="https://github.com/jabenninghoff/rdev/" aria-label="GitHub"><span class="fa fab fa-github fa-lg"></span></a></li>
<li class="nav-item dropdown">
<button class="nav-link dropdown-toggle" type="button" id="dropdown-lightswitch" data-bs-toggle="dropdown" aria-expanded="false" aria-haspopup="true" aria-label="Light switch"><span class="fa fa-sun"></span></button>
<ul class="dropdown-menu dropdown-menu-end" aria-labelledby="dropdown-lightswitch">
<li><button class="dropdown-item" data-bs-theme-value="light"><span class="fa fa-sun"></span> Light</button></li>
<li><button class="dropdown-item" data-bs-theme-value="dark"><span class="fa fa-moon"></span> Dark</button></li>
<li><button class="dropdown-item" data-bs-theme-value="auto"><span class="fa fa-adjust"></span> Auto</button></li>
</ul>
</li>
</ul>
</div>
</div>
</nav><div class="container template-article">
<div class="row">
<main id="main" class="col-md-9"><div class="page-header">
<img src="../logo.png" class="logo" alt=""><h1>Introduction to rdev</h1>
<small class="dont-index">Source: <a href="https://github.com/jabenninghoff/rdev/blob/HEAD/vignettes/rdev.Rmd" class="external-link"><code>vignettes/rdev.Rmd</code></a></small>
<div class="d-none name"><code>rdev.Rmd</code></div>
</div>
<div class="section level2">
<h2 id="overview">Overview<a class="anchor" aria-label="anchor" href="#overview"></a>
</h2>
<p>rdev supports my personal workflow, including creation of both
traditional R packages and R Analysis Packages
(<code><a href="../articles/analysis-package-layout.html">vignette("analysis-package-layout")</a></code>), enforcing
consistency across packages, and providing Continuous
Integration/Continuous Delivery (CI/CD) automation. I use the tools in
rdev to improve code quality, speed up development of R code, and
publish results of analyses in R and Quarto Notebooks as HTML to make
them accessible to non-R users.</p>
</div>
<div class="section level2">
<h2 id="installation">Installation<a class="anchor" aria-label="anchor" href="#installation"></a>
</h2>
<p>My current R development environment uses <a href="https://brew.sh" class="external-link">Homebrew</a>, <a href="https://github.com/r-lib/rig/" class="external-link">rig</a>, <a href="https://posit.co/download/rstudio-desktop/" class="external-link">RStudio</a>, <a href="https://github.com" class="external-link">GitHub</a>, a collection of R packages
including rdev, <a href="https://code.visualstudio.com" class="external-link">Visual Studio
Code</a>, and <a href="https://www.vim.org" class="external-link">Vim</a>.</p>
<div class="section level3">
<h3 id="homebrew">Homebrew<a class="anchor" aria-label="anchor" href="#homebrew"></a>
</h3>
<p>I use <a href="https://github.com/Homebrew/homebrew-bundle" class="external-link">Homebrew
Bundle</a> to install all software on my systems; my basic macOS working
environment is published on GitHub in <a href="https://github.com/jabenninghoff/macos-env/tree/master" class="external-link">macos-env</a>.</p>
</div>
<div class="section level3">
<h3 id="installing-r">Installing R<a class="anchor" aria-label="anchor" href="#installing-r"></a>
</h3>
<p>rig supports installation of multiple versions of official R
binaries, which I use for reproducibility. To install R using rig, first
install rig:</p>
<div class="sourceCode" id="cb1"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb1-1"><a href="#cb1-1" tabindex="-1"></a><span class="ex">brew</span> tap r-lib/rig</span>
<span id="cb1-2"><a href="#cb1-2" tabindex="-1"></a><span class="ex">brew</span> install <span class="at">--cask</span> rig</span></code></pre></div>
<p>Then install desired versions of R. The following installs R 3.6
through 4.5 on ARM based macs (as of 2025-10-08):</p>
<div class="sourceCode" id="cb2"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb2-1"><a href="#cb2-1" tabindex="-1"></a><span class="ex">rig</span> install oldrel/6 <span class="at">--without-pak</span> <span class="at">--arch</span> x86_64</span>
<span id="cb2-2"><a href="#cb2-2" tabindex="-1"></a><span class="ex">rig</span> install oldrel/5 <span class="at">--without-pak</span> <span class="at">--arch</span> x86_64</span>
<span id="cb2-3"><a href="#cb2-3" tabindex="-1"></a><span class="ex">rig</span> install oldrel/4 <span class="at">--without-pak</span></span>
<span id="cb2-4"><a href="#cb2-4" tabindex="-1"></a><span class="ex">rig</span> install oldrel/3 <span class="at">--without-pak</span></span>
<span id="cb2-5"><a href="#cb2-5" tabindex="-1"></a><span class="ex">rig</span> install oldrel/2 <span class="at">--without-pak</span></span>
<span id="cb2-6"><a href="#cb2-6" tabindex="-1"></a><span class="ex">rig</span> install oldrel/1 <span class="at">--without-pak</span></span>
<span id="cb2-7"><a href="#cb2-7" tabindex="-1"></a><span class="ex">rig</span> install oldrel <span class="at">--without-pak</span></span>
<span id="cb2-8"><a href="#cb2-8" tabindex="-1"></a><span class="ex">rig</span> install release <span class="at">--without-pak</span></span>
<span id="cb2-9"><a href="#cb2-9" tabindex="-1"></a><span class="ex">rig</span> default release</span></code></pre></div>
<p>Note that:</p>
<ol style="list-style-type: decimal">
<li>I don’t use <a href="https://pak.r-lib.org" class="external-link">pak</a>, which rig
installs by default, as it is not yet fully <a href="https://github.com/rstudio/renv/issues/1210" class="external-link">supported</a> by
renv.</li>
<li>The oldest version of R I install is 3.6, since RStudio now requires
R 3.6 or newer (as of version <a href="https://docs.posit.co/ide/news/#rstudio-2024.04.0" class="external-link">2024.04.00</a>)</li>
<li>Since there was no ARM binary release for R 3.6
(<code>oldrel/6</code>) or R 4.0 (<code>oldrel/5</code>), I install the
Intel binaries and run them with <a href="https://support.apple.com/en-us/102527" class="external-link">Rosetta 2</a>.</li>
</ol>
</div>
<div class="section level3">
<h3 id="development-tools">Development Tools<a class="anchor" aria-label="anchor" href="#development-tools"></a>
</h3>
<p>Well, obviously, I use <a href="https://posit.co/download/rstudio-desktop/" class="external-link">RStudio</a>. RStudio
is the leading IDE for R development and integrates with many R
packages, although it sometimes falls short; I use GitHub and the
command line for Git, and occasionally Visual Studio Code (which has
better support for markdown) and Vim (which is faster for some types of
edits).</p>
<p>Posit is developing a next-generation R and Python IDE based on
Visual Studio Code, <a href="https://github.com/posit-dev/positron" class="external-link">Positron</a>. While I’ve
tried using Positron, I’ve found that it has too many <a href="https://positron.posit.co/migrate-rstudio-compare.html" class="external-link">missing
features</a> to replace RStudio for my development, including:</p>
<ul>
<li>Lack of a notebook-style interface for RMarkdown or Quarto
documents</li>
<li>No support for lintr</li>
<li>No command History or package Build panes</li>
</ul>
<p>Of these, the first two are showstoppers and the missing panes are
nearly so.</p>
<p>RStudio, the GitHub desktop client, and Visual Studio Code are easily
installed using Homebrew:</p>
<div class="sourceCode" id="cb3"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb3-1"><a href="#cb3-1" tabindex="-1"></a><span class="ex">brew</span> install <span class="at">--cask</span> rstudio</span>
<span id="cb3-2"><a href="#cb3-2" tabindex="-1"></a><span class="ex">brew</span> install <span class="at">--cask</span> github</span>
<span id="cb3-3"><a href="#cb3-3" tabindex="-1"></a><span class="ex">brew</span> install <span class="at">--cask</span> visual-studio-code</span></code></pre></div>
<p>It is recommended to change the default settings for
<code>.RData</code> in RStudio (in Options > General > Basic >
Workspace):</p>
<ul>
<li>Uncheck “Restore .Data into workspace at startup”</li>
<li>Set “Save workspace to .Data on exit” to “Never”</li>
</ul>
<p>Vim is installed by default on macOS and most Unix-like systems.</p>
</div>
<div class="section level3">
<h3 id="packages">Packages<a class="anchor" aria-label="anchor" href="#packages"></a>
</h3>
<p>Managing packages and environments are a challenge for most modern
languages. Thankfully R doesn’t have the same level of challenge as
python, or even ruby, managing packages available within a project is a
best practice. I use <a href="https://github.com/rstudio/renv" class="external-link">renv</a>
for this purpose, and use renv to install and manage all packages in all
of my projects.</p>
<p>The <code>setup-r</code> script from rdev installs a base set of
packages needed to run rdev in the R User Library. A streamlined version
of that script is included below.</p>
<div class="sourceCode" id="cb4"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb4-1"><a href="#cb4-1" tabindex="-1"></a><span class="co"># fix rig permissions</span></span>
<span id="cb4-2"><a href="#cb4-2" tabindex="-1"></a><span class="fu">sudo</span> chown <span class="at">-R</span> <span class="st">"</span><span class="va">$(</span><span class="fu">whoami</span><span class="va">)</span><span class="st">"</span>:admin /Library/Frameworks/R.framework/Versions/<span class="pp">*</span>/Resources/library</span>
<span id="cb4-3"><a href="#cb4-3" tabindex="-1"></a></span>
<span id="cb4-4"><a href="#cb4-4" tabindex="-1"></a><span class="va">RVERSION</span><span class="op">=</span><span class="st">"</span><span class="va">$(</span><span class="ex">Rscript</span> <span class="at">-e</span> <span class="st">'cat(as.character(getRversion()[1,1:2]))'</span><span class="va">)</span><span class="st">"</span></span>
<span id="cb4-5"><a href="#cb4-5" tabindex="-1"></a><span class="va">USERLIB</span><span class="op">=</span><span class="st">"</span><span class="va">$HOME</span><span class="st">/Library/R/</span><span class="va">$(</span><span class="fu">uname</span> <span class="at">-m</span><span class="va">)</span><span class="st">/</span><span class="va">${RVERSION}</span><span class="st">/library"</span></span>
<span id="cb4-6"><a href="#cb4-6" tabindex="-1"></a><span class="va">DEVPKG</span><span class="op">=</span><span class="st">'c("renv", "styler", "lintr", "miniUI", "languageserver", "rmarkdown", "devtools", "available")'</span></span>
<span id="cb4-7"><a href="#cb4-7" tabindex="-1"></a><span class="va">GITPKG</span><span class="op">=</span><span class="st">'c("jabenninghoff/rdev")'</span></span>
<span id="cb4-8"><a href="#cb4-8" tabindex="-1"></a></span>
<span id="cb4-9"><a href="#cb4-9" tabindex="-1"></a><span class="cf">if</span> <span class="bu">[</span> <span class="ot">!</span> <span class="ot">-d</span> <span class="st">"</span><span class="va">${USERLIB}</span><span class="st">"</span> <span class="bu">]</span></span>
<span id="cb4-10"><a href="#cb4-10" tabindex="-1"></a><span class="cf">then</span></span>
<span id="cb4-11"><a href="#cb4-11" tabindex="-1"></a> <span class="fu">mkdir</span> <span class="at">-p</span> <span class="st">"</span><span class="va">${USERLIB}</span><span class="st">"</span></span>
<span id="cb4-12"><a href="#cb4-12" tabindex="-1"></a><span class="cf">fi</span></span>
<span id="cb4-13"><a href="#cb4-13" tabindex="-1"></a></span>
<span id="cb4-14"><a href="#cb4-14" tabindex="-1"></a><span class="bu">echo</span> <span class="st">"install.packages(</span><span class="va">${DEVPKG}</span><span class="st">, repos=</span><span class="dt">\"</span><span class="st">https://cloud.r-project.org</span><span class="dt">\"</span><span class="st">, lib=</span><span class="dt">\"</span><span class="va">${USERLIB}</span><span class="dt">\"</span><span class="st">)"</span> <span class="kw">|</span> <span class="ex">R</span> <span class="at">--no-save</span></span>
<span id="cb4-15"><a href="#cb4-15" tabindex="-1"></a><span class="bu">echo</span> <span class="st">"remotes::install_github(</span><span class="va">${GITPKG}</span><span class="st">, lib=</span><span class="dt">\"</span><span class="va">${USERLIB}</span><span class="dt">\"</span><span class="st">)"</span> <span class="kw">|</span> <span class="ex">R</span> <span class="at">--no-save</span></span></code></pre></div>
<p>The <code>chown</code> command is needed to allow updating the base
packages using the RStudio Packages “Update” function. I generally
update packages in RStudio with no projects open before starting
development, then update packages in projects using
<code><a href="https://rstudio.github.io/renv/reference/update.html" class="external-link">renv::update()</a></code>.</p>
<p>If you’re installing (development) versions of packages from GitHub,
it is <a href="https://usethis.r-lib.org/articles/git-credentials.html" class="external-link">recommended</a>
to set up a personal access token using
<code><a href="https://usethis.r-lib.org/reference/github-token.html" class="external-link">usethis::create_github_token()</a></code> and adding it to your Git
credential store using <code><a href="https://gitcreds.r-lib.org/reference/gitcreds_get.html" class="external-link">gitcreds::gitcreds_set()</a></code>. You can
verify GitHub is set up following usethis recommendations with
<code><a href="https://usethis.r-lib.org/reference/git_sitrep.html" class="external-link">usethis::git_sitrep()</a></code>.</p>
</div>
<div class="section level3">
<h3 id="further-reading">Further Reading<a class="anchor" aria-label="anchor" href="#further-reading"></a>
</h3>
<p>My workflow has been heavily influenced by the DevOps movement and
the research of the <a href="https://www.devops-research.com/research.html" class="external-link">DevOps Research and
Assessment (DORA)</a> team at Google started by Dr. Nicole Forsgren.
Their <a href="https://dora.dev/research/" class="external-link">research</a> shows how
technical and non-technical <a href="https://dora.dev/devops-capabilities/" class="external-link">capabilities</a> improve
outcomes.</p>
<p>The functions included in rdev support many of the technical
capabilities, including:</p>
<ul>
<li>Code maintainability</li>
<li>Continuous delivery</li>
<li>Continuous integration</li>
<li>Deployment automation</li>
<li>Shifting left on security</li>
<li>Test automation</li>
<li>Trunk-based development</li>
<li>Version control</li>
</ul>
<p>An outline of my <a href="https://web.archive.org/web/20221205210229/https://societyinforisk.org/SiRAcon" class="external-link">SIRAcon
2022</a> talk, “Making R Work for You (With Automation)” is available on
GitHub in <a href="https://jabenninghoff.github.io/siracon2022/" class="external-link">siracon2022</a>.</p>
</div>
</div>
</main><aside class="col-md-3"><nav id="toc" aria-label="Table of contents"><h2>On this page</h2>
</nav></aside>
</div>
<footer><div class="pkgdown-footer-left">
<p>Developed by John Benninghoff.</p>
</div>
<div class="pkgdown-footer-right">
<p>Site built with <a href="https://pkgdown.r-lib.org/" class="external-link">pkgdown</a> 2.2.0.</p>
</div>
</footer>
</div>
</body>
</html>