Debian Codegraph @

inst/doc/caseconverters.html

raw
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="Malte Grosser" />
14
15 <meta name="date" content="2023-08-27" />
16
17 <title>Case converters</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 pre > code.sourceCode { white-space: pre; position: relative; }
54 pre > code.sourceCode > span { display: inline-block; line-height: 1.25; }
55 pre > code.sourceCode > span:empty { height: 1.2em; }
56 .sourceCode { overflow: visible; }
57 code.sourceCode > span { color: inherit; text-decoration: inherit; }
58 div.sourceCode { margin: 1em 0; }
59 pre.sourceCode { margin: 0; }
60 @media screen {
61 div.sourceCode { overflow: auto; }
62 }
63 @media print {
64 pre > code.sourceCode { white-space: pre-wrap; }
65 pre > code.sourceCode > span { text-indent: -5em; padding-left: 5em; }
66 }
67 pre.numberSource code
68 { counter-reset: source-line 0; }
69 pre.numberSource code > span
70 { position: relative; left: -4em; counter-increment: source-line; }
71 pre.numberSource code > span > a:first-child::before
72 { content: counter(source-line);
73 position: relative; left: -1em; text-align: right; vertical-align: baseline;
74 border: none; display: inline-block;
75 -webkit-touch-callout: none; -webkit-user-select: none;
76 -khtml-user-select: none; -moz-user-select: none;
77 -ms-user-select: none; user-select: none;
78 padding: 0 4px; width: 4em;
79 color: #aaaaaa;
80 }
81 pre.numberSource { margin-left: 3em; border-left: 1px solid #aaaaaa; padding-left: 4px; }
82 div.sourceCode
83 { }
84 @media screen {
85 pre > code.sourceCode > span > a:first-child::before { text-decoration: underline; }
86 }
87 code span.al { color: #ff0000; font-weight: bold; }
88 code span.an { color: #60a0b0; font-weight: bold; font-style: italic; }
89 code span.at { color: #7d9029; }
90 code span.bn { color: #40a070; }
91 code span.bu { color: #008000; }
92 code span.cf { color: #007020; font-weight: bold; }
93 code span.ch { color: #4070a0; }
94 code span.cn { color: #880000; }
95 code span.co { color: #60a0b0; font-style: italic; }
96 code span.cv { color: #60a0b0; font-weight: bold; font-style: italic; }
97 code span.do { color: #ba2121; font-style: italic; }
98 code span.dt { color: #902000; }
99 code span.dv { color: #40a070; }
100 code span.er { color: #ff0000; font-weight: bold; }
101 code span.ex { }
102 code span.fl { color: #40a070; }
103 code span.fu { color: #06287e; }
104 code span.im { color: #008000; font-weight: bold; }
105 code span.in { color: #60a0b0; font-weight: bold; font-style: italic; }
106 code span.kw { color: #007020; font-weight: bold; }
107 code span.op { color: #666666; }
108 code span.ot { color: #007020; }
109 code span.pp { color: #bc7a00; }
110 code span.sc { color: #4070a0; }
111 code span.ss { color: #bb6688; }
112 code span.st { color: #4070a0; }
113 code span.va { color: #19177c; }
114 code span.vs { color: #4070a0; }
115 code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; }
116 </style>
117 <script>
118 // apply pandoc div.sourceCode style to pre.sourceCode instead
119 (function() {
120 var sheets = document.styleSheets;
121 for (var i = 0; i < sheets.length; i++) {
122 if (sheets[i].ownerNode.dataset["origin"] !== "pandoc") continue;
123 try { var rules = sheets[i].cssRules; } catch (e) { continue; }
124 var j = 0;
125 while (j < rules.length) {
126 var rule = rules[j];
127 // check if there is a div.sourceCode rule
128 if (rule.type !== rule.STYLE_RULE || rule.selectorText !== "div.sourceCode") {
129 j++;
130 continue;
131 }
132 var style = rule.style.cssText;
133 // check if color or background-color is set
134 if (rule.style.color === '' && rule.style.backgroundColor === '') {
135 j++;
136 continue;
137 }
138 // replace div.sourceCode by a pre.sourceCode rule
139 sheets[i].deleteRule(j);
140 sheets[i].insertRule('pre.sourceCode{' + style + '}', j);
141 }
142 }
143 })();
144 </script>
145
146
147
148
149 <style type="text/css">body {
150 background-color: #fff;
151 margin: 1em auto;
152 max-width: 700px;
153 overflow: visible;
154 padding-left: 2em;
155 padding-right: 2em;
156 font-family: "Open Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
157 font-size: 14px;
158 line-height: 1.35;
159 }
160 #TOC {
161 clear: both;
162 margin: 0 0 10px 10px;
163 padding: 4px;
164 width: 400px;
165 border: 1px solid #CCCCCC;
166 border-radius: 5px;
167 background-color: #f6f6f6;
168 font-size: 13px;
169 line-height: 1.3;
170 }
171 #TOC .toctitle {
172 font-weight: bold;
173 font-size: 15px;
174 margin-left: 5px;
175 }
176 #TOC ul {
177 padding-left: 40px;
178 margin-left: -1.5em;
179 margin-top: 5px;
180 margin-bottom: 5px;
181 }
182 #TOC ul ul {
183 margin-left: -2em;
184 }
185 #TOC li {
186 line-height: 16px;
187 }
188 table {
189 margin: 1em auto;
190 border-width: 1px;
191 border-color: #DDDDDD;
192 border-style: outset;
193 border-collapse: collapse;
194 }
195 table th {
196 border-width: 2px;
197 padding: 5px;
198 border-style: inset;
199 }
200 table td {
201 border-width: 1px;
202 border-style: inset;
203 line-height: 18px;
204 padding: 5px 5px;
205 }
206 table, table th, table td {
207 border-left-style: none;
208 border-right-style: none;
209 }
210 table thead, table tr.even {
211 background-color: #f7f7f7;
212 }
213 p {
214 margin: 0.5em 0;
215 }
216 blockquote {
217 background-color: #f6f6f6;
218 padding: 0.25em 0.75em;
219 }
220 hr {
221 border-style: solid;
222 border: none;
223 border-top: 1px solid #777;
224 margin: 28px 0;
225 }
226 dl {
227 margin-left: 0;
228 }
229 dl dd {
230 margin-bottom: 13px;
231 margin-left: 13px;
232 }
233 dl dt {
234 font-weight: bold;
235 }
236 ul {
237 margin-top: 0;
238 }
239 ul li {
240 list-style: circle outside;
241 }
242 ul ul {
243 margin-bottom: 0;
244 }
245 pre, code {
246 background-color: #f7f7f7;
247 border-radius: 3px;
248 color: #333;
249 white-space: pre-wrap;
250 }
251 pre {
252 border-radius: 3px;
253 margin: 5px 0px 10px 0px;
254 padding: 10px;
255 }
256 pre:not([class]) {
257 background-color: #f7f7f7;
258 }
259 code {
260 font-family: Consolas, Monaco, 'Courier New', monospace;
261 font-size: 85%;
262 }
263 p > code, li > code {
264 padding: 2px 0px;
265 }
266 div.figure {
267 text-align: center;
268 }
269 img {
270 background-color: #FFFFFF;
271 padding: 2px;
272 border: 1px solid #DDDDDD;
273 border-radius: 3px;
274 border: 1px solid #CCCCCC;
275 margin: 0 5px;
276 }
277 h1 {
278 margin-top: 0;
279 font-size: 35px;
280 line-height: 40px;
281 }
282 h2 {
283 border-bottom: 4px solid #f7f7f7;
284 padding-top: 10px;
285 padding-bottom: 2px;
286 font-size: 145%;
287 }
288 h3 {
289 border-bottom: 2px solid #f7f7f7;
290 padding-top: 10px;
291 font-size: 120%;
292 }
293 h4 {
294 border-bottom: 1px solid #f7f7f7;
295 margin-left: 8px;
296 font-size: 105%;
297 }
298 h5, h6 {
299 border-bottom: 1px solid #ccc;
300 font-size: 105%;
301 }
302 a {
303 color: #0033dd;
304 text-decoration: none;
305 }
306 a:hover {
307 color: #6666ff; }
308 a:visited {
309 color: #800080; }
310 a:visited:hover {
311 color: #BB00BB; }
312 a[href^="http:"] {
313 text-decoration: underline; }
314 a[href^="https:"] {
315 text-decoration: underline; }
316
317 code > span.kw { color: #555; font-weight: bold; }
318 code > span.dt { color: #902000; }
319 code > span.dv { color: #40a070; }
320 code > span.bn { color: #d14; }
321 code > span.fl { color: #d14; }
322 code > span.ch { color: #d14; }
323 code > span.st { color: #d14; }
324 code > span.co { color: #888888; font-style: italic; }
325 code > span.ot { color: #007020; }
326 code > span.al { color: #ff0000; font-weight: bold; }
327 code > span.fu { color: #900; font-weight: bold; }
328 code > span.er { color: #a61717; background-color: #e3d2d2; }
329 </style>
330
331
332
333
334 </head>
335
336 <body>
337
338
339
340
341 <h1 class="title toc-ignore">Case converters</h1>
342 <h4 class="author">Malte Grosser</h4>
343 <h4 class="date">2023-08-27</h4>
344
345
346
347 <div id="basic-examples" class="section level2">
348 <h2>Basic examples</h2>
349 <p>Default case is snake case</p>
350 <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>(snakecase)</span>
351 <span id="cb1-2"><a href="#cb1-2" tabindex="-1"></a><span class="fu">to_any_case</span>(<span class="st">&quot;veryComplicatedString&quot;</span>)</span>
352 <span id="cb1-3"><a href="#cb1-3" tabindex="-1"></a><span class="do">## [1] &quot;very_complicated_string&quot;</span></span></code></pre></div>
353 <p>Of course other cases are supported (<code>case</code>) and
354 separators can be adjusted (<code>sep_out</code>)</p>
355 <div class="sourceCode" id="cb2"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb2-1"><a href="#cb2-1" tabindex="-1"></a><span class="fu">to_any_case</span>(<span class="fu">names</span>(iris), <span class="at">sep_in =</span> <span class="st">&quot;</span><span class="sc">\\</span><span class="st">.&quot;</span>, <span class="at">case =</span> <span class="st">&quot;upper_camel&quot;</span>, <span class="at">sep_out =</span> <span class="st">&quot; &quot;</span>)</span>
356 <span id="cb2-2"><a href="#cb2-2" tabindex="-1"></a><span class="do">## [1] &quot;Sepal Length&quot; &quot;Sepal Width&quot; &quot;Petal Length&quot; &quot;Petal Width&quot; &quot;Species&quot;</span></span></code></pre></div>
357 <p>And you might want to remove special characters along the way</p>
358 <div class="sourceCode" id="cb3"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb3-1"><a href="#cb3-1" tabindex="-1"></a><span class="fu">to_any_case</span>(<span class="st">&quot;Doppelgänger is originally german&quot;</span>, </span>
359 <span id="cb3-2"><a href="#cb3-2" tabindex="-1"></a> <span class="at">transliterations =</span> <span class="st">&quot;german&quot;</span>, <span class="at">case =</span> <span class="st">&quot;upper_camel&quot;</span>)</span>
360 <span id="cb3-3"><a href="#cb3-3" tabindex="-1"></a><span class="do">## [1] &quot;DoppelgaengerIsOriginallyGerman&quot;</span></span></code></pre></div>
361 <p>All of the cases like: snake, lower_camel, upper_camel, all_caps,
362 lower_upper, upper_lower, mixed and sentence are based on parsed
363 case</p>
364 <div class="sourceCode" id="cb4"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb4-1"><a href="#cb4-1" tabindex="-1"></a><span class="fu">to_any_case</span>(<span class="st">&quot;THISIsHOW IAmPARSED!&quot;</span>, <span class="at">case =</span> <span class="st">&quot;parsed&quot;</span>)</span>
365 <span id="cb4-2"><a href="#cb4-2" tabindex="-1"></a><span class="do">## [1] &quot;THIS_Is_HOW_I_Am_PARSED&quot;</span></span></code></pre></div>
366 <p>Shortcut wrappers like <code>to_snake_case</code>,
367 <code>to_lower_camel_case</code> etc. are available.</p>
368 <p>Be aware that automatic case conversion depends on the input string
369 and it is recommended to verify the results. So you might want to pipe
370 these into <code>dput()</code> and hardcode name changes instead of
371 blindly trusting <code>to_any_case()</code>’s output:</p>
372 <div class="sourceCode" id="cb5"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb5-1"><a href="#cb5-1" tabindex="-1"></a><span class="fu">dput</span>(<span class="fu">to_any_case</span>(<span class="fu">c</span>(<span class="st">&quot;SomeBAdInput&quot;</span>, <span class="st">&quot;someGoodInput&quot;</span>)))</span>
373 <span id="cb5-2"><a href="#cb5-2" tabindex="-1"></a><span class="do">## c(&quot;some_b_ad_input&quot;, &quot;some_good_input&quot;)</span></span></code></pre></div>
374 <p>If you are interested in the design of this package, you can find
375 more information on its <a href="https://github.com/Tazinho/snakecase">github page</a>.</p>
376 </div>
377
378
379
380 <!-- code folding -->
381
382
383 <!-- dynamically load mathjax for compatibility with self-contained -->
384 <script>
385 (function () {
386 var script = document.createElement("script");
387 script.type = "text/javascript";
388 script.src = "https://mathjax.rstudio.com/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML";
389 document.getElementsByTagName("head")[0].appendChild(script);
390 })();
391 </script>
392
393 </body>
394 </html>