| 1 |
<!DOCTYPE html> |
| 2 |
|
| 3 |
<html> |
| 4 |
|
| 5 |
<head> |
| 6 |
|
| 7 |
<meta charset="utf-8" /> |
| 8 |
<meta name="generator" content="pandoc" /> |
| 9 |
<meta http-equiv="X-UA-Compatible" content="IE=EDGE" /> |
| 10 |
|
| 11 |
<meta name="viewport" content="width=device-width, initial-scale=1" /> |
| 12 |
|
| 13 |
<meta name="author" content="Michel Lang" /> |
| 14 |
|
| 15 |
<meta name="date" content="2026-02-02" /> |
| 16 |
|
| 17 |
<title>Setup tinytest</title> |
| 18 |
|
| 19 |
<script>// Pandoc 2.9 adds attributes on both header and div. We remove the former (to |
| 20 |
// be compatible with the behavior of Pandoc < 2.8). |
| 21 |
document.addEventListener('DOMContentLoaded', function(e) { |
| 22 |
var hs = document.querySelectorAll("div.section[class*='level'] > :first-child"); |
| 23 |
var i, h, a; |
| 24 |
for (i = 0; i < hs.length; i++) { |
| 25 |
h = hs[i]; |
| 26 |
if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6 |
| 27 |
a = h.attributes; |
| 28 |
while (a.length > 0) h.removeAttribute(a[0].name); |
| 29 |
} |
| 30 |
}); |
| 31 |
</script> |
| 32 |
|
| 33 |
<style type="text/css"> |
| 34 |
code{white-space: pre-wrap;} |
| 35 |
span.smallcaps{font-variant: small-caps;} |
| 36 |
span.underline{text-decoration: underline;} |
| 37 |
div.column{display: inline-block; vertical-align: top; width: 50%;} |
| 38 |
div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;} |
| 39 |
ul.task-list{list-style: none;} |
| 40 |
</style> |
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
<style type="text/css"> |
| 45 |
code { |
| 46 |
white-space: pre; |
| 47 |
} |
| 48 |
.sourceCode { |
| 49 |
overflow: visible; |
| 50 |
} |
| 51 |
</style> |
| 52 |
<style type="text/css" data-origin="pandoc"> |
| 53 |
html { -webkit-text-size-adjust: 100%; } |
| 54 |
pre > code.sourceCode { white-space: pre; position: relative; } |
| 55 |
pre > code.sourceCode > span { display: inline-block; line-height: 1.25; } |
| 56 |
pre > code.sourceCode > span:empty { height: 1.2em; } |
| 57 |
.sourceCode { overflow: visible; } |
| 58 |
code.sourceCode > span { color: inherit; text-decoration: inherit; } |
| 59 |
div.sourceCode { margin: 1em 0; } |
| 60 |
pre.sourceCode { margin: 0; } |
| 61 |
@media screen { |
| 62 |
div.sourceCode { overflow: auto; } |
| 63 |
} |
| 64 |
@media print { |
| 65 |
pre > code.sourceCode { white-space: pre-wrap; } |
| 66 |
pre > code.sourceCode > span { text-indent: -5em; padding-left: 5em; } |
| 67 |
} |
| 68 |
pre.numberSource code |
| 69 |
{ counter-reset: source-line 0; } |
| 70 |
pre.numberSource code > span |
| 71 |
{ position: relative; left: -4em; counter-increment: source-line; } |
| 72 |
pre.numberSource code > span > a:first-child::before |
| 73 |
{ content: counter(source-line); |
| 74 |
position: relative; left: -1em; text-align: right; vertical-align: baseline; |
| 75 |
border: none; display: inline-block; |
| 76 |
-webkit-touch-callout: none; -webkit-user-select: none; |
| 77 |
-khtml-user-select: none; -moz-user-select: none; |
| 78 |
-ms-user-select: none; user-select: none; |
| 79 |
padding: 0 4px; width: 4em; |
| 80 |
color: #aaaaaa; |
| 81 |
} |
| 82 |
pre.numberSource { margin-left: 3em; border-left: 1px solid #aaaaaa; padding-left: 4px; } |
| 83 |
div.sourceCode |
| 84 |
{ } |
| 85 |
@media screen { |
| 86 |
pre > code.sourceCode > span > a:first-child::before { text-decoration: underline; } |
| 87 |
} |
| 88 |
code span.al { color: #ff0000; font-weight: bold; } |
| 89 |
code span.an { color: #60a0b0; font-weight: bold; font-style: italic; } |
| 90 |
code span.at { color: #7d9029; } |
| 91 |
code span.bn { color: #40a070; } |
| 92 |
code span.bu { color: #008000; } |
| 93 |
code span.cf { color: #007020; font-weight: bold; } |
| 94 |
code span.ch { color: #4070a0; } |
| 95 |
code span.cn { color: #880000; } |
| 96 |
code span.co { color: #60a0b0; font-style: italic; } |
| 97 |
code span.cv { color: #60a0b0; font-weight: bold; font-style: italic; } |
| 98 |
code span.do { color: #ba2121; font-style: italic; } |
| 99 |
code span.dt { color: #902000; } |
| 100 |
code span.dv { color: #40a070; } |
| 101 |
code span.er { color: #ff0000; font-weight: bold; } |
| 102 |
code span.ex { } |
| 103 |
code span.fl { color: #40a070; } |
| 104 |
code span.fu { color: #06287e; } |
| 105 |
code span.im { color: #008000; font-weight: bold; } |
| 106 |
code span.in { color: #60a0b0; font-weight: bold; font-style: italic; } |
| 107 |
code span.kw { color: #007020; font-weight: bold; } |
| 108 |
code span.op { color: #666666; } |
| 109 |
code span.ot { color: #007020; } |
| 110 |
code span.pp { color: #bc7a00; } |
| 111 |
code span.sc { color: #4070a0; } |
| 112 |
code span.ss { color: #bb6688; } |
| 113 |
code span.st { color: #4070a0; } |
| 114 |
code span.va { color: #19177c; } |
| 115 |
code span.vs { color: #4070a0; } |
| 116 |
code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } |
| 117 |
</style> |
| 118 |
<script> |
| 119 |
// apply pandoc div.sourceCode style to pre.sourceCode instead |
| 120 |
(function() { |
| 121 |
var sheets = document.styleSheets; |
| 122 |
for (var i = 0; i < sheets.length; i++) { |
| 123 |
if (sheets[i].ownerNode.dataset["origin"] !== "pandoc") continue; |
| 124 |
try { var rules = sheets[i].cssRules; } catch (e) { continue; } |
| 125 |
var j = 0; |
| 126 |
while (j < rules.length) { |
| 127 |
var rule = rules[j]; |
| 128 |
// check if there is a div.sourceCode rule |
| 129 |
if (rule.type !== rule.STYLE_RULE || rule.selectorText !== "div.sourceCode") { |
| 130 |
j++; |
| 131 |
continue; |
| 132 |
} |
| 133 |
var style = rule.style.cssText; |
| 134 |
// check if color or background-color is set |
| 135 |
if (rule.style.color === '' && rule.style.backgroundColor === '') { |
| 136 |
j++; |
| 137 |
continue; |
| 138 |
} |
| 139 |
// replace div.sourceCode by a pre.sourceCode rule |
| 140 |
sheets[i].deleteRule(j); |
| 141 |
sheets[i].insertRule('pre.sourceCode{' + style + '}', j); |
| 142 |
} |
| 143 |
} |
| 144 |
})(); |
| 145 |
</script> |
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
<style type="text/css">body { |
| 151 |
background-color: #fff; |
| 152 |
margin: 1em auto; |
| 153 |
max-width: 700px; |
| 154 |
overflow: visible; |
| 155 |
padding-left: 2em; |
| 156 |
padding-right: 2em; |
| 157 |
font-family: "Open Sans", "Helvetica Neue", Helvetica, Arial, sans-serif; |
| 158 |
font-size: 14px; |
| 159 |
line-height: 1.35; |
| 160 |
} |
| 161 |
#TOC { |
| 162 |
clear: both; |
| 163 |
margin: 0 0 10px 10px; |
| 164 |
padding: 4px; |
| 165 |
width: 400px; |
| 166 |
border: 1px solid #CCCCCC; |
| 167 |
border-radius: 5px; |
| 168 |
background-color: #f6f6f6; |
| 169 |
font-size: 13px; |
| 170 |
line-height: 1.3; |
| 171 |
} |
| 172 |
#TOC .toctitle { |
| 173 |
font-weight: bold; |
| 174 |
font-size: 15px; |
| 175 |
margin-left: 5px; |
| 176 |
} |
| 177 |
#TOC ul { |
| 178 |
padding-left: 40px; |
| 179 |
margin-left: -1.5em; |
| 180 |
margin-top: 5px; |
| 181 |
margin-bottom: 5px; |
| 182 |
} |
| 183 |
#TOC ul ul { |
| 184 |
margin-left: -2em; |
| 185 |
} |
| 186 |
#TOC li { |
| 187 |
line-height: 16px; |
| 188 |
} |
| 189 |
table { |
| 190 |
margin: 1em auto; |
| 191 |
border-width: 1px; |
| 192 |
border-color: #DDDDDD; |
| 193 |
border-style: outset; |
| 194 |
border-collapse: collapse; |
| 195 |
} |
| 196 |
table th { |
| 197 |
border-width: 2px; |
| 198 |
padding: 5px; |
| 199 |
border-style: inset; |
| 200 |
} |
| 201 |
table td { |
| 202 |
border-width: 1px; |
| 203 |
border-style: inset; |
| 204 |
line-height: 18px; |
| 205 |
padding: 5px 5px; |
| 206 |
} |
| 207 |
table, table th, table td { |
| 208 |
border-left-style: none; |
| 209 |
border-right-style: none; |
| 210 |
} |
| 211 |
table thead, table tr.even { |
| 212 |
background-color: #f7f7f7; |
| 213 |
} |
| 214 |
p { |
| 215 |
margin: 0.5em 0; |
| 216 |
} |
| 217 |
blockquote { |
| 218 |
background-color: #f6f6f6; |
| 219 |
padding: 0.25em 0.75em; |
| 220 |
} |
| 221 |
hr { |
| 222 |
border-style: solid; |
| 223 |
border: none; |
| 224 |
border-top: 1px solid #777; |
| 225 |
margin: 28px 0; |
| 226 |
} |
| 227 |
dl { |
| 228 |
margin-left: 0; |
| 229 |
} |
| 230 |
dl dd { |
| 231 |
margin-bottom: 13px; |
| 232 |
margin-left: 13px; |
| 233 |
} |
| 234 |
dl dt { |
| 235 |
font-weight: bold; |
| 236 |
} |
| 237 |
ul { |
| 238 |
margin-top: 0; |
| 239 |
} |
| 240 |
ul li { |
| 241 |
list-style: circle outside; |
| 242 |
} |
| 243 |
ul ul { |
| 244 |
margin-bottom: 0; |
| 245 |
} |
| 246 |
pre, code { |
| 247 |
background-color: #f7f7f7; |
| 248 |
border-radius: 3px; |
| 249 |
color: #333; |
| 250 |
white-space: pre-wrap; |
| 251 |
} |
| 252 |
pre { |
| 253 |
border-radius: 3px; |
| 254 |
margin: 5px 0px 10px 0px; |
| 255 |
padding: 10px; |
| 256 |
} |
| 257 |
pre:not([class]) { |
| 258 |
background-color: #f7f7f7; |
| 259 |
} |
| 260 |
code { |
| 261 |
font-family: Consolas, Monaco, 'Courier New', monospace; |
| 262 |
font-size: 85%; |
| 263 |
} |
| 264 |
p > code, li > code { |
| 265 |
padding: 2px 0px; |
| 266 |
} |
| 267 |
div.figure { |
| 268 |
text-align: center; |
| 269 |
} |
| 270 |
img { |
| 271 |
background-color: #FFFFFF; |
| 272 |
padding: 2px; |
| 273 |
border: 1px solid #DDDDDD; |
| 274 |
border-radius: 3px; |
| 275 |
border: 1px solid #CCCCCC; |
| 276 |
margin: 0 5px; |
| 277 |
} |
| 278 |
h1 { |
| 279 |
margin-top: 0; |
| 280 |
font-size: 35px; |
| 281 |
line-height: 40px; |
| 282 |
} |
| 283 |
h2 { |
| 284 |
border-bottom: 4px solid #f7f7f7; |
| 285 |
padding-top: 10px; |
| 286 |
padding-bottom: 2px; |
| 287 |
font-size: 145%; |
| 288 |
} |
| 289 |
h3 { |
| 290 |
border-bottom: 2px solid #f7f7f7; |
| 291 |
padding-top: 10px; |
| 292 |
font-size: 120%; |
| 293 |
} |
| 294 |
h4 { |
| 295 |
border-bottom: 1px solid #f7f7f7; |
| 296 |
margin-left: 8px; |
| 297 |
font-size: 105%; |
| 298 |
} |
| 299 |
h5, h6 { |
| 300 |
border-bottom: 1px solid #ccc; |
| 301 |
font-size: 105%; |
| 302 |
} |
| 303 |
a { |
| 304 |
color: #0033dd; |
| 305 |
text-decoration: none; |
| 306 |
} |
| 307 |
a:hover { |
| 308 |
color: #6666ff; } |
| 309 |
a:visited { |
| 310 |
color: #800080; } |
| 311 |
a:visited:hover { |
| 312 |
color: #BB00BB; } |
| 313 |
a[href^="http:"] { |
| 314 |
text-decoration: underline; } |
| 315 |
a[href^="https:"] { |
| 316 |
text-decoration: underline; } |
| 317 |
|
| 318 |
code > span.kw { color: #555; font-weight: bold; } |
| 319 |
code > span.dt { color: #902000; } |
| 320 |
code > span.dv { color: #40a070; } |
| 321 |
code > span.bn { color: #d14; } |
| 322 |
code > span.fl { color: #d14; } |
| 323 |
code > span.ch { color: #d14; } |
| 324 |
code > span.st { color: #d14; } |
| 325 |
code > span.co { color: #888888; font-style: italic; } |
| 326 |
code > span.ot { color: #007020; } |
| 327 |
code > span.al { color: #ff0000; font-weight: bold; } |
| 328 |
code > span.fu { color: #900; font-weight: bold; } |
| 329 |
code > span.er { color: #a61717; background-color: #e3d2d2; } |
| 330 |
</style> |
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
</head> |
| 336 |
|
| 337 |
<body> |
| 338 |
|
| 339 |
|
| 340 |
|
| 341 |
|
| 342 |
<h1 class="title toc-ignore">Setup tinytest</h1> |
| 343 |
<h4 class="author">Michel Lang</h4> |
| 344 |
<h4 class="date">2026-02-02</h4> |
| 345 |
|
| 346 |
|
| 347 |
|
| 348 |
<div id="setup-tinytest" class="section level2"> |
| 349 |
<h2>Setup <code>tinytest</code></h2> |
| 350 |
<p>Setting up the <code>tinytest</code> framework is covered in detail |
| 351 |
in the documentation of <a href="https://cran.r-project.org/package=tinytest">tinytest</a>. Quick |
| 352 |
summary:</p> |
| 353 |
<ol style="list-style-type: decimal"> |
| 354 |
<li>In the package root directory, call |
| 355 |
<code>tinytest::setup_tinytest(".")</code>.</li> |
| 356 |
<li>Edit/add R scripts with unit tests to the directory |
| 357 |
<code>inst/tinytest</code>.</li> |
| 358 |
</ol> |
| 359 |
</div> |
| 360 |
<div id="setup-checkmate" class="section level2"> |
| 361 |
<h2>Setup <code>checkmate</code></h2> |
| 362 |
<ol style="list-style-type: decimal"> |
| 363 |
<li><p>Edit your <code>DESCRIPTION</code> and add <code>checkmate</code> |
| 364 |
to <code>Suggests</code> unless it is already listed in |
| 365 |
<code>Imports</code> for its assertions.</p></li> |
| 366 |
<li><p>In <strong>each</strong> test file which calls an expectation |
| 367 |
from <code>checkmate</code>, you must include the following lines at the |
| 368 |
beginning of the file:</p> |
| 369 |
<div class="sourceCode" id="cb1"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb1-1"><a href="#cb1-1" tabindex="-1"></a><span class="fu">library</span>(<span class="st">"tinytest"</span>)</span> |
| 370 |
<span id="cb1-2"><a href="#cb1-2" tabindex="-1"></a><span class="fu">library</span>(<span class="st">"checkmate"</span>)</span> |
| 371 |
<span id="cb1-3"><a href="#cb1-3" tabindex="-1"></a><span class="fu">using</span>(<span class="st">"checkmate"</span>)</span></code></pre></div> |
| 372 |
<p>If you forget the last line, expectations will not get reported |
| 373 |
correctly in the summary. Also note that sourcing a file which includes |
| 374 |
<code>using("checkmate")</code> is <strong>not</strong> |
| 375 |
sufficient.</p></li> |
| 376 |
<li><p>Check if everything works with <code>R CMD check</code>.</p></li> |
| 377 |
</ol> |
| 378 |
</div> |
| 379 |
|
| 380 |
|
| 381 |
|
| 382 |
<!-- code folding --> |
| 383 |
|
| 384 |
|
| 385 |
<!-- dynamically load mathjax for compatibility with self-contained --> |
| 386 |
<script> |
| 387 |
(function () { |
| 388 |
var script = document.createElement("script"); |
| 389 |
script.type = "text/javascript"; |
| 390 |
script.src = "https://mathjax.rstudio.com/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"; |
| 391 |
document.getElementsByTagName("head")[0].appendChild(script); |
| 392 |
})(); |
| 393 |
</script> |
| 394 |
|
| 395 |
</body> |
| 396 |
</html> |