Geostatitics for S+: Object-oriented Programming in S+

The framework for geostatistical modeling being described makes extensive use of the object-oriented programming capabilities provided in S+. Therefore, a brief description of object-oriented programming and its implementation within S+ is necessary.

Object-oriented Programming

Object-oriented programming refers to the practice of defining a data object which represents something of interest and a set of operations that can be carried out on that object. For example, consider the set of real numbers. Each member of this set can be considered an object upon which common operations can be conducted, such as addition, subtraction, multiplication, etc. In object-oriented programming, the structure of a data object is typically much more complicated. In the present situation, one of the data objects defined represents the (possibly multivariate) data, {z(s1),...,z(sn)}, containing the locations of sampling sites and values observed at those sites. Operations defined on this data structure include the exploratory and modeling functions introduced above.

Support for Object-oriented Programming in S+

Data Objects

S+ supports object-oriented programming through the definition of complex data objects and the definition of functions that act on those objects. Objects in S+ can be a scalar, a vector, a matrix, a list or a data frame. A list is simply a collection of, possibly heterogeneous, objects. Thus, it is possible to have a list that consists of a vector, a matrix, and another list. A data frame organizes data in rows and columns. Each column represents a variable and each row represents a case. This allows objects to be created that represent very complicated phenomena. For example, the following S+ statement creates a list containing a numeric vector and a list:

>  list.obj <- list(vect=c(1,2,3), 
+  lst=list(chars=c(`a','b','c'),ints=c(1,2,3))) 

[In S+ statements, '>' represents the S+ prompt and '+' represents the S+ continuation prompt.]

Object Classes

When conducting object-oriented programming, objects are assigned a "class" that indicates to functions what type of data the object contains. For instance, in this framework the data objects that represent spatial locations and associated observed values are assigned a class of "point". The class of any S+ object can be determined with the class() function.

Functions

Operations on objects are implemented as S+ functions, which take an object of a particular class and conduct an operation upon it. Many simple S+ functions directly support object orientation. For example, almost every object will have a related operation that allows the data in the object to be visualized or plotted. Therefore, the plot routine in S+ looks at its first argument to see whether it has been assigned a class. If it has, S+ executes a function named plot.class (if this function can be located) instead of the default plot function. In this way, the operation of plotting any object is done through the plot function, with which every S+ user is familiar.


S+ GeoStat Introduction OOPLa Data Structures Functions Download

majure
Updated: 11-Dec-1995