<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/rs-s3-generic-function-object-oriented-system/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://jasdumas.github.io/2018-02-23-s3-generic-function-oo/"> Jasmine Dumas' R Blog</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>	Just like your mom’s chippity chipper recipe – </p>
<p>In Data Science, there are numerous instances where different techniques call for the use of different tools. For me, this means hopping between R and python on a weekly basis. I’ve been fortunate enough to have taken formal courses in python &amp; R in the last few years and just by circumstances have chosen R as my primary language in my data science toolkit. This usually equates to a real mental struggle when jumping into a Jupyter Notebook and making trivial mistakes in the first 15 minutes, like below.</p>
<p><img alt="" src="https://i1.wp.com/jasdumas.github.io/post_data/python-mess.jpeg?w=456" data-recalc-dims="1"></p>
<p>I don’t have any tricks yet, aside from a set of data analysis starter notebooks to quell the initial confusion, but I have noticed when I mentor other Data Scientists (those who have R skills and are now learning python or vice versa) and participate in pair-programming, I often drift to explaining the differences between R’s generic-function OO and python (and a many other languages) message-passing OO as a means of remembering how to structure functions. I’m only knowledgeable about explaining this differences from printing out and bookmarking Hadley Wickham’s <a rel="nofollow" href="http://adv-r.had.co.nz/OO-essentials.html" target="_blank">OO Field Guide chapter</a> in the <a rel="nofollow" href="http://adv-r.had.co.nz/" target="_blank">Advanced R</a> book! Don’t be worried by the title of being too ‘Advanced’, if you are interested in learning more about the <em>why</em> of certain things in R, it’s a great resource.</p>
<p>With the first few paragraphs of the field guide outlining some examples of the different systems, I wanted to dig in a bit further and learn more about the <strong>generic-function object-oriented system</strong> that I could use to explain to others and hopefully help me remember.</p>
<h3>What is a generic function?</h3>
<p>According to Wikipedia:</p>
<blockquote>
<p>a <a rel="nofollow" href="https://en.wikipedia.org/wiki/Generic_function" target="_blank">generic function</a> is a function defined for [polymorphism](https://en.wikipedia.org/wiki/Polymorphism_(computer_science) which is the provision of a single interface to entities of different types.</p>
</blockquote>
<p>Wow, that’s a mouthful but essentially meaning that the function decides which method to call on different types of classes. Imagine the generic function as a recipe for cookies and the common steps include mixing, baking, and cooling and some different methods for specific types! <img alt="🍪" src="https://s.w.org/images/core/emoji/2.3/72x72/1f36a.png" class="wp-smiley"> Ultimately the cookies you make are dictated by what type of ingredients you include.</p>
<table>
<thead>
<tr>
<th>Generic Function (recipe)</th>
<th>Method (finishing)</th>
<th>Class (ingredient)</th>
</tr>
</thead>
<tbody>
<tr>
<td><a rel="nofollow" href="http://allrecipes.com/recipe/10275/classic-peanut-butter-cookies/" target="_blank">Cookies</a></td>
<td>Make criss-cross pattern</td>
<td>smooth peanut butter</td>
</tr>
<tr>
<td><a rel="nofollow" href="https://www.tasteofhome.com/recipes/buttery-almond-cookies" target="_blank">Cookies</a></td>
<td>Roll in remaining confectioners’ sugar</td>
<td>chopped almonds</td>
</tr>
<tr>
<td><a rel="nofollow" href="http://allrecipes.com/recipe/9668/gingerbread-men/?internalSource=streams&referringId=14712&referringContentType=recipe%20hub&clickId=st_trending_s" target="_blank">Cookies</a></td>
<td>Decorate with frosting</td>
<td>ground ginger</td>
</tr>
</tbody>
</table>
<h3>Further Reading</h3>
<ul>
<li><a rel="nofollow" href="https://stat.ethz.ch/R-manual/R-devel/library/methods/html/genericFunction-class.html" target="_blank">genericFunction-class {methods}</a></li>
<li><a rel="nofollow" href="http://www.hep.by/gnu/r-patched/r-exts/R-exts_152.html" target="_blank">Generic functions and methods</a></li>
<li><a rel="nofollow" href="https://www.rdocumentation.org/packages/methods/versions/3.3.1/topics/Methods?tap_a=5644-dce66f&tap_s=10907-287229" target="_blank">Methods</a></li>
<li><a rel="nofollow" href="https://statweb.stanford.edu/~jmc4/classInheritance.pdf" target="_blank">Developments in Class Inheritance and Method Selection</a></li>
<li><a rel="nofollow" href="https://www.r-project.org/conferences/useR-2006/Slides/Chambers.pdf" target="_blank">History of S &amp; R</a></li>
<li><a rel="nofollow" href="https://www.r-bloggers.com/tidbits-from-the-books-that-defined-s-and-r/" target="_blank">Tidbits from the Books that Defined S (and R)</a></li>
<li><a rel="nofollow" href="http://www.kraftrecipes.com/member-recipe/chippity-chippers-87857.aspx" target="_blank">Chippity Chippers Recipe</a></li>
</ul>
	<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="http://jasdumas.github.io/2018-02-23-s3-generic-function-oo/"> Jasmine Dumas' R Blog</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a rel="nofollow" href="https://www.r-project.org/" title="The R Project for Statistical Computing">R</a> news and <a rel="nofollow" href="https://www.r-bloggers.com/search/tutorial" title="R tutorials">tutorials</a> on topics such as: <a rel="nofollow" href="https://www.r-bloggers.com/search/data%20science" title="Data science">Data science</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data" title="Big Data">Big Data, <a rel="nofollow" href="https://www.r-users.com/" title="R jobs">R jobs</a>, visualization (<a rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2" title="ggplot and ggplot2 tutorials">ggplot2</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/boxplot" title="Boxplots using lattice and ggplot2 tutorials">Boxplots</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/map" title="Maps and gis">maps</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/animation" title="Animation in R">animation</a>), programming (<a rel="nofollow" href="https://www.r-bloggers.com/search/RStudio" title="RStudio IDE for R">RStudio</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/sweave" title="Sweave and literate programming">Sweave</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX" title="LaTeX in R">LaTeX</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/SQL" title="SQL and databases">SQL</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/eclipse" title="Eclipse IDE for R">Eclipse</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/git" title="git and github, Version Control System">git</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/hadoop" title="Large data in R using Hadoop">hadoop</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping" title="Web Scraping of google, facebook, yahoo, twitter and more using R">Web Scraping</a>) statistics (<a rel="nofollow" href="https://www.r-bloggers.com/search/regression" title="Regressions and ANOVA analysis tutorials">regression</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/PCA" title="principal component analysis tutorial">PCA</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/time+series" title="Time series">time series</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/trading" title="finance trading">trading</a>) and more...
<img width="1" alt="" src="http://feeds.feedburner.com/~r/RBloggers/~4/u9U5y8nVx0o" height="1"></a></div>