Debian Codegraph @

inst/doc/compatibility.html

raw symbols SCIP
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
14
15 <title>Compatibility with S3 and S4</title>
16
17 <script>// Pandoc 2.9 adds attributes on both header and div. We remove the former (to
18 // be compatible with the behavior of Pandoc < 2.8).
19 document.addEventListener('DOMContentLoaded', function(e) {
20 var hs = document.querySelectorAll("div.section[class*='level'] > :first-child");
21 var i, h, a;
22 for (i = 0; i < hs.length; i++) {
23 h = hs[i];
24 if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6
25 a = h.attributes;
26 while (a.length > 0) h.removeAttribute(a[0].name);
27 }
28 });
29 </script>
30
31 <style type="text/css">
32 code{white-space: pre-wrap;}
33 span.smallcaps{font-variant: small-caps;}
34 span.underline{text-decoration: underline;}
35 div.column{display: inline-block; vertical-align: top; width: 50%;}
36 div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
37 ul.task-list{list-style: none;}
38 </style>
39
40
41
42 <style type="text/css">
43 code {
44 white-space: pre;
45 }
46 .sourceCode {
47 overflow: visible;
48 }
49 </style>
50 <style type="text/css" data-origin="pandoc">
51 html { -webkit-text-size-adjust: 100%; }
52 pre > code.sourceCode { white-space: pre; position: relative; }
53 pre > code.sourceCode > span { display: inline-block; line-height: 1.25; }
54 pre > code.sourceCode > span:empty { height: 1.2em; }
55 .sourceCode { overflow: visible; }
56 code.sourceCode > span { color: inherit; text-decoration: inherit; }
57 div.sourceCode { margin: 1em 0; }
58 pre.sourceCode { margin: 0; }
59 @media screen {
60 div.sourceCode { overflow: auto; }
61 }
62 @media print {
63 pre > code.sourceCode { white-space: pre-wrap; }
64 pre > code.sourceCode > span { text-indent: -5em; padding-left: 5em; }
65 }
66 pre.numberSource code
67 { counter-reset: source-line 0; }
68 pre.numberSource code > span
69 { position: relative; left: -4em; counter-increment: source-line; }
70 pre.numberSource code > span > a:first-child::before
71 { content: counter(source-line);
72 position: relative; left: -1em; text-align: right; vertical-align: baseline;
73 border: none; display: inline-block;
74 -webkit-touch-callout: none; -webkit-user-select: none;
75 -khtml-user-select: none; -moz-user-select: none;
76 -ms-user-select: none; user-select: none;
77 padding: 0 4px; width: 4em;
78 color: #aaaaaa;
79 }
80 pre.numberSource { margin-left: 3em; border-left: 1px solid #aaaaaa; padding-left: 4px; }
81 div.sourceCode
82 { }
83 @media screen {
84 pre > code.sourceCode > span > a:first-child::before { text-decoration: underline; }
85 }
86 code span.al { color: #ff0000; font-weight: bold; }
87 code span.an { color: #60a0b0; font-weight: bold; font-style: italic; }
88 code span.at { color: #7d9029; }
89 code span.bn { color: #40a070; }
90 code span.bu { color: #008000; }
91 code span.cf { color: #007020; font-weight: bold; }
92 code span.ch { color: #4070a0; }
93 code span.cn { color: #880000; }
94 code span.co { color: #60a0b0; font-style: italic; }
95 code span.cv { color: #60a0b0; font-weight: bold; font-style: italic; }
96 code span.do { color: #ba2121; font-style: italic; }
97 code span.dt { color: #902000; }
98 code span.dv { color: #40a070; }
99 code span.er { color: #ff0000; font-weight: bold; }
100 code span.ex { }
101 code span.fl { color: #40a070; }
102 code span.fu { color: #06287e; }
103 code span.im { color: #008000; font-weight: bold; }
104 code span.in { color: #60a0b0; font-weight: bold; font-style: italic; }
105 code span.kw { color: #007020; font-weight: bold; }
106 code span.op { color: #666666; }
107 code span.ot { color: #007020; }
108 code span.pp { color: #bc7a00; }
109 code span.sc { color: #4070a0; }
110 code span.ss { color: #bb6688; }
111 code span.st { color: #4070a0; }
112 code span.va { color: #19177c; }
113 code span.vs { color: #4070a0; }
114 code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; }
115 </style>
116 <script>
117 // apply pandoc div.sourceCode style to pre.sourceCode instead
118 (function() {
119 var sheets = document.styleSheets;
120 for (var i = 0; i < sheets.length; i++) {
121 if (sheets[i].ownerNode.dataset["origin"] !== "pandoc") continue;
122 try { var rules = sheets[i].cssRules; } catch (e) { continue; }
123 var j = 0;
124 while (j < rules.length) {
125 var rule = rules[j];
126 // check if there is a div.sourceCode rule
127 if (rule.type !== rule.STYLE_RULE || rule.selectorText !== "div.sourceCode") {
128 j++;
129 continue;
130 }
131 var style = rule.style.cssText;
132 // check if color or background-color is set
133 if (rule.style.color === '' && rule.style.backgroundColor === '') {
134 j++;
135 continue;
136 }
137 // replace div.sourceCode by a pre.sourceCode rule
138 sheets[i].deleteRule(j);
139 sheets[i].insertRule('pre.sourceCode{' + style + '}', j);
140 }
141 }
142 })();
143 </script>
144
145
146
147
148 <style type="text/css">body {
149 background-color: #fff;
150 margin: 1em auto;
151 max-width: 700px;
152 overflow: visible;
153 padding-left: 2em;
154 padding-right: 2em;
155 font-family: "Open Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
156 font-size: 14px;
157 line-height: 1.35;
158 }
159 #TOC {
160 clear: both;
161 margin: 0 0 10px 10px;
162 padding: 4px;
163 width: 400px;
164 border: 1px solid #CCCCCC;
165 border-radius: 5px;
166 background-color: #f6f6f6;
167 font-size: 13px;
168 line-height: 1.3;
169 }
170 #TOC .toctitle {
171 font-weight: bold;
172 font-size: 15px;
173 margin-left: 5px;
174 }
175 #TOC ul {
176 padding-left: 40px;
177 margin-left: -1.5em;
178 margin-top: 5px;
179 margin-bottom: 5px;
180 }
181 #TOC ul ul {
182 margin-left: -2em;
183 }
184 #TOC li {
185 line-height: 16px;
186 }
187 table {
188 margin: 1em auto;
189 border-width: 1px;
190 border-color: #DDDDDD;
191 border-style: outset;
192 border-collapse: collapse;
193 }
194 table th {
195 border-width: 2px;
196 padding: 5px;
197 border-style: inset;
198 }
199 table td {
200 border-width: 1px;
201 border-style: inset;
202 line-height: 18px;
203 padding: 5px 5px;
204 }
205 table, table th, table td {
206 border-left-style: none;
207 border-right-style: none;
208 }
209 table thead, table tr.even {
210 background-color: #f7f7f7;
211 }
212 p {
213 margin: 0.5em 0;
214 }
215 blockquote {
216 background-color: #f6f6f6;
217 padding: 0.25em 0.75em;
218 }
219 hr {
220 border-style: solid;
221 border: none;
222 border-top: 1px solid #777;
223 margin: 28px 0;
224 }
225 dl {
226 margin-left: 0;
227 }
228 dl dd {
229 margin-bottom: 13px;
230 margin-left: 13px;
231 }
232 dl dt {
233 font-weight: bold;
234 }
235 ul {
236 margin-top: 0;
237 }
238 ul li {
239 list-style: circle outside;
240 }
241 ul ul {
242 margin-bottom: 0;
243 }
244 pre, code {
245 background-color: #f7f7f7;
246 border-radius: 3px;
247 color: #333;
248 white-space: pre-wrap;
249 }
250 pre {
251 border-radius: 3px;
252 margin: 5px 0px 10px 0px;
253 padding: 10px;
254 }
255 pre:not([class]) {
256 background-color: #f7f7f7;
257 }
258 code {
259 font-family: Consolas, Monaco, 'Courier New', monospace;
260 font-size: 85%;
261 }
262 p > code, li > code {
263 padding: 2px 0px;
264 }
265 div.figure {
266 text-align: center;
267 }
268 img {
269 background-color: #FFFFFF;
270 padding: 2px;
271 border: 1px solid #DDDDDD;
272 border-radius: 3px;
273 border: 1px solid #CCCCCC;
274 margin: 0 5px;
275 }
276 h1 {
277 margin-top: 0;
278 font-size: 35px;
279 line-height: 40px;
280 }
281 h2 {
282 border-bottom: 4px solid #f7f7f7;
283 padding-top: 10px;
284 padding-bottom: 2px;
285 font-size: 145%;
286 }
287 h3 {
288 border-bottom: 2px solid #f7f7f7;
289 padding-top: 10px;
290 font-size: 120%;
291 }
292 h4 {
293 border-bottom: 1px solid #f7f7f7;
294 margin-left: 8px;
295 font-size: 105%;
296 }
297 h5, h6 {
298 border-bottom: 1px solid #ccc;
299 font-size: 105%;
300 }
301 a {
302 color: #0033dd;
303 text-decoration: none;
304 }
305 a:hover {
306 color: #6666ff; }
307 a:visited {
308 color: #800080; }
309 a:visited:hover {
310 color: #BB00BB; }
311 a[href^="http:"] {
312 text-decoration: underline; }
313 a[href^="https:"] {
314 text-decoration: underline; }
315
316 code > span.kw { color: #555; font-weight: bold; }
317 code > span.dt { color: #902000; }
318 code > span.dv { color: #40a070; }
319 code > span.bn { color: #d14; }
320 code > span.fl { color: #d14; }
321 code > span.ch { color: #d14; }
322 code > span.st { color: #d14; }
323 code > span.co { color: #888888; font-style: italic; }
324 code > span.ot { color: #007020; }
325 code > span.al { color: #ff0000; font-weight: bold; }
326 code > span.fu { color: #900; font-weight: bold; }
327 code > span.er { color: #a61717; background-color: #e3d2d2; }
328 </style>
329
330
331
332
333 </head>
334
335 <body>
336
337
338
339
340 <h1 class="title toc-ignore">Compatibility with S3 and S4</h1>
341
342
343
344 <p>S7 is designed to be compatible with S3 and S4. This vignette
345 discusses the details.</p>
346 <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>(S7)</span></code></pre></div>
347 <div id="s3" class="section level2">
348 <h2>S3</h2>
349 <p>S7 objects <em>are</em> S3 objects, because S7 is implemented on top
350 of S3. There are two main differences between an S7 object and an S3
351 object:</p>
352 <ul>
353 <li><p>As well as the <code>class</code> attribute possessed by S3
354 objects, S7 objects have an additional <code>S7_class</code> attribute
355 that contains the object that defines the class.</p></li>
356 <li><p>S7 objects have properties; S3 objects have attributes.
357 Properties are implemented on top of attributes, so you can access them
358 directly with <code>attr</code> and friends. When working inside of S7,
359 you should never use attributes directly, but it does mean that existing
360 code will continue to work.</p></li>
361 </ul>
362 <p>All up, this means most usage of S7 with S3 will just work.</p>
363 <ul>
364 <li><p>S7 can register methods for:</p>
365 <ul>
366 <li>S7 class and S3 generic</li>
367 <li>S3 class and S7 generic</li>
368 </ul></li>
369 <li><p>S7 classes can extend S3 classes</p></li>
370 <li><p>S3 classes can extend S7 classes</p></li>
371 </ul>
372 <div id="methods" class="section level3">
373 <h3>Methods</h3>
374 <p><code>method()</code> is designed to be the single tool for method
375 registration that you need when working with S7 classes. You can also
376 register a method for an S7 class and S3 generic without using S7,
377 because all S7 objects have S3 classes, and S3 dispatch will operate on
378 them normally.</p>
379 <div class="sourceCode" id="cb2"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb2-1"><a href="#cb2-1" tabindex="-1"></a>Foo <span class="ot">&lt;-</span> <span class="fu">new_class</span>(<span class="st">&quot;Foo&quot;</span>)</span>
380 <span id="cb2-2"><a href="#cb2-2" tabindex="-1"></a><span class="fu">class</span>(<span class="fu">Foo</span>())</span>
381 <span id="cb2-3"><a href="#cb2-3" tabindex="-1"></a><span class="co">#&gt; [1] &quot;Foo&quot; &quot;S7_object&quot;</span></span>
382 <span id="cb2-4"><a href="#cb2-4" tabindex="-1"></a></span>
383 <span id="cb2-5"><a href="#cb2-5" tabindex="-1"></a>mean.Foo <span class="ot">&lt;-</span> <span class="cf">function</span>(x, ...) {</span>
384 <span id="cb2-6"><a href="#cb2-6" tabindex="-1"></a> <span class="st">&quot;mean of foo&quot;</span></span>
385 <span id="cb2-7"><a href="#cb2-7" tabindex="-1"></a>}</span>
386 <span id="cb2-8"><a href="#cb2-8" tabindex="-1"></a></span>
387 <span id="cb2-9"><a href="#cb2-9" tabindex="-1"></a><span class="fu">mean</span>(<span class="fu">Foo</span>())</span>
388 <span id="cb2-10"><a href="#cb2-10" tabindex="-1"></a><span class="co">#&gt; [1] &quot;mean of foo&quot;</span></span></code></pre></div>
389 </div>
390 <div id="classes" class="section level3">
391 <h3>Classes</h3>
392 <p>It’s possible to extend an S7 class with S3. This is primarily useful
393 because in many cases it allows you to change a class hierarchy from the
394 inside out: you can provide a formal definition of an S3 class using S7,
395 and its subclasses don’t need to change.</p>
396 </div>
397 <div id="list-classes" class="section level3">
398 <h3>List classes</h3>
399 <p>Many simple S3 classes are implemented as lists, e.g. rle.</p>
400 <div class="sourceCode" id="cb3"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb3-1"><a href="#cb3-1" tabindex="-1"></a>rle <span class="ot">&lt;-</span> <span class="cf">function</span>(x) {</span>
401 <span id="cb3-2"><a href="#cb3-2" tabindex="-1"></a> <span class="cf">if</span> (<span class="sc">!</span><span class="fu">is.vector</span>(x) <span class="sc">&amp;&amp;</span> <span class="sc">!</span><span class="fu">is.list</span>(x)) {</span>
402 <span id="cb3-3"><a href="#cb3-3" tabindex="-1"></a> <span class="fu">stop</span>(<span class="st">&quot;&#39;x&#39; must be a vector of an atomic type&quot;</span>)</span>
403 <span id="cb3-4"><a href="#cb3-4" tabindex="-1"></a> }</span>
404 <span id="cb3-5"><a href="#cb3-5" tabindex="-1"></a> n <span class="ot">&lt;-</span> <span class="fu">length</span>(x)</span>
405 <span id="cb3-6"><a href="#cb3-6" tabindex="-1"></a> <span class="cf">if</span> (n <span class="sc">==</span> <span class="dv">0</span><span class="dt">L</span>) {</span>
406 <span id="cb3-7"><a href="#cb3-7" tabindex="-1"></a> <span class="fu">new_rle</span>(<span class="fu">integer</span>(), x)</span>
407 <span id="cb3-8"><a href="#cb3-8" tabindex="-1"></a> } <span class="cf">else</span> {</span>
408 <span id="cb3-9"><a href="#cb3-9" tabindex="-1"></a> y <span class="ot">&lt;-</span> x[<span class="sc">-</span><span class="dv">1</span><span class="dt">L</span>] <span class="sc">!=</span> x[<span class="sc">-</span>n]</span>
409 <span id="cb3-10"><a href="#cb3-10" tabindex="-1"></a> i <span class="ot">&lt;-</span> <span class="fu">c</span>(<span class="fu">which</span>(y <span class="sc">|</span> <span class="fu">is.na</span>(y)), n)</span>
410 <span id="cb3-11"><a href="#cb3-11" tabindex="-1"></a> <span class="fu">new_rle</span>(<span class="fu">diff</span>(<span class="fu">c</span>(<span class="dv">0</span><span class="dt">L</span>, i)), x[i])</span>
411 <span id="cb3-12"><a href="#cb3-12" tabindex="-1"></a> }</span>
412 <span id="cb3-13"><a href="#cb3-13" tabindex="-1"></a>}</span>
413 <span id="cb3-14"><a href="#cb3-14" tabindex="-1"></a>new_rle <span class="ot">&lt;-</span> <span class="cf">function</span>(lengths, values) {</span>
414 <span id="cb3-15"><a href="#cb3-15" tabindex="-1"></a> <span class="fu">structure</span>(</span>
415 <span id="cb3-16"><a href="#cb3-16" tabindex="-1"></a> <span class="fu">list</span>(</span>
416 <span id="cb3-17"><a href="#cb3-17" tabindex="-1"></a> <span class="at">lengths =</span> lengths,</span>
417 <span id="cb3-18"><a href="#cb3-18" tabindex="-1"></a> <span class="at">values =</span> values</span>
418 <span id="cb3-19"><a href="#cb3-19" tabindex="-1"></a> ),</span>
419 <span id="cb3-20"><a href="#cb3-20" tabindex="-1"></a> <span class="at">class =</span> <span class="st">&quot;rle&quot;</span></span>
420 <span id="cb3-21"><a href="#cb3-21" tabindex="-1"></a> )</span>
421 <span id="cb3-22"><a href="#cb3-22" tabindex="-1"></a>}</span></code></pre></div>
422 <p>There are two ways to convert this to S7. You could keep the
423 structure exactly the same, using a <code>list</code> as the underlying
424 data structure and using a constructor to enforce the structure:</p>
425 <div class="sourceCode" id="cb4"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb4-1"><a href="#cb4-1" tabindex="-1"></a>new_rle <span class="ot">&lt;-</span> <span class="fu">new_class</span>(<span class="st">&quot;rle&quot;</span>,</span>
426 <span id="cb4-2"><a href="#cb4-2" tabindex="-1"></a> <span class="at">parent =</span> class_list,</span>
427 <span id="cb4-3"><a href="#cb4-3" tabindex="-1"></a> <span class="at">constructor =</span> <span class="cf">function</span>(lengths, values) {</span>
428 <span id="cb4-4"><a href="#cb4-4" tabindex="-1"></a> <span class="fu">new_object</span>(<span class="fu">list</span>(<span class="at">lengths =</span> lengths, <span class="at">values =</span> values))</span>
429 <span id="cb4-5"><a href="#cb4-5" tabindex="-1"></a> }</span>
430 <span id="cb4-6"><a href="#cb4-6" tabindex="-1"></a>)</span>
431 <span id="cb4-7"><a href="#cb4-7" tabindex="-1"></a><span class="fu">rle</span>(<span class="dv">1</span><span class="sc">:</span><span class="dv">10</span>)</span>
432 <span id="cb4-8"><a href="#cb4-8" tabindex="-1"></a><span class="co">#&gt; Run Length Encoding</span></span>
433 <span id="cb4-9"><a href="#cb4-9" tabindex="-1"></a><span class="co">#&gt; lengths: int [1:10] 1 1 1 1 1 1 1 1 1 1</span></span>
434 <span id="cb4-10"><a href="#cb4-10" tabindex="-1"></a><span class="co">#&gt; values : int [1:10] 1 2 3 4 5 6 7 8 9 10</span></span></code></pre></div>
435 <p>Alternatively you could convert it to the most natural representation
436 using S7:</p>
437 <div class="sourceCode" id="cb5"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb5-1"><a href="#cb5-1" tabindex="-1"></a>new_rle <span class="ot">&lt;-</span> <span class="fu">new_class</span>(<span class="st">&quot;rle&quot;</span>, <span class="at">properties =</span> <span class="fu">list</span>(</span>
438 <span id="cb5-2"><a href="#cb5-2" tabindex="-1"></a> <span class="at">lengths =</span> class_integer,</span>
439 <span id="cb5-3"><a href="#cb5-3" tabindex="-1"></a> <span class="at">values =</span> class_atomic</span>
440 <span id="cb5-4"><a href="#cb5-4" tabindex="-1"></a>))</span></code></pre></div>
441 <p>To allow existing methods to work you’ll need to override
442 <code>$</code> to access properties instead of list elements:</p>
443 <div class="sourceCode" id="cb6"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb6-1"><a href="#cb6-1" tabindex="-1"></a><span class="fu">method</span>(<span class="st">`</span><span class="at">$</span><span class="st">`</span>, new_rle) <span class="ot">&lt;-</span> prop</span>
444 <span id="cb6-2"><a href="#cb6-2" tabindex="-1"></a><span class="fu">rle</span>(<span class="dv">1</span><span class="sc">:</span><span class="dv">10</span>)</span>
445 <span id="cb6-3"><a href="#cb6-3" tabindex="-1"></a><span class="co">#&gt; Run Length Encoding</span></span>
446 <span id="cb6-4"><a href="#cb6-4" tabindex="-1"></a><span class="co">#&gt; lengths: int [1:10] 1 1 1 1 1 1 1 1 1 1</span></span>
447 <span id="cb6-5"><a href="#cb6-5" tabindex="-1"></a><span class="co">#&gt; values : int [1:10] 1 2 3 4 5 6 7 8 9 10</span></span></code></pre></div>
448 <p>The chief disadvantage of this approach is any subclasses will need
449 to be converted to S7 as well.</p>
450 </div>
451 </div>
452 <div id="s4" class="section level2">
453 <h2>S4</h2>
454 <p>S7 properties are equivalent to S4 slots. The chief difference is
455 that they can be dynamic.</p>
456 <ul>
457 <li>S7 classes can not extend S4 classes</li>
458 <li>S4 classes can extend S3 classes</li>
459 <li>S7 can register methods for:
460 <ul>
461 <li>S7 class and S4 generic</li>
462 <li>S4 class and S7 generic</li>
463 </ul></li>
464 </ul>
465 <div id="unions" class="section level3">
466 <h3>Unions</h3>
467 <p>S4 unions are automatically converted to S7 unions. There’s an
468 important difference in the way that class unions are handled in S4 and
469 S7. In S4, they’re handled at method dispatch time, so when you create
470 <code>setUnion(&quot;u1&quot;, c(&quot;class1&quot;, &quot;class2&quot;))</code>, <code>class1</code>
471 and <code>class2</code> now extend <code>u1</code>. In S7, unions are
472 handled at method registration time so that registering a method for a
473 union is just short-hand for registering a method for each of the
474 classes.</p>
475 <div class="sourceCode" id="cb7"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb7-1"><a href="#cb7-1" tabindex="-1"></a>Class1 <span class="ot">&lt;-</span> <span class="fu">new_class</span>(<span class="st">&quot;Class1&quot;</span>)</span>
476 <span id="cb7-2"><a href="#cb7-2" tabindex="-1"></a>Class2 <span class="ot">&lt;-</span> <span class="fu">new_class</span>(<span class="st">&quot;Class2&quot;</span>)</span>
477 <span id="cb7-3"><a href="#cb7-3" tabindex="-1"></a>Union1 <span class="ot">&lt;-</span> <span class="fu">new_union</span>(Class1, Class2)</span>
478 <span id="cb7-4"><a href="#cb7-4" tabindex="-1"></a></span>
479 <span id="cb7-5"><a href="#cb7-5" tabindex="-1"></a>foo <span class="ot">&lt;-</span> <span class="fu">new_generic</span>(<span class="st">&quot;foo&quot;</span>, <span class="st">&quot;x&quot;</span>)</span>
480 <span id="cb7-6"><a href="#cb7-6" tabindex="-1"></a><span class="fu">method</span>(foo, Union1) <span class="ot">&lt;-</span> <span class="cf">function</span>(x) <span class="st">&quot;&quot;</span></span>
481 <span id="cb7-7"><a href="#cb7-7" tabindex="-1"></a>foo</span>
482 <span id="cb7-8"><a href="#cb7-8" tabindex="-1"></a><span class="co">#&gt; &lt;S7_generic&gt; foo(x, ...) with 2 methods:</span></span>
483 <span id="cb7-9"><a href="#cb7-9" tabindex="-1"></a><span class="co">#&gt; 1: method(foo, Class2)</span></span>
484 <span id="cb7-10"><a href="#cb7-10" tabindex="-1"></a><span class="co">#&gt; 2: method(foo, Class1)</span></span></code></pre></div>
485 <p>S7 unions allow you to restrict the type of a property in the same
486 way that S4 unions allow you to restrict the type of a slot.</p>
487 </div>
488 </div>
489
490
491
492 <!-- code folding -->
493
494
495 <!-- dynamically load mathjax for compatibility with self-contained -->
496 <script>
497 (function () {
498 var script = document.createElement("script");
499 script.type = "text/javascript";
500 script.src = "https://mathjax.rstudio.com/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML";
501 document.getElementsByTagName("head")[0].appendChild(script);
502 })();
503 </script>
504
505 </body>
506 </html>