[Thread #RStats #Programming ]
Some important points taken from "Object-Oriented Programming, Functional Programming and R", by John M. Chambers
arxiv.org/pdf/1409.3531.…
An article about what is Functional Programming (FP), and how does it differ from Object Oriented Programming (OOP) ?
Note that both these paradigms are used in R, and interact with each others.
Here’s the definition of what FP is :
- Programming == creating function
- Functions returns values computed from arguments (and only these)
- A function has no side effect
Side note: a function is said to have side effect when it has an impact outside of its scope, that is to say when a function has an effect outside its argument.
Wikipedia has a good page about this : en.wikipedia.org/wiki/Side_effe…
A function without side effect is said to be « pure ».
The pure function concept is also at the root of the naming of the {purrr} package, as explained here :
github.com/tidyverse/purr…
R does not enforce functions to be pure. The example from the article being the Random number generation, which is implemented as 'a distinctly “state-based” model in which an object in the global environment (.Random.seed) represents the current state of the generators.'
On the other hand, OOP is :
- Programming == creating objects
- Objects have class, and are defined by properties
- An object inherits from another superclass
- Computation is made through methods defined in the object
So, is R an OOP language? « Not from its inception », but there are many OOP paradigms that has been implemented in R: S3, S4, RC…
The more modern being R6: cran.r-project.org/web/packages/R…
Some OOP are even implemented just for a specific package (e.g ggplo2 with: cran.r-project.org/web/packages/g…)
The specificity of R OOP is that object methods are function calls, hence the use of "functional OOP". It opposes to "encapsulated (OOP), in which methods are part of the class definition". In other words "Methods belong to functions, not to classes; the functions are generic".
You may have heard it before, but:
- Everything that exists is an object.
- Everything that happens is a function call.
What that means, basically, is that contrary to other languages as Java or C++, every reference in R is a reference to a single internal structure type: a data.frame, a vector or a function refer, internally, to the same data structure.
But what does "reference" mean? A reference is the combination of a name and a context: the context being an environment, a reference is then name + environment.
This concept of environment is central for R programming, as it defines the context in which a name is looked for, and can lead to surprising behaviors if you don’t understand them correctly, especially with packages.
This is the concept of "local reference": unless otherwise specified, every object is evaluated in the environment it is called.
This also allows you to use the same name in different environments/functions.
So, to sum up, R OOP can be considered as a Functional OOP as methods, which perform actions on the objects, are implemented as functions, not as part of the object.
The big difference with other OOP paradigms is that methods are generic: for example, you can call print or plot on every model object, regardless if it’s a lm, glm, or any other — this kind of methods are not contained in the model object.
To sum up what a functional OOP requires :
- Classes for objects
- Generic function that dispatch methods
- Methods for each class

This is what S3 does: creating functions that dispatch methods to class.
adv-r.had.co.nz/S3.html
And, to conclude ;)
(Conclusion 2: Computer Science is Awesome)

• • •

Missing some Tweet in this thread? You can try to force a refresh
 

Keep Current with Colin 🤘🌱🏃‍♀️

Colin 🤘🌱🏃‍♀️ Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @_ColinFay

Aug 8, 2018
#RStats — What's up CRAN?

In the past 7 months:

🆕 1178 new 📦

🆓 18 unarchived 📦

⏹ 493 archived 📦
At the end of June, there were around 12500 📦 on the CRAN
Changes on CRAN check ✅

See stats.ox.ac.uk/pub/bdr/Rblas/… for more info
Read 9 tweets
Jul 25, 2018
💬 "If you're aiming at humans only, you can build a shiny app. If you want machines to access your data, build an API"

💬 "And remember that any other language can access your R API. You're opening a lot of doors."

#RStats
Some important things to know when working with APIs:

🕸 About http requests : developer.mozilla.org/en-US/docs/Web…

🚀 About REST API : en.wikipedia.org/wiki/Represent…
Read 14 tweets
Jun 11, 2018
[Thread]
Why do we use arrow `<-` instead of equal `=` for assignment in #RStats :
It’s an historical choice: R comes from S, which used <- for assignment. S uses `<-` partly because it is inspired by APL, which had the ← operator for assignment, as it was developed for this keyboard, which has a key for arrow :
en.wikipedia.org/wiki/APL_(prog…
Not that at that time, with APL, the arrow was chosen because it distinguished from the equal operator (there were no `==` for testing equality).
See : softwarepreservation.org/projects/apl/B…
Read 16 tweets
May 12, 2018
Current status: looking for more memes to put in my @erum2018 talk.
#RStats #eRum2018
So far, I've got:
Read 8 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Don't want to be a Premium member but still want to support us?

Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal

Or Donate anonymously using crypto!

Ethereum

0xfe58350B80634f60Fa6Dc149a72b4DFbc17D341E copy

Bitcoin

3ATGMxNzCUFzxpMCHL5sWSt4DVtS8UqXpi copy

Thank you for your support!

Follow Us on Twitter!

:(