An introduction to object-oriented programming in R

14 downloads 12414 Views 113KB Size Report
programming in R. Giorgio Valentini e –mail: [email protected]. DSI – Dipartimento di Scienze dell' Informazione. Università degli Studi di Milano ...
An introduction to object-oriented programming in R Giorgio Valentini e –mail: [email protected] DSI – Dipartimento di Scienze dell’ Informazione Università degli Studi di Milano

1

Why OO-programming in R? 1. Modeling and programming reasons – OO-modeling and OO-programming are close to the problem domain – OO-programming paradigm provides a unified view of data structures and procedures – It is easy to use, modifiy and extends OO sw libraries

2. Practical reasons in bioinformatics domain – Most of Bioconductor libraries adopt the OOprogramming paradigm – Many useful R packages are OO 2

OO programming in R: classes and methods

Classes: “ideas” of objects Objects

Methods: functions defined for specific classes

3

Classes • In R all software entities are objects • Each object belong to a class • A class is a general scheme for objects: from a general standpoint it represents an “idea”, i.e. the general structure of a given object • Objects are realizations or instances of a class.

4

Classes in R

• Two kinds of information about a class are commonly stored in R: 1. Representation of the class 2. Relation of the class to other classes

5

Representation of the class Classes are represented in R in two (non mutually exclusive) ways: 1. Slots: – a slot contains an object of another class – complicated classes can be defined in terms of simpler ones

2. Prototype: •

A definition of a “prototypical” object for that class

6

Example of class representation and object generation # Class representing codons (triplets of nucleotides) setClass("triplets", representation(x="character"), prototype(x="UAG")) # Construction of objects of the “triplets” class seq0